From 61adf4b7e9077422c303d09dd777ef5b7df1726b Mon Sep 17 00:00:00 2001 From: dpo Date: Wed, 8 Mar 2023 08:02:11 +0000 Subject: [PATCH] :robot: Format .jl files --- benchmarks/tables/bpdn-constr-table.jl | 54 ++++++++++++++--- benchmarks/tables/bpdn-table.jl | 70 ++++++++++++++++++---- benchmarks/tables/fh-table.jl | 73 +++++++++++++++++++--- benchmarks/tables/nnmf-table.jl | 79 ++++++++++++++++++++---- benchmarks/tables/regulopt-tables.jl | 83 +++++++++++++++----------- benchmarks/tables/svm-table.jl | 57 ++++++++++++++---- examples/demo-bpdn-constr.jl | 12 +++- examples/demo-nnmf-constr.jl | 20 ++++++- src/TRDH_alg.jl | 12 +++- src/TR_alg.jl | 13 ++-- src/input_struct.jl | 23 ++++++- test/runtests.jl | 3 +- 12 files changed, 398 insertions(+), 101 deletions(-) diff --git a/benchmarks/tables/bpdn-constr-table.jl b/benchmarks/tables/bpdn-constr-table.jl index 419901c5..438a4d74 100644 --- a/benchmarks/tables/bpdn-constr-table.jl +++ b/benchmarks/tables/bpdn-constr-table.jl @@ -13,17 +13,53 @@ verbose = 0 # 10 ϵ = 1.0e-6 maxIter = 500 maxIter_inner = 20 -options = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options6 = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false) -options5 = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = true) -options7 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner, reduce_TR = false) +options = + ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options6 = ROSolverOptions( + ν = 1.0, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, +) +options5 = ROSolverOptions( + ν = 1.0, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = true, +) +options7 = ROSolverOptions( + spectral = false, + psb = true, + ϵa = ϵ, + ϵr = ϵ, + maxIter = maxIter_inner, + reduce_TR = false, +) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR] subsolvers = [:None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH] solver_options = [options, options, options5, options6, options, options, options, options, options] -subsolver_options = [options2, options2, options2, options2, options2, options7, options2, options3, options4] # n'importe lequel si subsolver = :None +subsolver_options = + [options2, options2, options2, options2, options2, options7, options2, options3, options4] # n'importe lequel si subsolver = :None -benchmark_table(f, 1:f.meta.nvar, sol, h, λ, solvers, subsolvers, solver_options, subsolver_options, "BPDN-cstr") \ No newline at end of file +benchmark_table( + f, + 1:(f.meta.nvar), + sol, + h, + λ, + solvers, + subsolvers, + solver_options, + subsolver_options, + "BPDN-cstr", +) diff --git a/benchmarks/tables/bpdn-table.jl b/benchmarks/tables/bpdn-table.jl index 9c896d0d..fe2b116f 100644 --- a/benchmarks/tables/bpdn-table.jl +++ b/benchmarks/tables/bpdn-table.jl @@ -14,18 +14,66 @@ verbose = 0 # 10 ϵ = 1.0e-6 maxIter = 500 maxIter_inner = 40 -options = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options6 = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false) -options5 = ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = true) -options7 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner, reduce_TR = false) -options8 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner, reduce_TR = false) +options = + ROSolverOptions(ν = 1.0, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options6 = ROSolverOptions( + ν = 1.0, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, +) +options5 = ROSolverOptions( + ν = 1.0, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = true, +) +options7 = ROSolverOptions( + spectral = false, + psb = true, + ϵa = ϵ, + ϵr = ϵ, + maxIter = maxIter_inner, + reduce_TR = false, +) +options8 = + ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner, reduce_TR = false) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR] subsolvers = [:None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] -solver_options = [options, options, options5, options6, options, options, options, options, options, options] -subsolver_options = [options2, options2, options2, options2, options2, options7, options2, options3, options4, options8] # n'importe lequel si subsolver = :None +solver_options = + [options, options, options5, options6, options, options, options, options, options, options] +subsolver_options = [ + options2, + options2, + options2, + options2, + options2, + options7, + options2, + options3, + options4, + options8, +] # n'importe lequel si subsolver = :None -benchmark_table(f, 1:f.meta.nvar, sol, h, λ, solvers, subsolvers, solver_options, subsolver_options, "BPDN") \ No newline at end of file +benchmark_table( + f, + 1:(f.meta.nvar), + sol, + h, + λ, + solvers, + subsolvers, + solver_options, + subsolver_options, + "BPDN", +) diff --git a/benchmarks/tables/fh-table.jl b/benchmarks/tables/fh-table.jl index dacbd84c..99f78bfc 100644 --- a/benchmarks/tables/fh-table.jl +++ b/benchmarks/tables/fh-table.jl @@ -13,20 +13,75 @@ verbose = 0 #10 maxIter = 1000 maxIter_sub = 200 # max iter for subsolver ϵ = 1.0e-4 -options = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = + ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_sub) options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_sub) options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_sub) -options5 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = true) -options6 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false) -options7 = ROSolverOptions(spectral = false, psb = true, reduce_TR = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_sub) -options8 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false, reduce_TR = false) +options5 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = true, +) +options6 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, +) +options7 = ROSolverOptions( + spectral = false, + psb = true, + reduce_TR = false, + ϵa = ϵ, + ϵr = ϵ, + maxIter = maxIter_sub, +) +options8 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, + reduce_TR = false, +) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR] subsolvers = [:None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH] -solver_options = [options, options, options5, options6, options8, options, options, options, options, options] -subsolver_options = [options2, options2, options2, options2, options2, options2, options7, options2, options3, options4] +solver_options = + [options, options, options5, options6, options8, options, options, options, options, options] +subsolver_options = [ + options2, + options2, + options2, + options2, + options2, + options2, + options7, + options2, + options3, + options4, +] subset = 2:10 # issues with R2 alone -benchmark_table(f, 1:f.meta.nvar, [], h, λ, solvers[subset], subsolvers[subset], solver_options[subset], subsolver_options[subset], - "FH with ν = $ν, λ = $λ") +benchmark_table( + f, + 1:(f.meta.nvar), + [], + h, + λ, + solvers[subset], + subsolvers[subset], + solver_options[subset], + subsolver_options[subset], + "FH with ν = $ν, λ = $λ", +) diff --git a/benchmarks/tables/nnmf-table.jl b/benchmarks/tables/nnmf-table.jl index 7f6b1a61..915e53ee 100644 --- a/benchmarks/tables/nnmf-table.jl +++ b/benchmarks/tables/nnmf-table.jl @@ -11,19 +11,74 @@ h = NormL0(λ) maxIter = 500 maxIter_inner = 40 verbose = 0 #10 -options = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options5 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = true) -options6 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false) -options7 = ROSolverOptions(spectral = false, psb = true, reduce_TR = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options8 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false, reduce_TR = false) +options = + ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options5 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = true, +) +options6 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, +) +options7 = ROSolverOptions( + spectral = false, + psb = true, + reduce_TR = false, + ϵa = ϵ, + ϵr = ϵ, + maxIter = maxIter_inner, +) +options8 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, + reduce_TR = false, +) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR] subsolvers = [:None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] -solver_options = [options, options, options5, options6, options8, options, options, options, options, options] -subsolver_options = [options2, options2, options2, options2, options2, options2, options7, options2, options3, options4] +solver_options = + [options, options, options5, options6, options8, options, options, options, options, options] +subsolver_options = [ + options2, + options2, + options2, + options2, + options2, + options2, + options7, + options2, + options3, + options4, +] -benchmark_table(f, selected, [], h, λ, solvers, subsolvers, solver_options, subsolver_options, - "NNMF with m = $m, n = $n, k = $k, ν = $ν, λ = $λ") \ No newline at end of file +benchmark_table( + f, + selected, + [], + h, + λ, + solvers, + subsolvers, + solver_options, + subsolver_options, + "NNMF with m = $m, n = $n, k = $k, ν = $ν, λ = $λ", +) diff --git a/benchmarks/tables/regulopt-tables.jl b/benchmarks/tables/regulopt-tables.jl index 674698b9..e005f7d8 100644 --- a/benchmarks/tables/regulopt-tables.jl +++ b/benchmarks/tables/regulopt-tables.jl @@ -2,7 +2,12 @@ using PrettyTables using Random using LinearAlgebra using ProximalOperators -using NLPModels, NLPModelsModifiers, RegularizedProblems, RegularizedOptimization, ShiftedProximalOperators, SolverBenchmark +using NLPModels, + NLPModelsModifiers, + RegularizedProblems, + RegularizedOptimization, + ShiftedProximalOperators, + SolverBenchmark using Printf # utils for extracting stats / display table @@ -11,12 +16,19 @@ modelname(nlp::LBFGSModel) = "LBFGS" modelname(nlp::SpectralGradientModel) = "SpectralGradient" modelname(nlp::DiagonalQNModel) = "DiagonalQN" subsolvername(subsolver::Symbol) = subsolver == :None ? "" : string("-", subsolver) -function options_str(options::ROSolverOptions, solver::Symbol, subsolver_options::ROSolverOptions, subsolver::Symbol) +function options_str( + options::ROSolverOptions, + solver::Symbol, + subsolver_options::ROSolverOptions, + subsolver::Symbol, +) if solver == :TRDH out_str = !options.spectral ? (options.psb ? "-DiagQN-PSB" : "-DiagQN-Andrei") : "-Spectral" out_str = (options.reduce_TR) ? out_str : string(out_str, "-noredTR") elseif solver == :TR && subsolver == :TRDH - out_str = !subsolver_options.spectral ? (subsolver_options.psb ? "-DiagQN-PSB" : "-DiagQN-Andrei") : "-Spectral" + out_str = + !subsolver_options.spectral ? (subsolver_options.psb ? "-DiagQN-PSB" : "-DiagQN-Andrei") : + "-Spectral" out_str = (subsolver_options.reduce_TR) ? out_str : string(out_str, "-noredTR") else out_str = "" @@ -46,38 +58,42 @@ function benchmark_table( subsolver_options, pb_name::String, ) - - row_names = ["$(solver)$(subsolvername(subsolver))$(options_str(opt, solver, subsolver_opt, subsolver))" - for (solver, opt, subsolver, subsolver_opt) in zip(solvers, solver_options, subsolvers, subsolver_options)] + row_names = [ + "$(solver)$(subsolvername(subsolver))$(options_str(opt, solver, subsolver_opt, subsolver))" + for (solver, opt, subsolver, subsolver_opt) in + zip(solvers, solver_options, subsolvers, subsolver_options) + ] n∇f_evals = [] nprox_evals = [] solver_stats = [] - for (solver, subsolver, opt, sub_opt) in zip(solvers, subsolvers, solver_options, subsolver_options) + for (solver, subsolver, opt, sub_opt) in + zip(solvers, subsolvers, solver_options, subsolver_options) @info " using $solver with subsolver = $subsolver" args = solver == :R2 ? () : (NormLinf(1.0),) if subsolver == :None solver_out = eval(solver)(f, h, args..., opt, x0 = f.meta.x0, selected = selected) else - solver_out = eval(solver)(f, h, args..., opt, x0 = f.meta.x0, subsolver = eval(subsolver), - subsolver_options = sub_opt, selected = selected) + solver_out = eval(solver)( + f, + h, + args..., + opt, + x0 = f.meta.x0, + subsolver = eval(subsolver), + subsolver_options = sub_opt, + selected = selected, + ) end push!(n∇f_evals, grad_evals(f)) push!(nprox_evals, nb_prox_evals(solver_out, solver)) push!(solver_stats, solver_out) reset!(f) - end if length(sol) == 0 - header = [ - "f(x)", - "h(x)/λ", - "ξ", - "∇f evals", - "prox calls", - ] + header = ["f(x)", "h(x)/λ", "ξ", "∇f evals", "prox calls"] else header = [ "f(x) (true = $(round(obj(model, sol); sigdigits = 4)))", @@ -91,7 +107,7 @@ function benchmark_table( n_solvers = length(row_names) data = Matrix{Any}(undef, n_solvers, length(header)) - for i=1:n_solvers + for i = 1:n_solvers solver_out = solver_stats[i] x = solver_out.solution fx = solver_out.solver_specific[:Fhist][end] @@ -108,32 +124,29 @@ function benchmark_table( end if length(sol) == 0 - print_formats = ft_printf(["%7.3e", "%7.1e", "%7.1e", "%i","%i"], 1:length(header)) + print_formats = ft_printf(["%7.3e", "%7.1e", "%7.1e", "%i", "%i"], 1:length(header)) else - print_formats = ft_printf(["%7.3e", "%7.1e", "%7.1e", "%7.3e", "%i","%i"], 1:length(header)) + print_formats = ft_printf(["%7.3e", "%7.1e", "%7.1e", "%7.3e", "%i", "%i"], 1:length(header)) end - return pretty_table(data; - header = header, - row_names= row_names, - title = "$pb_name $(modelname(f)) $(typeof(h).name.name)", - # backend = Val(:latex), - formatters = (print_formats, - # (v, i, j) -> (SolverBenchmark.safe_latex_AbstractFloat(v)), - ), - ) + return pretty_table( + data; + header = header, + row_names = row_names, + title = "$pb_name $(modelname(f)) $(typeof(h).name.name)", + # backend = Val(:latex), + formatters = ( + print_formats, + # (v, i, j) -> (SolverBenchmark.safe_latex_AbstractFloat(v)), + ), + ) end - - # λ = norm(grad(model, rand(model.meta.nvar)), Inf) / 100000 # h = NormL1(λ) # benchmark_table(f, selected, [], h, λ, solvers, subsolvers, solver_options, subsolver_options, # "NNMF with m = $m, n = $n, k = $k, ν = 1.0e-3,") - - - # header = ["TR LSR1 L0Box", "R2 LSR1 L0Box", "LM L0Box", "LMTR L0Box"] # TR_out = TR(f, h, χ, options, x0 = f.meta.x0) # n∇f_TR = neval_grad(f) @@ -154,4 +167,4 @@ end # n∇f_evals = [n∇f_TR, n∇f_R2, n∇f_LM, n∇f_LMTR] # nprox_evals = [prox_evals_TR, prox_evals_R2, prox_evals_LM, prox_evals_LMTR] -# solver_stats = [TR_out, R2_out, LM_out, LMTR_out] \ No newline at end of file +# solver_stats = [TR_out, R2_out, LM_out, LMTR_out] diff --git a/benchmarks/tables/svm-table.jl b/benchmarks/tables/svm-table.jl index 05be38eb..a8c302f1 100644 --- a/benchmarks/tables/svm-table.jl +++ b/benchmarks/tables/svm-table.jl @@ -2,7 +2,7 @@ include("regulopt-tables.jl") using MLDatasets Random.seed!(1234) -nlp_train, nls_train, sol_train = RegularizedProblems.svm_train_model() +nlp_train, nls_train, sol_train = RegularizedProblems.svm_train_model() nlp_test, nls_test, sol_test = RegularizedProblems.svm_test_model() f = LSR1Model(nlp_train) f_test = LSR1Model(nlp_test) @@ -14,19 +14,54 @@ verbose = 0 #10 ϵ = 1.0e-6 maxIter = 500 maxIter_inner = 40 -options = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) -options5 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = true) -options6 = ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = false, psb = false) -options7 = ROSolverOptions(spectral = false, psb = true, reduce_TR = false, ϵa = ϵ, ϵr = ϵ, maxIter=maxIter_inner) +options = + ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options3 = ROSolverOptions(spectral = false, psb = false, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options4 = ROSolverOptions(spectral = true, ϵa = ϵ, ϵr = ϵ, maxIter = maxIter_inner) +options5 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = true, +) +options6 = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = false, + psb = false, +) +options7 = ROSolverOptions( + spectral = false, + psb = true, + reduce_TR = false, + ϵa = ϵ, + ϵr = ϵ, + maxIter = maxIter_inner, +) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR] subsolvers = [:None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH] solver_options = [options, options, options5, options6, options, options, options, options, options] -subsolver_options = [options2, options2, options2, options2, options2, options2, options7, options3, options4] +subsolver_options = + [options2, options2, options2, options2, options2, options2, options7, options3, options4] subset = 1:9 -benchmark_table(f, 1:f.meta.nvar, [], h, λ, solvers[subset], subsolvers[subset], solver_options[subset], subsolver_options[subset], - "SVM with ν = $ν, λ = $λ") \ No newline at end of file +benchmark_table( + f, + 1:(f.meta.nvar), + [], + h, + λ, + solvers[subset], + subsolvers[subset], + solver_options[subset], + subsolver_options[subset], + "SVM with ν = $ν, λ = $λ", +) diff --git a/examples/demo-bpdn-constr.jl b/examples/demo-bpdn-constr.jl index 21559562..ca27b323 100644 --- a/examples/demo-bpdn-constr.jl +++ b/examples/demo-bpdn-constr.jl @@ -9,7 +9,15 @@ include("plot-utils-bpdn.jl") Random.seed!(1234) function demo_solver(f, nls, sol, h, χ, suffix = "l0-linf") - options = ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, spectral = false, psb = true) + options = ROSolverOptions( + ν = 1.0, + β = 1e16, + ϵa = 1e-6, + ϵr = 1e-6, + verbose = 10, + spectral = false, + psb = true, + ) @info " using TR to solve with" h χ reset!(f) @@ -22,7 +30,7 @@ function demo_solver(f, nls, sol, h, χ, suffix = "l0-linf") R2_out = R2(f, h, options, x0 = f.meta.x0) @info "R2 relative error" norm(R2_out.solution - sol) / norm(sol) plot_bpdn(R2_out, sol, "constr-r2-$(suffix)") - + @info " using TRDH to solve with" h χ reset!(f) TRDH_out = TRDH(f, h, χ, options, x0 = f.meta.x0) diff --git a/examples/demo-nnmf-constr.jl b/examples/demo-nnmf-constr.jl index 91f74071..5ebffeb1 100644 --- a/examples/demo-nnmf-constr.jl +++ b/examples/demo-nnmf-constr.jl @@ -9,7 +9,15 @@ include("plot-utils-nnmf.jl") Random.seed!(1234) function demo_solver(f, h, χ, selected, Avec, m, n, k, suffix = "l0-linf") - options = ROSolverOptions(ν = 1.0e-3, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, maxIter = 500, spectral = true) + options = ROSolverOptions( + ν = 1.0e-3, + β = 1e16, + ϵa = 1e-6, + ϵr = 1e-6, + verbose = 10, + maxIter = 500, + spectral = true, + ) @info " using TR to solve with" h χ reset!(f) TR_out = TR(f, h, χ, options, selected = selected) @@ -28,7 +36,15 @@ function demo_solver(f, h, χ, selected, Avec, m, n, k, suffix = "l0-linf") subsolver_options = ROSolverOptions(spectral = false, psb = true) @info " using TR with TRDH as subproblem to solve with" h χ reset!(f) - TR2_out = TR(f, h, χ, options, selected = selected, subsolver = TRDH, subsolver_options = subsolver_options) + TR2_out = TR( + f, + h, + χ, + options, + selected = selected, + subsolver = TRDH, + subsolver_options = subsolver_options, + ) # plot_nnmf(TR2_out, Avec, m, n, k, "tr-trdh-$suffix") @info " using TRDH to solve with" h χ diff --git a/src/TRDH_alg.jl b/src/TRDH_alg.jl index 126ae2f1..da35b030 100644 --- a/src/TRDH_alg.jl +++ b/src/TRDH_alg.jl @@ -47,7 +47,13 @@ In the second form, instead of `nlp`, the user may pass in * `Hobj_hist`: an array with the history of values of the nonsmooth objective * `Complex_hist`: an array with the history of number of inner iterations. """ -function TRDH(nlp::AbstractNLPModel{R}, h, χ, options::ROSolverOptions{R}; kwargs...) where {R <: Real} +function TRDH( + nlp::AbstractNLPModel{R}, + h, + χ, + options::ROSolverOptions{R}; + kwargs..., +) where {R <: Real} kwargs_dict = Dict(kwargs...) x0 = pop!(kwargs_dict, :x0, nlp.meta.x0) xk, k, outdict = TRDH( @@ -330,7 +336,9 @@ function TRDH( #! format: on @info "TRDH: terminating with √ξ1 = $(sqrt(ξ1))" else - @info @sprintf "%6d %8.1e %8.1e %7.1e %8s %7.1e %7.1e %7.1e %7.1e" k fk hk sqrt(ξ) "" Δk χ(xk) χ(s) νInv + @info @sprintf "%6d %8.1e %8.1e %7.1e %8s %7.1e %7.1e %7.1e %7.1e" k fk hk sqrt(ξ) "" Δk χ( + xk, + ) χ(s) νInv @info "TRDH: terminating with √ξ = $(sqrt(ξ))" end end diff --git a/src/TR_alg.jl b/src/TR_alg.jl index 3841e69c..7e4368a7 100644 --- a/src/TR_alg.jl +++ b/src/TR_alg.jl @@ -101,8 +101,10 @@ function TR( xkn = similar(xk) s = zero(xk) - ψ = (has_bounds(f) || subsolver == TRDH) ? - shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) : shifted(h, xk, Δk, χ) + ψ = + (has_bounds(f) || subsolver == TRDH) ? + shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) : + shifted(h, xk, Δk, χ) Fobj_hist = zeros(maxIter) Hobj_hist = zeros(maxIter) @@ -208,7 +210,8 @@ function TR( if η1 ≤ ρk < Inf xk .= xkn - (has_bounds(f) || subsolver == TRDH) && set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) + (has_bounds(f) || subsolver == TRDH) && + set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) #update functions fk = fkn @@ -227,8 +230,8 @@ function TR( if ρk < η1 || ρk == Inf Δk = Δk / 2 - (has_bounds(f) || subsolver == TRDH) ? set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) : - set_radius!(ψ, Δk) + (has_bounds(f) || subsolver == TRDH) ? + set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) : set_radius!(ψ, Δk) end tired = k ≥ maxIter || elapsed_time > maxTime end diff --git a/src/input_struct.jl b/src/input_struct.jl index 2ff0c799..de262fc7 100644 --- a/src/input_struct.jl +++ b/src/input_struct.jl @@ -18,7 +18,7 @@ mutable struct ROSolverOptions{R} β::R # TR size as factor of first PG step spectral::Bool # for TRDH: use spectral gradient update if true, otherwise DiagonalQN psb::Bool # for TRDH with DiagonalQN (spectral = false): use PSB update if true, otherwise Andrei update - reduce_TR::Bool + reduce_TR::Bool function ROSolverOptions{R}(; ϵa::R = √eps(R), @@ -54,7 +54,26 @@ mutable struct ROSolverOptions{R} @assert γ > 1 @assert θ > 0 @assert β ≥ 1 - return new{R}(ϵa, ϵr, neg_tol, Δk, verbose, maxIter, maxTime, σmin, η1, η2, α, ν, γ, θ, β, spectral, psb, reduce_TR) + return new{R}( + ϵa, + ϵr, + neg_tol, + Δk, + verbose, + maxIter, + maxTime, + σmin, + η1, + η2, + α, + ν, + γ, + θ, + β, + spectral, + psb, + reduce_TR, + ) end end diff --git a/test/runtests.jl b/test/runtests.jl index c4629acc..b63743b4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,7 +5,8 @@ using NLPModels, NLPModelsModifiers, RegularizedProblems, RegularizedOptimizatio const global compound = 1 const global nz = 10 * compound -const global options = ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, spectral = true) +const global options = + ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, spectral = true) const global bpdn, bpdn_nls, sol = bpdn_model(compound) const global bpdn2, bpdn_nls2, sol2 = bpdn_model(compound, bounds = true) const global λ = norm(grad(bpdn, zeros(bpdn.meta.nvar)), Inf) / 10