Skip to content
Open

TDTR #68

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
32 changes: 32 additions & 0 deletions src/globalization/trs_solvers/solvers/TDTR.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

a = ∇f[1]
c = ∇f[2]
b = Λ[1]
d = Λ[2]
e = Δ^2

k1 = a+c-b^2*e-d^2*e
k2 = d*e
K = k1 -4*b*k2
J = k1 +2*b*k2
L = -b*c-a*d +b^2*k2+b*d^2*e
H = b^2*c+a*d^2-b^2*d^2*e
B = b*e+k2
C = 108*B^2*H+72*e*H*K+2*K^3-36*B*K*L-108*e*L^2+sqrt(-4*(-12*e*H+K^2-12*B*L)^3+(108*B^2*H+72*e*H*K+2*K^3-36*B*K*L-108*e*L^2)^2)
g = b+d

U = -((2^(2/3)*C^(1/3) - 6*e*g^2 + (2*2^(1/3)*J^2)/C^(1/3) - 4*K)/e)
W = ((2^(2/3)*C^(1/3) - 6*e*g^2 + (2*2^(1/3)*J^2)/C^(1/3) - 4*K)/e)
V = C^(1/3)/(3*2^(1/3)*e) + 2*g^2 + (2^(1/3)*J^2)/(3*C^(1/3)*e) + (4*K)/(3*e)
Y = 2 *sqrt(6)*(e*g^3 + g*K + 2*L)
Q = V - Y/(e Sqrt[U])
R = V + Y/(e Sqrt[U])


sol1 = 1/12 * (-6g-6sqrt(R)-sqrt(6)*sqrt(U))
sol2 = 1/12 * (-6g+6sqrt(R)-sqrt(6)*sqrt(U))
sol3 = 1/12 * (-6g-6sqrt(R)+sqrt(6)*sqrt(U))
sol4 = 1/12 * (-6g+6sqrt(R)+sqrt(6)*sqrt(U))



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")