Skip to content
Open
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: 27 additions & 0 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build JOSS paper draft PDF
on:
push:
branches:
- joss-paper

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload pdf artifact
uses: actions/upload-artifact@v4
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
14 changes: 14 additions & 0 deletions paper/examples/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[deps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
ProximalAlgorithms = "140ffc9f-1907-541a-a177-7475e0a401e9"
ProximalCore = "dc4f5ac2-75d1-4f31-931e-60435d74994b"
ProximalOperators = "a725b495-10eb-56fe-b38b-717eba820537"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
204 changes: 204 additions & 0 deletions paper/examples/comparison_linespectraestimation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# this script for comparing different solvers is inspired by
# - https://github.com/JuliaFirstOrder/StructuredOptimization.jl/blob/master/demos/LineSpectraEstimation.ipynb
# - https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/paper/paper/examples/Benchmark.jl
# - https://juliafirstorder.github.io/ProximalAlgorithms.jl/stable/guide/custom_objectives/#Example:-counting-operations

using Random, SparseArrays, LinearAlgebra
using DSP, Statistics, FFTW
using Zygote
using DifferentiationInterface: AutoZygote
using ProximalCore, ProximalOperators, ProximalAlgorithms
using PrettyTables, LaTeXStrings

#--------------------------------------------------------------
# benchmark configuration
CFG = Dict(
"seed" => 1234,
"tol" => 1e-6,
"max_iter" => 1_000_000,
"verbose" => false,
"solvers" => [:ForwardBackward, :FastForwardBackward, :ZeroFPR, :PANOC, :PANOCplus],
"regularizers" => [:NormL1, :NormLinf, :NormL0, :IndBallL0],
"num_samples" => 20,
"print_table" => true,
)

#--------------------------------------------------------------
# counters
mutable struct Counting{T}
f::T
eval_count::Int
grad_count::Int
prox_count::Int
end

Counting(f::T) where {T} = Counting{T}(f, 0, 0, 0)

function (f::Counting)(x)
f.eval_count += 1
return f.f(x)
end

function ProximalAlgorithms.value_and_gradient(f::Counting, x)
f.eval_count += 1
f.grad_count += 1
return ProximalAlgorithms.value_and_gradient(f.f, x)
end

function ProximalCore.prox!(y, f::Counting, x, gamma)
f.prox_count += 1
return ProximalCore.prox!(y, f.f, x, gamma)
end

#--------------------------------------------------------------
# problem generation
function make_loss_fun(cfg)
Random.seed!(cfg["seed"]) # For reproducibility

Fs = 16e3 #sampling frequency
Nt = 2^7 #time samples
y0 = zeros(Nt)
SNR = 20
S = 4 #super-resolution factor
f_s = range(0, stop=Fs/2; length=div(S*Nt, 2)+1) # super resolution frequency axis
f = range(0, stop=Fs/2; length=div(Nt, 2)+1) # frequency axis
t = 0:(1/Fs):((Nt-1)/Fs) # time axis
N = 14 # number of sinusoids
Nf = div(S*Nt, 4)+1
p = randperm(Nf)[1:N]
fk = f_s[p] # pick sinusoids frequencies
A = 0.1 .* randn(N) .+ 0.7 # amplitude
for i in eachindex(fk)
y0 .+= A[i] .* sin.(2*pi*fk[i] .* t) # mixture of sinusoids
end
y = y0 .+ 10^(-SNR/10)*sqrt(var(y0))*randn(length(y0)); # add noise

x0 = randn(ComplexF64, S*Nt)
f = ProximalAlgorithms.AutoDifferentiable(x -> 0.5*norm(ifft(x)[1:Nt]-complex(y), 2)^2, AutoZygote())
return f, x0
end

function run_solver(f, g, x0, solversym, cfg)
maxit = cfg["max_iter"]
tol = cfg["tol"]
verbose = cfg["verbose"]
solverbuilder = ProximalAlgorithms.eval(solversym)
solver = solverbuilder(maxit=maxit, tol=tol, verbose=verbose)

fc = Counting(f)
gc = Counting(g)

runtime = @elapsed x, iters = solver(f=fc, g=gc, x0=x0)
status = iters < maxit ? "first_order" : "max_iter"
objx = f(x)+g(x)
return (
name=String(solversym),
objective=objx,
status=status,
runtime=runtime,
iters=iters,
fevals=fc.eval_count,
gradevals=fc.grad_count,
proxevals=gc.prox_count
)
end

function run_solver_mult(f, g, x0, solversym, cfg)
nsamples = cfg["num_samples"]
nx = length(x0)
objx = zeros(nsamples)
status = zeros(nsamples)
runtime = zeros(nsamples)
iters = zeros(nsamples)
fevals = zeros(nsamples)
gradevals = zeros(nsamples)
proxevals = zeros(nsamples)
for i = 1:nsamples
# random initial guess
seed = cfg["seed"] + i - 1
Random.seed!(seed) # For reproducibility
x0 .= randn(ComplexF64, nx)
# call solver
res = run_solver(f, g, x0, solversym, cfg)
# store results
objx[i] = res.objective
status[i] = res.status == "first_order" ? 1 : 0
runtime[i] = res.runtime
iters[i] = res.iters
fevals[i] = res.fevals
gradevals[i] = res.gradevals
proxevals[i] = res.proxevals
end
nsolved = Int(sum(status))
return (
name=String(solversym),
objective=median(objx),
status="$(nsolved)/$(nsamples)",
runtime=median(runtime),
iters=median(iters),
fevals=median(fevals),
gradevals=median(gradevals),
proxevals=median(proxevals)
)
end

function bench_regularizer(f, g, x0, cfg)
results = NamedTuple[]
for solversym in cfg["solvers"]
push!(results, run_solver_mult(f, g, x0, solversym, cfg))
end

restable = [
(; name=m.name,
status=string(m.status),
runtime=round(m.runtime, digits=4),
gradevals=m.gradevals,
proxevals=m.proxevals,
objx=round(m.objective, digits=4))
for m in results
]

return restable
end

# main
function main(; cfg=CFG, latex_out=true)
f, x0 = make_loss_fun(cfg)

for regsym in cfg["regularizers"]
regstr = String(regsym)
regbuilder = ProximalOperators.eval(regsym)
if regbuilder == IndBallL0
λ = 28 # 2*N in LineSpectraEstimation.ipynb
else
λ = 1
end
g = regbuilder(λ)

restable = bench_regularizer(f, g, x0, cfg)

if cfg["print_table"]
println("\n=== Results with "*regstr*" ===")
for row in restable
println(row)
end
end

# save as latex format
if latex_out
table_str = pretty_table(String,
restable;
backend=:latex,
column_labels=["Method", "Success rate", L"$t$ ($s$)", L"$\#\nabla f$", L"$\#prox$", "Objective"],
style=LatexTableStyle(column_label=String[]),
table_format=latex_table_format__booktabs
)

open("table_"*regstr*".tex", "w") do io
write(io, table_str)
end
end
end

return nothing
end
21 changes: 21 additions & 0 deletions paper/examples/example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ProximalOperators, ProximalAlgorithms

struct Rosenbrock{T}
a::T
end
(f::Rosenbrock)(x) = (f.a-x[1])^2 + 100*(x[2]-x[1]^2)^2
function ProximalAlgorithms.value_and_gradient(f::Rosenbrock, x)
return f(x), [2*(x[1]-f.a) + 400*(x[1]^2-x[2])*x[1], 200*(x[2]-x[1]^2)]
end

f = Rosenbrock(1.0)
g = NormL1(2.0)

solver = ProximalAlgorithms.ForwardBackward(tol = 1e-6, verbose = true)
x, iters = solver(x0 = ones(2), f = f, g = g)

using Zygote
using DifferentiationInterface: AutoZygote

f_auto = ProximalAlgorithms.AutoDifferentiable(x -> f(x), AutoZygote())
x, iters = solver(x0 = ones(2), f = f_auto, g = g)
11 changes: 11 additions & 0 deletions paper/examples/table_IndBallL0.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{tabular}{rrrrrr}
\toprule
\textbf{Method} & \textbf{Success rate} & \textbf{$t$ ($s$)} & \textbf{$\#\nabla f$} & \textbf{$\#prox$} & \textbf{Objective} \\
\midrule
ForwardBackward & 20/20 & 0.5451 & 7509.5 & 7508.5 & 19.4546 \\
FastForwardBackward & 20/20 & 0.1482 & 3066.0 & 1533.0 & 23.8179 \\
ZeroFPR & 20/20 & 0.0374 & 521.5 & 520.5 & 18.7917 \\
PANOC & 20/20 & 0.0253 & 523.0 & 269.5 & 11.1509 \\
PANOCplus & 20/20 & 0.0272 & 517.0 & 258.0 & 11.1509 \\
\bottomrule
\end{tabular}
11 changes: 11 additions & 0 deletions paper/examples/table_NormL0.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{tabular}{rrrrrr}
\toprule
\textbf{Method} & \textbf{Success rate} & \textbf{$t$ ($s$)} & \textbf{$\#\nabla f$} & \textbf{$\#prox$} & \textbf{Objective} \\
\midrule
ForwardBackward & 20/20 & 0.5405 & 17898.0 & 17897.0 & 28.0178 \\
FastForwardBackward & 20/20 & 0.0791 & 2704.0 & 1352.0 & 28.0178 \\
ZeroFPR & 20/20 & 0.0137 & 414.0 & 413.0 & 31.0171 \\
PANOC & 20/20 & 0.0193 & 550.0 & 313.0 & 28.0178 \\
PANOCplus & 20/20 & 0.0202 & 620.0 & 309.5 & 28.0178 \\
\bottomrule
\end{tabular}
11 changes: 11 additions & 0 deletions paper/examples/table_NormL1.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{tabular}{rrrrrr}
\toprule
\textbf{Method} & \textbf{Success rate} & \textbf{$t$ ($s$)} & \textbf{$\#\nabla f$} & \textbf{$\#prox$} & \textbf{Objective} \\
\midrule
ForwardBackward & 20/20 & 0.0001 & 3.0 & 2.0 & 231.763 \\
FastForwardBackward & 20/20 & 0.0001 & 4.0 & 2.0 & 231.763 \\
ZeroFPR & 20/20 & 0.0001 & 4.0 & 3.0 & 231.763 \\
PANOC & 20/20 & 0.0001 & 4.0 & 2.0 & 231.763 \\
PANOCplus & 20/20 & 0.0001 & 5.0 & 2.0 & 231.763 \\
\bottomrule
\end{tabular}
11 changes: 11 additions & 0 deletions paper/examples/table_NormLinf.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{tabular}{rrrrrr}
\toprule
\textbf{Method} & \textbf{Success rate} & \textbf{$t$ ($s$)} & \textbf{$\#\nabla f$} & \textbf{$\#prox$} & \textbf{Objective} \\
\midrule
ForwardBackward & 20/20 & 0.2252 & 5883.5 & 5882.5 & 40.742 \\
FastForwardBackward & 20/20 & 0.0328 & 1032.0 & 516.0 & 40.742 \\
ZeroFPR & 20/20 & 0.0186 & 467.0 & 466.0 & 40.742 \\
PANOC & 20/20 & 0.0281 & 811.0 & 433.0 & 40.742 \\
PANOCplus & 20/20 & 0.0333 & 851.0 & 425.0 & 40.742 \\
\bottomrule
\end{tabular}
Loading
Loading