-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
[WIP] Ensemble #620
Closed
Closed
[WIP] Ensemble #620
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function SciMLBase.EnsembleProblem(prob::OptimizationProblem, u0s::Vector{Vector{T}}; kwargs...) where {T} | ||
prob_func = (prob, i, repeat = nothing) -> remake(prob, u0 = u0s[i]) | ||
return SciMLBase.EnsembleProblem(prob; prob_func, kwargs...) | ||
end | ||
|
||
function SciMLBase.EnsembleProblem(prob::OptimizationProblem, trajectories::Int; kwargs...) | ||
if prob.lb != nothing && prob.ub != nothing | ||
u0s = QuasiMonteCarlo.sample(trajectories, prob.lb, prob.ub, LatinHypercubeSample()) | ||
prob_func = (prob, i, repeat = nothing) -> remake(prob, u0 = u0s[:, i]) | ||
else | ||
error("EnsembleProblem requires either initial points as second argument or lower and upper bounds to be defined with the trajectories second argument method.") | ||
end | ||
return SciMLBase.EnsembleProblem(prob; prob_func, kwargs...) | ||
end | ||
|
||
|
||
function SciMLBase.solve(prob::EnsembleProblem{T}, args...; kwargs...) where {T <: OptimizationProblem} | ||
return SciMLBase.__solve(prob, args...; kwargs...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Optimization, OptimizationOptimJL, ForwardDiff, Test | ||
|
||
x0 = zeros(2) | ||
rosenbrock(x, p = nothing) = (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^2 | ||
l1 = rosenbrock(x0) | ||
|
||
optf = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff()) | ||
prob = OptimizationProblem(optf, x0) | ||
sol1 = Optimization.solve(prob, OptimizationOptimJL.BFGS(), maxiters = 5) | ||
|
||
|
||
ensembleprob = Optimization.EnsembleProblem(prob, [x0, x0 .+ rand(2), x0 .+ rand(2), x0 .+ rand(2)]) | ||
|
||
sol = Optimization.solve(ensembleprob, OptimizationOptimJL.BFGS(), EnsembleThreads(), trajectories = 4, maxiters = 5) | ||
@test findmin(i -> sol[i].objective, 1:4)[1] < sol1.objective | ||
|
||
sol = Optimization.solve(ensembleprob, OptimizationOptimJL.BFGS(), EnsembleDistributed(), trajectories = 4, maxiters = 5) | ||
@test findmin(i -> sol[i].objective, 1:4)[1] < sol1.objective |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just keep to the interface. This doesn't seem like a necessary shorthand to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to provide an automated way of doing the solves with initial points sampled, it would be useful. I can probably do it another way if you are opposed to this, but do note that the other dispatch is already not conforming fully with the current interface of creating these problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good to come up with such a shorthand at a higher level of the interface, since NonlinearProblem, NonlinearLeastSquaresProblem, etc. would want to do similar things.