diff --git a/src/optimize/problem_types.jl b/src/optimize/problem_types.jl index ec2afb4..16c14a3 100644 --- a/src/optimize/problem_types.jl +++ b/src/optimize/problem_types.jl @@ -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, diff --git a/test/optimize/param.jl b/test/optimize/param.jl new file mode 100644 index 0000000..321a7f2 --- /dev/null +++ b/test/optimize/param.jl @@ -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 \ No newline at end of file diff --git a/test/optimize/preconditioning.jl b/test/optimize/preconditioning.jl index a68e608..4acf9ab 100644 --- a/test/optimize/preconditioning.jl +++ b/test/optimize/preconditioning.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 2eeb21d..015a4ab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")