Skip to content

add safety check for adaptive #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 13, 2024
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
27 changes: 22 additions & 5 deletions examples/optimal_experiment_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ using Random
using Distributions
using LinearAlgebra
using Statistics
using SCIP
using HiGHS
using MathOptInterface
const MOI = MathOptInterface
using SparseArrays
using Test
using StableRNGs

# The Optimal Experiment Design Problem consists of choosing a subset of experiments
# maximising the information gain.
Expand All @@ -34,7 +35,10 @@ seed - for the Random functions.
m - number of experiments.
Build the experiment matrix A.
"""
function build_data(m)
function build_data(m; seed=nothing)
if seed != nothing
rng = StableRNG(seed)
end
n = Int(floor(m/10))
B = rand(m,n)
B = B'*B
Expand All @@ -51,7 +55,7 @@ end
Build MOI version of the lmo.
"""
function build_moi_lmo(m)
o = SCIP.Optimizer()
o = HiGHS.Optimizer()
MOI.empty!(o)
MOI.set(o, MOI.Silent(), true)

Expand Down Expand Up @@ -267,7 +271,7 @@ m = 300
x_b, _, primal, dual_gap, traj_data_b, _ = FrankWolfe.blended_conditional_gradient(f, grad!, lmo, x0, verbose=true, trajectory=true,line_search=FrankWolfe.Secant(domain_oracle=domain_oracle))

@test traj_data_s[end][1] < traj_data[end][1]
@test traj_data_d[end][1] <= traj_data_s[end][1]
@test traj_data_d[end][1] <= traj_data[end][1]
@test traj_data_b[end][1] <= traj_data_s[end][1]
@test isapprox(f(x_s), f(x))
@test isapprox(f(x_s), f(x_d))
Expand Down Expand Up @@ -302,11 +306,24 @@ m = 300
x_b, _, primal, dual_gap, traj_data_b, _ = FrankWolfe.blended_conditional_gradient(f, grad!, lmo, x0, verbose=true, trajectory=true,line_search=FrankWolfe.Secant(domain_oracle=domain_oracle))

@test traj_data_s[end][1] < traj_data[end][1]
@test traj_data_d[end][1] <= traj_data_s[end][1]
@test traj_data_d[end][1] <= traj_data[end][1]
@test traj_data_b[end][1] <= traj_data_s[end][1]
@test isapprox(f(x_s), f(x))
@test isapprox(f(x_s), f(x_d))
@test isapprox(f(x_s), f(x_b))
end
end

@testset "Failing Optimal Design Instance with AFW" begin
seed = 8775360557774874450
m = 100
A = build_data(m, seed=seed)
f, grad! = build_a_criterion(A)

lmo = FrankWolfe.ProbabilitySimplexOracle(1.0)
x0, active_set, _ = build_start_point(A)

_, _, primal, dual_gap, _, _ = FrankWolfe.away_frank_wolfe(f, grad!, lmo, active_set; verbose=true)
@test isfinite(primal)
end

3 changes: 2 additions & 1 deletion src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ function perform_line_search(
niter = 0
clipping = false
gradient_storage = storage.gradient_storage
f_x = f(x)

grad!(gradient_storage, x_storage)
while 0 > fast_dot(gradient_storage, d) && γ ≥ 100 * eps(float(γ))
while f(x_storage) > f_x || 0 > fast_dot(gradient_storage, d) && γ ≥ 100 * eps(float(γ))
M *= line_search.tau
γ = min(max(dot_dir / (M * ndir2), 0), gamma_max)
x_storage = muladd_memory_mode(memory_mode, x_storage, x, γ, d)
Expand Down
Loading