Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cooperation #16

Open
pkofod opened this issue Aug 15, 2018 · 12 comments
Open

Cooperation #16

pkofod opened this issue Aug 15, 2018 · 12 comments

Comments

@pkofod
Copy link

pkofod commented Aug 15, 2018

We're/I'm still interested in cooperating and getting this in Optim. I was reluctant at some point, but adding StaticArrays as a dependency to Optim would be worth it to have this functionality in Optim.

edit: let me say why I was reluctant. My main problem was that I prefer not to depend on the actual type packages (numbers, arrays, ...) as it discourages generic interfaces. However, StaticOptim is almost stdlib, and the traits interface I had been hoping for in v1.0 that describes mutability is probably not coming any time soon.

@aaowens
Copy link
Owner

aaowens commented Aug 16, 2018

One straightforward way would be to copy and paste this code as is into Optim and have optimize(f, x::StaticArray, BFGS()) call the static version and return a StaticOptimizationResult, but this type doesn't have most of the fields of the expected MultivariateOptimizationResults. The code here doesn't currently support any optimization options, but it shouldn't be hard to add them.

I think it should be possible to fill in the fields of MultivariateOptimizationResults with some modifications to the code here, but I'm not sure what that would do to performance. Also, MultivariateOptimizationResults is mutable, so I think constructing it would allocate.

Would you be happy with a new type struct StaticOptimizationResults <: OptimizationResults which has most (all?) of the fields of MultivariateOptimizationResults?

@pkofod
Copy link
Author

pkofod commented Aug 16, 2018

For now, I have no problem prepending Static on whatever needs a Static to be performant. But I will have a look at MultivariateOptimizationResults and see if we actually use that mutability anywhere.

@pkofod
Copy link
Author

pkofod commented Aug 16, 2018

I should add, that I'd be happy to participate in "experimenting" in this repo before we move stuff into Optim.

@aaowens
Copy link
Owner

aaowens commented Aug 17, 2018

Ok, I started this over here #17 . I left out some fields from MultivariateOptimizationResults because I wasn't sure what they were.

@pkofod
Copy link
Author

pkofod commented Aug 19, 2018

I'm wondering, how much did you actually modify from LineSearches?

edit: seems like it's just checking the order

@aaowens
Copy link
Owner

aaowens commented Aug 19, 2018

There should be two changes.

  1. Modify operators to work on StaticArrays
  2. Skip the make ϕ functions by copying the code into the loop body. I couldn't make it not allocate without that. Possibly this is no longer necessary on 1.0.

@pkofod
Copy link
Author

pkofod commented Aug 20, 2018

Okay, I will try to see if we can't just call the linesearches functions directly, as that would certainly simplify the code.

@pkofod
Copy link
Author

pkofod commented Aug 20, 2018

Hm, I basically took the code for the line search, and inserted it into a function, and I get


julia> @btime  soptimize(rosenbrock, sx, StaticOptim.Order2(), nothing; tol = 1e-8)
  30.671 μs (901 allocations: 28.59 KiB)
Results of Static Optimization Algorithm
 * Minimizer: [0.9999999999990606,0.9999999999980389]
 * Minimum: [1.5610191722141176e-24]
 * Hf(x): [801.6874976886638,-399.8345645795701,-399.83456457957504,199.9124176978296]
 * Number of iterations: [31]
 * Number of function calls: [69]
 * Number of gradient calls: [31]
 * Converged: [true]

instead of

julia> @btime  soptimize(rosenbrock, sx, StaticOptim.Order2(), nothing; tol = 1e-8)
  2.398 μs (4 allocations: 192 bytes)
Results of Static Optimization Algorithm
 * Minimizer: [0.9999999999990606,0.9999999999980389]
 * Minimum: [1.5610191722141176e-24]
 * Hf(x): [801.6874976886638,-399.8345645795701,-399.83456457957504,199.9124176978296]
 * Number of iterations: [31]
 * Number of function calls: [69]
 * Number of gradient calls: [31]
 * Converged: [true]

I wonder what optimization we're cheating ourselves for by putting it in a function.

@aaowens
Copy link
Owner

aaowens commented Oct 31, 2018

I've also tried to put the linesearch code in a function, but my results are similar to yours. Using @inline makes no difference.

@pkofod
Copy link
Author

pkofod commented Oct 31, 2018

I never got around to figuring this out, but might have some time tonight

@aaowens
Copy link
Owner

aaowens commented Mar 13, 2019

I tagged an initial version for this package and updated the readme. I'm not sure if you still want the functionality in Optim since there might not be a way to reuse the existing linesearch code. This package does a few other things besides multivariate optimization too (root-finding, univariate optimization) so it's useful by itself.

@pkofod
Copy link
Author

pkofod commented Mar 14, 2019

That's fine! I have another package that covers the same things you mention in the making, that I intend to be a back-end for Optim, but since you're using this already don't let me hold you back on anything :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants