Skip to content

Commit 748fb09

Browse files
authored
Merge pull request #487 from SciML/ap/simplenonlinearsolve_history
fix: restore the history of SimpleNonlinearSolve
2 parents eb3df11 + 1b24ae4 commit 748fb09

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

lib/SimpleNonlinearSolve/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

lib/SimpleNonlinearSolve/test/core/adjoint_tests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@testitem "Simple Adjoint Test" tags=[:adjoint] begin
2-
using ForwardDiff, ReverseDiff, SciMLSensitivity, Tracker, Zygote, DiffEqBase,
3-
SimpleNonlinearSolve
2+
using ForwardDiff, ReverseDiff, SciMLSensitivity, Tracker, Zygote, DiffEqBase
43

54
ff(u, p) = u .^ 2 .- p
65

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@testitem "Nonlinear Least Squares" tags=[:core] begin
2+
using LinearAlgebra
3+
4+
true_function(x, θ) = @. θ[1] * exp(θ[2] * x) * cos(θ[3] * x + θ[4])
5+
6+
θ_true = [1.0, 0.1, 2.0, 0.5]
7+
x = [-1.0, -0.5, 0.0, 0.5, 1.0]
8+
y_target = true_function(x, θ_true)
9+
10+
function loss_function(θ, p)
11+
= true_function(p, θ)
12+
return.- y_target
13+
end
14+
15+
function loss_function!(resid, θ, p)
16+
= true_function(p, θ)
17+
@. resid =- y_target
18+
return
19+
end
20+
21+
θ_init = θ_true .+ 0.1
22+
prob_oop = NonlinearLeastSquaresProblem{false}(loss_function, θ_init, x)
23+
24+
@testset "Solver: $(nameof(typeof(solver)))" for solver in [
25+
SimpleNewtonRaphson(AutoForwardDiff()), SimpleGaussNewton(AutoForwardDiff()),
26+
SimpleNewtonRaphson(AutoFiniteDiff()), SimpleGaussNewton(AutoFiniteDiff())]
27+
sol = solve(prob_oop, solver)
28+
@test norm(sol.resid, Inf) < 1e-12
29+
end
30+
31+
prob_iip = NonlinearLeastSquaresProblem(
32+
NonlinearFunction{true}(loss_function!, resid_prototype = zeros(length(y_target))),
33+
θ_init, x)
34+
35+
@testset "Solver: $(nameof(typeof(solver)))" for solver in [
36+
SimpleNewtonRaphson(AutoForwardDiff()), SimpleGaussNewton(AutoForwardDiff()),
37+
SimpleNewtonRaphson(AutoFiniteDiff()), SimpleGaussNewton(AutoFiniteDiff())]
38+
sol = solve(prob_iip, solver)
39+
@test norm(sol.resid, Inf) < 1e-12
40+
end
41+
end

0 commit comments

Comments
 (0)