Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/multivariate/optimize/optimize.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
update_g!(d, state, method) = nothing
function update_g!(d, state, method::M) where {M<:Union{FirstOrderOptimizer,Newton}}
function update_g!(d, state, method::FirstOrderOptimizer)
# Update the function value and gradient
value_gradient!(d, state.x)
project_tangent!(method.manifold, gradient(d), state.x)
end
function update_g!(d, state, method::Newton)
# Update the function value and gradient
value_gradient!(d, state.x)
if M <: FirstOrderOptimizer #only for methods that support manifold optimization
project_tangent!(method.manifold, gradient(d), state.x)
end
end
update_fg!(d, state, method) = nothing
update_fg!(d, state, method::ZerothOrderOptimizer) = value!(d, state.x)
function update_fg!(d, state, method::M) where {M<:Union{FirstOrderOptimizer,Newton}}
function update_fg!(d, state, method::FirstOrderOptimizer)
value_gradient!(d, state.x)
project_tangent!(method.manifold, gradient(d), state.x)

Check warning on line 15 in src/multivariate/optimize/optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/multivariate/optimize/optimize.jl#L13-L15

Added lines #L13 - L15 were not covered by tests
end
function update_fg!(d, state, method::Newton)

Check warning on line 17 in src/multivariate/optimize/optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/multivariate/optimize/optimize.jl#L17

Added line #L17 was not covered by tests
value_gradient!(d, state.x)
if M <: FirstOrderOptimizer #only for methods that support manifold optimization
project_tangent!(method.manifold, gradient(d), state.x)
end
end

# Update the Hessian
Expand Down
38 changes: 2 additions & 36 deletions src/multivariate/solvers/constrained/samin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function optimize(
(;nt, ns, t0, rt, r_expand, bounds_ratio, neps, coverage_ok, verbosity) = method
verbose = verbosity > 0

x_tol, f_tol = options.f_abstol, options.x_abstol
x_tol, f_tol = options.x_abstol, options.f_abstol

x0 = copy(x)
n = size(x, 1) # dimension of parameter
Expand Down Expand Up @@ -213,7 +213,6 @@ function optimize(
end
converge = 0
termination_code = TerminationCode.NotImplemented

return MultivariateOptimizationResults(
method,
x0,# initial_x,
Expand All @@ -236,7 +235,7 @@ function optimize(
h_calls(d),
options.time_limit,
_time - time0,
NamedTuple(),
(;x_converged = x_absΔ <0.0, f_converged = f_absΔ <= 0.0, g_converged = false, iterations = f_calls(d) >= options.iterations, time_limit = _time - time0 > options.time_limit, callback = stopped_by_callback, f_increased = false, ls_failed = false),
# not hit ever since stopped_by were not here?
termination_code,
)
Expand Down Expand Up @@ -361,39 +360,6 @@ function optimize(
x = xopt
end
end
termination_code = TerminationCode.NotImplemented
return MultivariateOptimizationResults(
method,
x0,# initial_x,
xopt, #pick_best_x(f_incr_pick, state),
fopt, # pick_best_f(f_incr_pick, state, d),
f_calls(d), #iteration,
f_calls(d) >= options.iterations, #iteration == options.iterations,
x_converged, # x_converged,
x_tol,#T(options.x_tol),
0.0,#T(options.x_tol),
x_absΔ,# x_abschange(state),
NaN,# x_relchange(state),
f_converged, # f_converged,
f_tol,#T(options.f_tol),
0.0,#T(options.f_tol),
f_absΔ,#f_abschange(d, state),
NaN,#f_relchange(d, state),
false,#g_converged,
0.0,#T(options.g_tol),
NaN,#g_residual(d),
false, #f_increased,
tr,
f_calls(d),
g_calls(d),
h_calls(d),
true,
options.time_limit,
_time - time0,
NamedTuple(),
termination_code,
)

end

# TODO
Expand Down
18 changes: 10 additions & 8 deletions test/multivariate/solvers/constrained/samin.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using Random
Random.seed!(3288)
@testset "SAMIN" begin
@testset "SAMIN $i" for i in keys(MVP.UnconstrainedProblems.examples)
prob = MVP.UnconstrainedProblems.examples[i]
if i !== "Himmelblau"
xtrue = prob.solutions
if length(xtrue) > 10 || i == "Powell" || i == "Parabola"
continue
end
xtrue = prob.solutions
f = OptimTestProblems.MultivariateProblems.objective(prob)
x0 = prob.initial_x
res = optimize(
f,
x0 ./ 1.1 .- 2.0,
x0 .* 1.1 .+ 2.0,
x0,
Optim.SAMIN(t0 = 2.0, r_expand = 9.0, verbosity = 0),
Optim.Options(iterations = 100000),
xtrue ./ 1.1,
xtrue .* 1.1,
xtrue .* 1.02,
Optim.SAMIN(t0 = 1.0, r_expand = 2.0, verbosity = 0),
Optim.Options(iterations = 10000),
)
@test Optim.minimum(res) < 1e-5
@test abs(prob.minimum-Optim.minimum(res)) < 1e-5
end
end
Loading