Skip to content
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
28 changes: 23 additions & 5 deletions examples/plot-utils-nnmf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ function plot_nnmf(outstruct, Avec, m, n, k, name = "tr-qr")
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"))
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(
Expand Down
2 changes: 1 addition & 1 deletion src/R2_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function R2(nlp::AbstractNLPModel, args...; kwargs...)
xk, k, outdict = R2(
x -> obj(nlp, x),
(g, x) -> grad!(nlp, x, g),
args...,
args...,
x0;
l_bound = nlp.meta.lvar,
u_bound = nlp.meta.uvar,
Expand Down
13 changes: 8 additions & 5 deletions src/TR_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function TR(
subsolver_logger::Logging.AbstractLogger = Logging.NullLogger(),
subsolver = R2,
subsolver_options = ROSolverOptions(),
selected::AbstractVector{<:Integer} = 1:f.meta.nvar,
selected::AbstractVector{<:Integer} = 1:(f.meta.nvar),
) where {H, X}
start_time = time()
elapsed_time = 0.0
Expand Down Expand Up @@ -101,7 +101,8 @@ function TR(

xkn = similar(xk)
s = zero(xk)
ψ = has_bounds(f) ? shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) :
ψ =
has_bounds(f) ? shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) :
shifted(h, xk, Δk, χ)

Fobj_hist = zeros(maxIter)
Expand Down Expand Up @@ -169,8 +170,9 @@ function TR(

subsolver_options.ϵa = k == 1 ? 1.0e-5 : max(ϵ, min(1e-2, sqrt(ξ1)) * ξ1)
∆_effective = min(β * χ(s), Δk)
has_bounds(f) ? set_bounds!(ψ, max.(-∆_effective, l_bound - xk), min.(∆_effective, u_bound - xk)) :
set_radius!(ψ, ∆_effective)
has_bounds(f) ?
set_bounds!(ψ, max.(-∆_effective, l_bound - xk), min.(∆_effective, u_bound - xk)) :
set_radius!(ψ, ∆_effective)
s, iter, _ = with_logger(subsolver_logger) do
subsolver(φ, ∇φ!, ψ, subsolver_options, s)
end
Expand Down Expand Up @@ -225,7 +227,8 @@ function TR(

if ρk < η1 || ρk == Inf
Δk = Δk / 2
has_bounds(f) ? set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) : set_radius!(ψ, Δk)
has_bounds(f) ? set_bounds!(ψ, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk)) :
set_radius!(ψ, Δk)
end
tired = k ≥ maxIter || elapsed_time > maxTime
end
Expand Down