-
Notifications
You must be signed in to change notification settings - Fork 10
TR with bounds #84
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
geoffroyleconte
merged 5 commits into
JuliaSmoothOptimizers:master
from
geoffroyleconte:TR-constraints
Feb 9, 2023
Merged
TR with bounds #84
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
efce20d
TR with bounds
geoffroyleconte e957b65
remove initial guess (not feasible)
geoffroyleconte e004e8a
run demos with constraints using ci
geoffroyleconte 4e859eb
change update radius, add error plot bpdn
geoffroyleconte 23d545f
fix horizontal spacing plot nnmf
geoffroyleconte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Random | ||
| using LinearAlgebra | ||
| using ProximalOperators | ||
| using NLPModels, NLPModelsModifiers, RegularizedProblems, RegularizedOptimization | ||
| using Printf | ||
|
|
||
| include("plot-utils-bpdn.jl") | ||
|
|
||
| Random.seed!(1234) | ||
|
|
||
| function demo_solver(f, sol, h, χ, suffix = "l0-linf") | ||
| options = ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10) | ||
|
|
||
| @info " using TR to solve with" h χ | ||
| reset!(f) | ||
| TR_out = TR(f, h, χ, options, x0 = f.meta.x0) | ||
| @info "TR relative error" norm(TR_out.solution - sol) / norm(sol) | ||
| plot_bpdn(TR_out, sol, "constr-tr-r2-$(suffix)") | ||
| end | ||
|
|
||
| function demo_bpdn_constr(compound = 1) | ||
| model, nls_model, sol = bpdn_model(compound, bounds = true) | ||
| f = LSR1Model(model) | ||
| λ = norm(grad(model, zeros(model.meta.nvar)), Inf) / 10 | ||
| demo_solver(f, sol, NormL0(λ), NormLinf(1.0)) | ||
| λ = norm(grad(model, zeros(model.meta.nvar)), Inf) / 3 | ||
| demo_solver(f, sol, NormL1(λ), NormLinf(1.0), "l1-linf") | ||
| end | ||
|
|
||
| demo_bpdn_constr() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Random | ||
| using LinearAlgebra | ||
| using ProximalOperators | ||
| using NLPModels, NLPModelsModifiers, RegularizedProblems, RegularizedOptimization | ||
| using Printf | ||
|
|
||
| include("plot-utils-nnmf.jl") | ||
|
|
||
| Random.seed!(1234) | ||
|
|
||
| function demo_solver(f, h, χ, selected, Avec, m, n, k, suffix = "l0-linf") | ||
| options = ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, maxIter = 500) | ||
| @info " using TR to solve with" h χ | ||
| reset!(f) | ||
| TR_out = TR(f, h, χ, options, selected = selected) | ||
| plot_nnmf(TR_out, Avec, m, n, k, "tr-r2-$suffix") | ||
| end | ||
|
|
||
| function demo_nnmf() | ||
| m, n, k = 100, 50, 5 | ||
| model, A, selected = nnmf_model(m, n, k) | ||
| f = LSR1Model(model) | ||
| λ = norm(grad(model, rand(model.meta.nvar)), Inf) / 200 | ||
| demo_solver(f, NormL0(λ), NormLinf(1.0), selected, A, m, n, k, "l0-linf") | ||
| λ = norm(grad(model, rand(model.meta.nvar)), Inf) / 10000 | ||
| demo_solver(f, NormL1(λ), NormLinf(1.0), selected, A, m, n, k, "l1-linf") | ||
| end | ||
|
|
||
| demo_nnmf() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using PGFPlots | ||
|
|
||
| function plot_nnmf(outstruct, Avec, m, n, k, name = "tr-qr") | ||
| Comp_pg = outstruct.solver_specific[:SubsolverCounter] | ||
| objdec = outstruct.solver_specific[:Fhist] + outstruct.solver_specific[:Hhist] | ||
| x = outstruct.solution | ||
| A = reshape(Avec, m, n) | ||
| W = reshape(x[1:(m * k)], m, k) | ||
| H = reshape(x[(m * k + 1):end], k, n) | ||
| WH = W * H | ||
|
|
||
| a = GroupPlot(2, 2, groupStyle = "horizontal sep = 2.5cm") | ||
| push!(a, Axis(Plots.Image(A, (1, m), (1, n), colormap=ColorMaps.Named("Jet")), xlabel = "A matrix (reference)")) | ||
| push!(a, Axis(Plots.Image(WH, (1, m), (1, n), colormap=ColorMaps.Named("Jet")), xlabel = "WH matrix")) | ||
| push!(a, Axis(Plots.Image(H, (1, k), (1, n), colormap=ColorMaps.Named("Jet")), xlabel = "H matrix")) | ||
| push!(a, Axis(Plots.Image(abs.(A - WH), (1, m), (1, n), colormap=ColorMaps.Named("Jet")), xlabel = "|A-WH| matrix")) | ||
| save("nnmf-$(name).pdf", a) | ||
|
|
||
| b = Axis( | ||
| Plots.Linear(1:length(Comp_pg), Comp_pg, mark = "none"), | ||
| xlabel = "outer iterations", | ||
| ylabel = "inner iterations", | ||
| ymode = "log", | ||
| ) | ||
| save("nnmf-inner-outer-$(name).pdf", b) | ||
|
|
||
| c = Axis( | ||
| Plots.Linear(1:length(objdec), objdec, mark = "none"), | ||
| xlabel = "\$ k^{th}\$ \$ \\nabla f \$ Call", | ||
| ylabel = "Objective Value", | ||
| ymode = "log", | ||
| ) | ||
| save("nnmf-objdec-$(name).pdf", c) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| for (mod, mod_name) ∈ ((x -> x, "exact"), (LSR1Model, "lsr1"), (LBFGSModel, "lbfgs")) | ||
| for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) | ||
| for solver_sym ∈ (:TR,) | ||
| solver_sym == :TR && mod_name == "exact" && continue | ||
| solver_name = string(solver_sym) | ||
| solver = eval(solver_sym) | ||
| @testset "bpdn-with-bounds-$(mod_name)-$(solver_name)-$(h_name)" begin | ||
| x0 = zeros(bpdn2.meta.nvar) | ||
| p = randperm(bpdn2.meta.nvar)[1:nz] | ||
| args = solver_sym == :R2 ? () : (NormLinf(1.0),) | ||
| @test has_bounds(mod(bpdn2)) | ||
| out = solver(mod(bpdn2), h, args..., options, x0 = x0) | ||
| @test typeof(out.solution) == typeof(bpdn2.meta.x0) | ||
| @test length(out.solution) == bpdn2.meta.nvar | ||
| @test typeof(out.solver_specific[:Fhist]) == typeof(out.solution) | ||
| @test typeof(out.solver_specific[:Hhist]) == typeof(out.solution) | ||
| @test typeof(out.solver_specific[:SubsolverCounter]) == Array{Int, 1} | ||
| @test typeof(out.dual_feas) == eltype(out.solution) | ||
| @test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:Hhist]) | ||
| @test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:SubsolverCounter]) | ||
| @test obj(bpdn2, out.solution) == out.solver_specific[:Fhist][end] | ||
| @test h(out.solution) == out.solver_specific[:Hhist][end] | ||
| @test out.status == :first_order | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.