Skip to content

Commit

Permalink
Merge pull request #67 from JuliaNLSolvers/pkm/params
Browse files Browse the repository at this point in the history
Test param
  • Loading branch information
pkofod committed Feb 3, 2024
2 parents e2908ca + 3be9cd3 commit 892e7ef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/optimize/problem_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ struct OptimizationOptions{T1,T2,T3,T4,Txn,Tgn}
end

OptimizationOptions(;
x_abstol = 0.0,
x_reltol = 0.0,
x_abstol = 0,
x_reltol = 0,
x_norm = x -> norm(x, Inf),
g_abstol = 1e-8,
g_reltol = 0.0,
g_norm = x -> norm(x, Inf),
f_limit = -Inf,
f_abstol = 0.0,
f_reltol = 0.0,
f_abstol = -Inf, #
f_reltol = -Inf, # Not useful at 0 if for example we have quadric and trust region accept but objective is the same
nm_tol = 1e-8,
maxiter = 10000,
show_trace = false,
Expand Down
27 changes: 27 additions & 0 deletions test/optimize/param.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testset "param test" begin
N_test = 9
w = rand(N_test)
function obji(x, data)
s=sum((x .- data) .^ 2)
s
end
function g!(G, x, data)
G .= 2 * (x .- data)
G
end
function h!(H, x, data)
H .= 2 * I
H
end
param1 = [1, 2, 3]
sc = ScalarObjective(; f = obji, g = g!, h = h!, param = param1)
op = OptimizationProblem(sc)
sol1 = solve(op, [3.0, 4.0, 4.0], BFGS(), OptimizationOptions())
@test sol1.info.solution param1

param2 = [10, 20, 30]
sc = ScalarObjective(; f = obji, g = g!, h = h!, param = param2)
op = OptimizationProblem(sc)
sol2 = solve(op, [3.0, 4.0, 4.0], BFGS(), OptimizationOptions())
@test sol2.info.solution param2
end
2 changes: 1 addition & 1 deletion test/optimize/preconditioning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using Test
OPT_PROBS["laplacian"]["array"]["mutating"],
copy(initial_x),
optimizer(P),
OptimizationOptions(g_abstol = 1e-6),
OptimizationOptions(g_abstol = 1e-6, f_abstol = 0.0),
)
push!(mino, results.info.minimum)
push!(iter, results.info.iter)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ include("optimize/problems.jl")
include("optimize/interface.jl")
include("optimize/preconditioning.jl")
include("optimize/complex.jl")
include("optimize/param.jl")
include("lsqfit/interface.jl")
include("globalization/runtests.jl")

0 comments on commit 892e7ef

Please sign in to comment.