5050f_model = ADNLSModel(F, x0, m, name = "nonlinear LS model of f")
5151
5252# Get the regularizer from ProximalOperators
53- λ = 1.0
53+ λ = 0.01
5454h = NormL0(λ)
5555
5656# Wrap into a RegularizedNLPModel
@@ -69,9 +69,41 @@ out = LM(regularized_pb, verbose = 1, atol = 1e-4)
6969println("LM converged after $(out.iter) iterations.")
7070```
7171
72+ We can visualize the solution with plots,
73+ ``` @example ls
74+ using Plots
75+
76+ # Extract estimated parameters
77+ a_est, b_est = out.solution
78+
79+ # True curve
80+ y_true = [a_true * exp(b_true * ti) for ti in t]
81+
82+ # Estimated curve
83+ y_est = [a_est * exp(b_est * ti) for ti in t]
84+
85+ # Plot
86+ scatter(t, y, label="Noisy data", legend=:bottomleft)
87+ plot!(t, y_true, label="True model", lw=2)
88+ plot!(t, y_est, label="Fitted model", lw=2, ls=:dash)
89+ ```
90+
7291``` @example ls
7392#We can choose LMTR instead which is a trust-region method
7493out = LMTR(regularized_pb, verbose = 1, atol = 1e-4)
7594println("LMTR converged after $(out.iter) iterations.")
95+ ```
96+
97+ ``` @example ls
98+ # Extract estimated parameters
99+ a_est, b_est = out.solution
100+
101+ # Estimated curve
102+ y_est = [a_est * exp(b_est * ti) for ti in t]
103+
104+ # Plot
105+ scatter(t, y, label="Noisy data", legend=:bottomleft)
106+ plot!(t, y_true, label="True model", lw=2)
107+ plot!(t, y_est, label="Fitted model", lw=2, ls=:dash)
76108
77109```
0 commit comments