Skip to content

Commit

Permalink
Merge branch 'master' into optimal-design
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrych committed Sep 4, 2024
2 parents 0635fe8 + 9bbc512 commit c52da3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Tullio = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[targets]
test = ["CSV", "Combinatorics", "DataFrames", "DoubleFloats", "DynamicPolynomials", "FiniteDifferences", "ForwardDiff", "GLPK", "JSON", "JuMP", "LaTeXStrings", "MAT", "MultivariatePolynomials", "Plots", "PlotThemes", "Polyhedra", "ReverseDiff", "ZipFile", "Test", "Clp", "Hypatia"]
test = ["CSV", "Combinatorics", "DataFrames", "DoubleFloats", "DynamicPolynomials", "FiniteDifferences", "ForwardDiff", "GLPK", "JSON", "JuMP", "LaTeXStrings", "MAT", "MultivariatePolynomials", "Plots", "PlotThemes", "Polyhedra", "ReverseDiff", "ZipFile", "Test", "Tullio", "Clp", "Hypatia"]
29 changes: 20 additions & 9 deletions src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,31 @@ end
Base.print(io::IO, ::Backtracking) = print(io, "Backtracking")

"""
Secant(limit_num_steps, tol)
Secant(limit_num_steps, tol, domain_oracle)
Secant line search strategy, which iteratively refines the step size using the secant method.
This method is geared towards problems with self-concordant functions (but might require extra structure)
and potentially faster than the backtracking line search. Order of convergence is superlinear
with exponent 1.618 (Golden Ratio) but not quite quadratic. Convergence is not guaranteed in general
and potentially faster than the backtracking line search.
The order of convergence is superlinear with exponent 1.618 (Golden Ratio) but not quite quadratic.
Convergence is not guaranteed in general.
# Arguments
- `limit_num_steps::Int`: Maximum number of iterations for the secant method. (default 40)
- `tol::Float64`: Tolerance for convergence. (default 1e-8)
- `domain_oracle::Function`, returns true if the argument x is in the domain of the objective function f.
# References
- [Secant Method](https://en.wikipedia.org/wiki/Secant_method)
"""
struct Secant <: LineSearchMethod
struct Secant{F} <: LineSearchMethod
limit_num_steps::Int
tol::Float64
domain_oracle::F
end

function Secant(limit_num_steps, tol)
return Secant(limit_num_steps, tol, x -> true)
end

function Secant(; limit_num_steps=40, tol=1e-8)
Expand All @@ -391,15 +398,19 @@ function perform_line_search(
memory_mode,
)
dot_gdir = dot(gradient, d)
# gamma = min(gamma_max, abs(dot_gdir)) # Start with a potentially smaller step
gamma = gamma_max
storage, grad_storage = workspace
storage = muladd_memory_mode(memory_mode, storage, x, gamma, d)
while !line_search.domain_oracle(storage)
gamma_max /= 2
gamma = gamma_max
storage = muladd_memory_mode(memory_mode, storage, x, gamma, d)
end
new_val = f(storage)
best_gamma = gamma
best_val = new_val
i = 1

gamma_prev = zero(best_gamma)
while abs(dot_gdir) > line_search.tol
if i > line_search.limit_num_steps
return best_gamma
Expand All @@ -412,9 +423,9 @@ function perform_line_search(
return best_gamma
end

gamma_prev = (i == 1) ? 0 : gamma
gamma = gamma - dot_gdir_new * (gamma - gamma_prev) / (dot_gdir_new - dot_gdir)
gamma = clamp(gamma, 0, gamma_max) # Ensure gamma stays in [0, gamma_max]
gamma_new = gamma - dot_gdir_new * (gamma - gamma_prev) / (dot_gdir_new - dot_gdir)
gamma_prev = gamma
gamma = clamp(gamma_new, 0, gamma_max) # Ensure gamma stays in [0, gamma_max]

storage = muladd_memory_mode(memory_mode, storage, x, gamma, d)
new_val = f(storage)
Expand Down

0 comments on commit c52da3a

Please sign in to comment.