1
1
using NonlinearSolve, LinearSolve, LinearAlgebra, Test, Random
2
+ import LeastSquaresOptim
2
3
3
4
true_function (x, θ) = @. θ[1 ] * exp (θ[2 ] * x) * cos (θ[3 ] * x + θ[4 ])
4
5
true_function (y, x, θ) = (@. y = θ[1 ] * exp (θ[2 ] * x) * cos (θ[3 ] * x + θ[4 ]))
@@ -25,22 +26,11 @@ prob_oop = NonlinearLeastSquaresProblem{false}(loss_function, θ_init, x)
25
26
prob_iip = NonlinearLeastSquaresProblem (NonlinearFunction (loss_function;
26
27
resid_prototype = zero (y_target)), θ_init, x)
27
28
28
- sol = solve (prob_oop, GaussNewton (; linsolve = NormalCholeskyFactorization ());
29
- maxiters = 1000 , abstol = 1e-8 )
30
- @test SciMLBase. successful_retcode (sol)
31
- @test norm (sol. resid) < 1e-6
32
-
33
- sol = solve (prob_iip, GaussNewton (; linsolve = NormalCholeskyFactorization ());
34
- maxiters = 1000 , abstol = 1e-8 )
35
- @test SciMLBase. successful_retcode (sol)
36
- @test norm (sol. resid) < 1e-6
37
-
38
- sol = solve (prob_oop, LevenbergMarquardt (; linsolve = NormalCholeskyFactorization ());
39
- maxiters = 1000 , abstol = 1e-8 )
40
- @test SciMLBase. successful_retcode (sol)
41
- @test norm (sol. resid) < 1e-6
42
-
43
- sol = solve (prob_iip, LevenbergMarquardt (; linsolve = NormalCholeskyFactorization ());
44
- maxiters = 1000 , abstol = 1e-8 )
45
- @test SciMLBase. successful_retcode (sol)
46
- @test norm (sol. resid) < 1e-6
29
+ nlls_problems = [prob_oop, prob_iip]
30
+ solvers = [GaussNewton (), LevenbergMarquardt (), LSOptimSolver (:lm ), LSOptimSolver (:dogleg )]
31
+
32
+ for prob in nlls_problems, solver in solvers
33
+ @time sol = solve (prob, solver; maxiters = 1000 , abstol = 1e-8 )
34
+ @test SciMLBase. successful_retcode (sol)
35
+ @test norm (sol. resid) < 1e-6
36
+ end
0 commit comments