Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/ProximalAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ function run(solver::ProximalAlgorithm{I, T})::Tuple{I, T} where {I, T}
# [...]
# end
#
if verbose(solver) display(solver) end
for (it, point) in enumerate(solver)
if verbose(solver, it) display(solver, it) end
end
if verbose(solver) display(solver, it) end
return (it, point)
end

Expand Down
20 changes: 17 additions & 3 deletions src/algorithms/DouglasRachford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
################################################################################
# Constructor(s)

function DRSIterator(x0::BlockArray{R}; f=Zero(), g=Zero(), gamma::R=1.0, maxit::I=10000, tol::R=1e-4, verbose=1) where {I, R}
function DRSIterator(x0::BlockArray{R}; f=Zero(), g=Zero(), gamma::R=1.0, maxit::I=10000, tol::R=1e-4, verbose=2) where {I, R}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why verbose=2 by default? I would say 1, that is the minimum (nonzero) verbosity.

y = blockcopy(x0)
r = blockcopy(x0)
z = blockcopy(x0)
Expand All @@ -38,9 +38,23 @@ maxit(sol::DRSIterator) = sol.maxit

converged(sol::DRSIterator, it) = blockmaxabs(sol.FPR_x)/sol.gamma <= sol.tol

verbose(sol::DRSIterator, it) = sol.verbose > 0
verbose(sol::DRSIterator) = sol.verbose > 0
verbose(sol::DRSIterator, it) = sol.verbose > 0 && (sol.verbose == 1 ? true : (it == 1 || it%100 == 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the above comment: should be sol.verbose == 2 ? true. Furthermore, I would make that 100 an option (output_freq maybe? Of course defaulting to 100).


display(sol::DRSIterator, it) = println("$(it) $(blockmaxabs(sol.FPR_x)/sol.gamma)")
function display(sol::DRSIterator)
@printf("%6s | %10s | %10s |\n ", "it", "gamma", "fpr")
@printf("------|------------|------------|\n")
end

function display(sol::DRSIterator, it)
@printf("%6d | %7.4e | %7.4e | \n", it, sol.gamma, blockmaxabs(sol.FPR_x)/sol.gamma)
end

function Base.show(io::IO, sol::DRSIterator)
println(io, "Douglas-Rachford Splitting" )
println(io, "fpr : $(blockmaxabs(sol.FPR_x))")
println(io, "gamma : $(sol.gamma)")
end

################################################################################
# Initialization
Expand Down
18 changes: 15 additions & 3 deletions src/algorithms/ForwardBackward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
################################################################################
# Constructor

function FBSIterator(x0::T; fs=Zero(), As=Identity(blocksize(x0)), fq=Zero(), Aq=Identity(blocksize(x0)), g=Zero(), gamma::R=-1.0, maxit::I=10000, tol::R=1e-4, adaptive=false, fast=false, verbose=1) where {I, R, T}
function FBSIterator(x0::T; fs=Zero(), As=Identity(blocksize(x0)), fq=Zero(), Aq=Identity(blocksize(x0)), g=Zero(), gamma::R=-1.0, maxit::I=10000, tol::R=1e-4, adaptive=false, fast=false, verbose=2) where {I, R, T}
n = blocksize(x0)
mq = size(Aq, 1)
ms = size(As, 1)
Expand All @@ -69,10 +69,22 @@ maxit(sol::FBSIterator) = sol.maxit

converged(sol::FBSIterator, it) = blockmaxabs(sol.FPR_x)/sol.gamma <= sol.tol

verbose(sol::FBSIterator, it) = sol.verbose > 0
verbose(sol::FBSIterator) = sol.verbose > 0
verbose(sol::FBSIterator, it) = sol.verbose > 0 && (sol.verbose == 1 ? true : (it == 1 || it%100 == 0))

function display(sol::FBSIterator)
@printf("%6s | %10s | %10s |\n ", "it", "gamma", "fpr")
@printf("------|------------|------------|\n")
end

function display(sol::FBSIterator, it)
println("$(it) $(sol.gamma) $(blockmaxabs(sol.FPR_x)/sol.gamma)")
@printf("%6d | %7.4e | %7.4e | \n", it, sol.gamma, blockmaxabs(sol.FPR_x)/sol.gamma)
end

function Base.show(io::IO, sol::FBSIterator)
println(io, (sol.fast ? "Fast " : "")*"Forward-Backward Splitting" )
println(io, "fpr : $(blockmaxabs(sol.FPR_x))")
println(io, "gamma : $(sol.gamma)")
end

################################################################################
Expand Down
6 changes: 6 additions & 0 deletions src/algorithms/Template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ maxit(sol::TemplateIterator) = sol.maxit

converged(sol::TemplateIterator, it) = false

verbose(sol::TemplateIterator) = true
verbose(sol::TemplateIterator, it) = true

display(sol::TemplateIterator) = println("its ")
display(sol::TemplateIterator, it) = println("$(it) iterations performed")

function Base.show(io::IO, sol::TemplateIterator)
print(io, "Template Solver" )
end

################################################################################
# Initialization

Expand Down
19 changes: 16 additions & 3 deletions src/algorithms/ZeroFPR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end
################################################################################
# Constructor

function ZeroFPRIterator(x0::T; fs=Zero(), As=Identity(blocksize(x0)), fq=Zero(), Aq=Identity(blocksize(x0)), g=Zero(), gamma::R=-1.0, maxit::I=10000, tol::R=1e-4, adaptive=false, memory=10, verbose=1, alpha=0.95, sigma=0.5) where {I, R, T}
function ZeroFPRIterator(x0::T; fs=Zero(), As=Identity(blocksize(x0)), fq=Zero(), Aq=Identity(blocksize(x0)), g=Zero(), gamma::R=-1.0, maxit::I=10000, tol::R=1e-4, adaptive=false, memory=10, verbose=2, alpha=0.95, sigma=0.5) where {I, R, T}
n = blocksize(x0)
mq = size(Aq, 1)
ms = size(As, 1)
Expand All @@ -62,10 +62,23 @@ maxit(sol::ZeroFPRIterator) = sol.maxit

converged(sol::ZeroFPRIterator, it) = blockmaxabs(sol.FPR_x)/sol.gamma <= sol.tol

verbose(sol::ZeroFPRIterator, it) = sol.verbose > 0
verbose(sol::ZeroFPRIterator) = sol.verbose > 0
verbose(sol::ZeroFPRIterator, it) = sol.verbose > 0 && (sol.verbose == 1 ? true : (it == 1 || it%100 == 0))

function display(sol::ZeroFPRIterator)
@printf("%6s | %10s | %10s | %10s | %10s |\n ", "it", "gamma", "fpr", "tau", "FBE")
@printf("------|------------|------------|------------|------------|\n")
end
function display(sol::ZeroFPRIterator, it)
println("$(it) $(sol.gamma) $(blockmaxabs(sol.FPR_x)/sol.gamma) $(blockmaxabs(sol.d)) $(sol.tau) $(sol.FBE_x)")
@printf("%6d | %7.4e | %7.4e | %7.4e | %7.4e | \n", it, sol.gamma, blockmaxabs(sol.FPR_x)/sol.gamma, sol.tau, sol.FBE_x)
end

function Base.show(io::IO, sol::ZeroFPRIterator)
println(io, "ZeroFPR" )
println(io, "fpr : $(blockmaxabs(sol.FPR_x))")
println(io, "gamma : $(sol.gamma)")
println(io, "tau : $(sol.tau)")
print( io, "FBE : $(sol.FBE_x)")
end

################################################################################
Expand Down
3 changes: 3 additions & 0 deletions test/test_l1logreg_small.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fs=f, As=A, g=g, tol=1e-6, adaptive=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 1658
println(sol)

# Fast/Adaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fs=f, As=A, g=g, tol=1e-6, adaptive=true, fast=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 473
println(sol)

# ZeroFPR/Adaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fs=f, As=A, g=g, tol=1e-6, adaptive=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 19
println(sol)
7 changes: 7 additions & 0 deletions test/test_lasso_small.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,51 @@ x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=A, g=g, gamma=1.0/norm(A)^2)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 140
println(sol)

# Nonfast/Adaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=A, g=g, adaptive=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 247
println(sol)

# Fast/Nonadaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=A, g=g, gamma=1.0/norm(A)^2, fast=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 94
println(sol)

# Fast/Adaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=A, g=g, adaptive=true, fast=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 156
println(sol)

# ZeroFPR/Nonadaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fq=f, Aq=A, g=g, gamma=1.0/norm(A)^2)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 8
println(sol)

# ZeroFPR/Adaptive

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fq=f, Aq=A, g=g, adaptive=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 10
println(sol)

# Douglas-Rachford

x0 = zeros(n)
@time it, x, sol = ProximalAlgorithms.DRS(x0; f=f2, g=g, gamma=10.0/norm(A)^2)
@test vecnorm(x - x_star, Inf) <= 1e-4
println(sol)
6 changes: 6 additions & 0 deletions test/test_lasso_small_split_f.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,44 @@ x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, gamma=1.0/norm(A)^2)
@test vecnorm(x .- x_star, Inf) <= 1e-4
@test it == 140
println(sol)

