-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a dispatch to SimpleNewtonRaphson for NNLS and SimpleGaussNewton
Fixes #82
- Loading branch information
1 parent
0d73574
commit 3b587fb
Showing
4 changed files
with
35 additions
and
3 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,19 @@ | ||
using SimpleNonlinearSolve, Random, LinearAlgebra, Test | ||
|
||
true_function(x, θ) = @. θ[1] * exp(θ[2] * x) * cos(θ[3] * x + θ[4]) | ||
|
||
θ_true = [1.0, 0.1, 2.0, 0.5] | ||
x = [-1.0, -0.5, 0.0, 0.5, 1.0] | ||
y_target = true_function(x, θ_true) | ||
|
||
function loss_function(θ, p) | ||
ŷ = true_function(p, θ) | ||
return abs2.(ŷ .- y_target) | ||
end | ||
|
||
θ_init = θ_true .+ randn!(similar(θ_true)) * 0.1 | ||
prob_oop = NonlinearLeastSquaresProblem{false}(loss_function, θ_init, x) | ||
sol = solve(prob_oop, SimpleNewtonRaphson()) | ||
sol = solve(prob_oop, SimpleGaussNewton()) | ||
|
||
@test norm(sol.resid) < 1e-12 |
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