@@ -58,9 +58,9 @@ function ocp(T)
5858 t ∈ [0, T], time
5959 x ∈ R², state
6060 u ∈ R², control
61- x(0) == [-1, 0] # Starting point (left well)
62- x(T) == [1, 0] # End point (right well)
63- ẋ(t) == u(t) # Path dynamics
61+ x(0) == [-1, 0] # Starting point (left well)
62+ x(T) == [1, 0] # End point (right well)
63+ ẋ(t) == u(t) # Path dynamics
6464 ∫( sum((u(t) - f(x(t))).^2) ) → min # Minimize deviation from deterministic flow
6565 end
6666 return action
@@ -142,22 +142,27 @@ To find the maximum likelihood path, we also need to minimize the transient time
142142# Continuation function to avoid global variables
143143function continuation_mam(Ts; init_guess=init)
144144 objectives = Float64[]
145+ iterations_list = Int[]
145146 current_sol = init_guess
146147
147- println(" Time Objective Iterations")
148148 for T in Ts
149149 current_sol = solve(ocp(T); display=false, init=current_sol, grid_size=1000, tol=1e-8)
150- obj = objective(current_sol)
151- @printf("%6.2f %9.6e %d\n", T, obj, iterations(current_sol))
152- push!(objectives, obj)
150+ push!(objectives, objective(current_sol))
151+ push!(iterations_list, iterations(current_sol))
153152 end
154153
155- return objectives, current_sol
154+ return objectives, iterations_list, current_sol
156155end
157156
158157# Perform continuation
159158Ts = range(1, 100, 100)
160- objectives, final_sol = continuation_mam(Ts)
159+ objectives, iters, final_sol = continuation_mam(Ts)
160+
161+ # Display results
162+ println(" Time Objective Iterations")
163+ for i in eachindex(Ts)
164+ @printf("%6.2f %9.6e %d\n", Ts[i], objectives[i], iters[i])
165+ end
161166nothing # hide
162167```
163168
@@ -178,9 +183,15 @@ Let us visualize the evolution of the objective function with respect to the tra
178183``` @example main-mam
179184plt1 = scatter(Ts, log10.(objectives), xlabel="Time", label="Objective (log10)")
180185vline!(plt1, [T_min], label="Minimum at T=$(round(T_min, digits=1))", z_order=:back)
186+ plot(plt1, size=(800,400))
187+ ```
188+
189+ We now focus on the region around the minimum for a clearer view:
190+
191+ ``` @example main-mam
181192plt2 = scatter(Ts[40:100], log10.(objectives[40:100]), xlabel="Time", label="Objective (log10)")
182193vline!(plt2, [T_min], label="Minimum", z_order=:back)
183- plot(plt1, plt2, layout=(2,1), size=(800,800 ))
194+ plot(plt2, size=(800,400 ))
184195```
185196
186197!!! note "Interpretation"
0 commit comments