-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more methods for EnsembleProblem and add more tests
- Loading branch information
1 parent
8c17212
commit 23754a8
Showing
5 changed files
with
61 additions
and
0 deletions.
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,8 @@ | ||
using DifferentialEquations | ||
|
||
f(u, p, t) = 1.01 * u | ||
u0 = 1 / 2 | ||
tspan = (0.0, 1.0) | ||
prob = ODEProblem(f, u0, tspan) | ||
ensemble_prob = EnsembleProblem(prob, prob_func = (prob, i, repeat) -> remake(prob, u0 = rand())) | ||
sim = solve(ensemble_prob, EnsembleThreads(), trajectories = 10, dt = 0.1) |
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,26 @@ | ||
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 | ||
|
||
prob = OptimizationProblem(optf, x0, lb = [-0.5, -0.5], ub = [0.5, 0.5]) | ||
ensembleprob = Optimization.EnsembleProblem(prob, 5, prob_func = (prob, i, repeat) -> remake(prob, u0 = rand(-0.5:0.001:0.5, 2))) | ||
|
||
sol = Optimization.solve(ensembleprob, OptimizationOptimJL.BFGS(), EnsembleThreads(), trajectories = 5, maxiters = 5) | ||
@test findmin(i -> sol[i].objective, 1:4)[1] < sol1.objective | ||
|
||
sol = Optimization.solve(ensembleprob, OptimizationOptimJL.BFGS(), EnsembleDistributed(), trajectories = 5, maxiters = 5) | ||
@test findmin(i -> sol[i].objective, 1:4)[1] < sol1.objective |
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