# Nonfast/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, adaptive=true)
@test vecnorm(x .- x_star, Inf) <= 1e-4
@test it == 247
println(sol)

# Fast/Nonadaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, gamma=1.0/norm(A)^2, fast=true)
@test vecnorm(x .- x_star, Inf) <= 1e-4
@test it == 94
println(sol)

# Fast/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, adaptive=true, fast=true)
@test vecnorm(x .- x_star, Inf) <= 1e-4
@test it == 156
println(sol)

# ZeroFPR/Nonadaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fq=f, Aq=opA, g=g, gamma=1.0/norm(A)^2)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 8
println(sol)

# ZeroFPR/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fq=f, Aq=opA, g=g, adaptive=true)
@test vecnorm(x - x_star, Inf) <= 1e-4
@test it == 10
println(sol)
6 changes: 6 additions & 0 deletions test/test_lasso_small_split_x.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,37 @@ x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, gamma=1.0/norm(A)^2)
@test ProximalAlgorithms.blockmaxabs(x .- x_star) <= 1e-4
@test it == 140
println(sol)

# Nonfast/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, adaptive=true)
@test ProximalAlgorithms.blockmaxabs(x .- x_star) <= 1e-4
@test it == 247
println(sol)

# Fast/Nonadaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, gamma=1.0/norm(A)^2, fast=true)
@test ProximalAlgorithms.blockmaxabs(x .- x_star) <= 1e-4
@test it == 94
println(sol)

# Fast/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.FBS(x0; fq=f, Aq=opA, g=g, adaptive=true, fast=true)
@test ProximalAlgorithms.blockmaxabs(x .- x_star) <= 1e-4
@test it == 156
println(sol)

# ZeroFPR/Adaptive

x0 = ProximalAlgorithms.blockzeros(x_star)
@time it, x, sol = ProximalAlgorithms.ZeroFPR(x0; fq=f, Aq=opA, g=g, adaptive=true)
@test ProximalAlgorithms.blockmaxabs(x .- x_star) <= 1e-4
@test it == 10
println(sol)

1 change: 1 addition & 0 deletions test/test_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ x0 = randn(10)
it, x, sol = ProximalAlgorithms.Template(x0)
@test it == 10
@test norm(x - x0) == 0.0
println(sol)