Skip to content

Commit

Permalink
fix blocks bug in min_action_method (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
oameye authored Feb 20, 2024
1 parent 625903c commit a5057e6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/largedeviations/min_action_method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To set an initial path different from a straight line, see the multiple dispatch
The minimization can be performed in blocks to save intermediate results.
## Keyword arguments
* `functional = "FW"`: type of action functional to minimize.
* `functional = "FW"`: type of action functional to minimize.
Defaults to [`fw_action`](@ref), alternative: [`om_action`](@ref).
* `maxiter = 100`: maximum number of iterations before the algorithm stops.
* `blocks = 1`: number of iterative optimization blocks
Expand All @@ -39,7 +39,7 @@ function min_action_method(sys::StochSystem, x_i::State, x_f::State, N::Int, T::
showprogress = false,
verbose = true,
kwargs...)

init = reduce(hcat, range(x_i, x_f, length=N))
min_action_method(sys::StochSystem, init, T;
functional=functional, maxiter=maxiter, blocks=blocks, method=method,
Expand Down Expand Up @@ -68,23 +68,23 @@ function min_action_method(sys::StochSystem, init::Matrix, T::Real;
showprogress = false,
verbose = true,
kwargs...)

println("=== Initializing MAM action minimizer ===")

A = inv(sys.Σ)
f(x) = action(sys, fix_ends(x, init[:,1], init[:,end]),
range(0.0, T, length=size(init, 2)), functional; cov_inv=A)

result = Vector{Optim.OptimizationResults}(undef, blocks)
result[1] = Optim.optimize(f, init, method,
Optim.Options(iterations=Int(ceil(maxiter/blocks)), kwargs...))
verbose ? println(result[1]) : nothing

if blocks > 1
iterator = showprogress ? tqdm(2:blocks) : 2:blocks
for m in iterator
result[m] = Optim.optimize(f, result[m-1].minimizer, method,
Optim.Options(Int(ceil(maxiter/blocks)), kwargs...))
Optim.Options(iterations=Int(ceil(maxiter/blocks)), kwargs...))
verbose ? println(result[m]) : nothing
end
save_info ? (return result) : return [Optim.minimizer(result[i]) for i=1:blocks]
Expand All @@ -102,4 +102,4 @@ function fix_ends(x::Matrix, x_i::State, x_f::State)
m = x
m[:,1] = x_i; m[:,end] = x_f
m
end;
end;

0 comments on commit a5057e6

Please sign in to comment.