Skip to content

Commit 4117cd0

Browse files
committed
format everything
1 parent 5e39caf commit 4117cd0

38 files changed

+1065
-514
lines changed

benchmark/benchmarks.jl

Lines changed: 94 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ using FileIO
88

99
const SUITE = BenchmarkGroup()
1010

11-
function ProximalAlgorithms.value_and_gradient_closure(f::ProximalOperators.LeastSquaresDirect, x)
12-
res = f.A*x - f.b
13-
norm(res)^2, () -> f.A'*res
11+
function ProximalAlgorithms.value_and_gradient_closure(
12+
f::ProximalOperators.LeastSquaresDirect,
13+
x,
14+
)
15+
res = f.A * x - f.b
16+
norm(res)^2, () -> f.A' * res
1417
end
1518

1619
struct SquaredDistance{Tb}
@@ -41,80 +44,93 @@ for (benchmark_name, file_name) in [
4144
lam = R(data["lambda"])
4245
m, n = size(A)
4346

44-
SUITE[k]["ForwardBackward"] = @benchmarkable solver(x0=x0, f=f, g=g) setup=begin
45-
solver = ProximalAlgorithms.ForwardBackward(tol=1e-6)
46-
x0 = zeros($T, size($A, 2))
47-
f = LeastSquares($A, $b)
48-
g = NormL1($lam)
49-
end
50-
51-
SUITE[k]["FastForwardBackward"] = @benchmarkable solver(x0=x0, f=f, g=g) setup=begin
52-
solver = ProximalAlgorithms.FastForwardBackward(tol=1e-6)
53-
x0 = zeros($T, size($A, 2))
54-
f = LeastSquares($A, $b)
55-
g = NormL1($lam)
56-
end
57-
58-
SUITE[k]["ZeroFPR"] = @benchmarkable solver(x0=x0, f=f, A=$A, g=g) setup=begin
59-
solver = ProximalAlgorithms.ZeroFPR(tol=1e-6)
60-
x0 = zeros($T, size($A, 2))
61-
f = SquaredDistance($b)
62-
g = NormL1($lam)
63-
end
64-
65-
SUITE[k]["PANOC"] = @benchmarkable solver(x0=x0, f=f, A=$A, g=g) setup=begin
66-
solver = ProximalAlgorithms.PANOC(tol=1e-6)
67-
x0 = zeros($T, size($A, 2))
68-
f = SquaredDistance($b)
69-
g = NormL1($lam)
70-
end
71-
72-
SUITE[k]["PANOCplus"] = @benchmarkable solver(x0=x0, f=f, A=$A, g=g) setup=begin
73-
solver = ProximalAlgorithms.PANOCplus(tol=1e-6)
74-
x0 = zeros($T, size($A, 2))
75-
f = SquaredDistance($b)
76-
g = NormL1($lam)
77-
end
78-
79-
SUITE[k]["DouglasRachford"] = @benchmarkable solver(x0=x0, f=f, g=g, gamma=$R(1)) setup=begin
80-
solver = ProximalAlgorithms.DouglasRachford(tol=1e-6)
81-
x0 = zeros($T, size($A, 2))
82-
f = LeastSquares($A, $b)
83-
g = NormL1($lam)
84-
end
85-
86-
SUITE[k]["DRLS"] = @benchmarkable solver(x0=x0, f=f, g=g, Lf=Lf) setup=begin
87-
solver = ProximalAlgorithms.DRLS(tol=1e-6)
88-
x0 = zeros($T, size($A, 2))
89-
f = LeastSquares($A, $b)
90-
Lf = opnorm(($A)' * $A)
91-
g = NormL1($lam)
92-
end
93-
94-
SUITE[k]["AFBA-1"] = @benchmarkable solver(x0=x0, y0=y0, f=f, g=g, beta_f=beta_f) setup=begin
95-
beta_f = opnorm($A)^2
96-
solver = ProximalAlgorithms.AFBA(theta=$R(1), mu=$R(1), tol=$R(1e-6))
97-
x0 = zeros($T, size($A, 2))
98-
y0 = zeros($T, size($A, 2))
99-
f = LeastSquares($A, $b)
100-
g = NormL1($lam)
101-
end
102-
103-
SUITE[k]["AFBA-2"] = @benchmarkable solver(x0=x0, y0=y0, h=h, L=$A, g=g) setup=begin
104-
beta_f = opnorm($A)^2
105-
solver = ProximalAlgorithms.AFBA(theta=$R(1), mu=$R(1), tol=$R(1e-6))
106-
x0 = zeros($T, size($A, 2))
107-
y0 = zeros($T, size($A, 1))
108-
h = Translate(SqrNormL2(), -$b)
109-
g = NormL1($lam)
110-
end
111-
112-
SUITE[k]["SFISTA"] = @benchmarkable solver(x0=x0, f=f, Lf=Lf, g=g) setup=begin
113-
solver = ProximalAlgorithms.SFISTA(tol=$R(1e-3))
114-
x0 = zeros($T, size($A, 2))
115-
f = LeastSquares($A, $b)
116-
g = NormL1($lam)
117-
Lf = opnorm($A)^2
118-
end
47+
SUITE[k]["ForwardBackward"] =
48+
@benchmarkable solver(x0 = x0, f = f, g = g) setup = begin
49+
solver = ProximalAlgorithms.ForwardBackward(tol = 1e-6)
50+
x0 = zeros($T, size($A, 2))
51+
f = LeastSquares($A, $b)
52+
g = NormL1($lam)
53+
end
54+
55+
SUITE[k]["FastForwardBackward"] =
56+
@benchmarkable solver(x0 = x0, f = f, g = g) setup = begin
57+
solver = ProximalAlgorithms.FastForwardBackward(tol = 1e-6)
58+
x0 = zeros($T, size($A, 2))
59+
f = LeastSquares($A, $b)
60+
g = NormL1($lam)
61+
end
62+
63+
SUITE[k]["ZeroFPR"] =
64+
@benchmarkable solver(x0 = x0, f = f, A = $A, g = g) setup = begin
65+
solver = ProximalAlgorithms.ZeroFPR(tol = 1e-6)
66+
x0 = zeros($T, size($A, 2))
67+
f = SquaredDistance($b)
68+
g = NormL1($lam)
69+
end
70+
71+
SUITE[k]["PANOC"] =
72+
@benchmarkable solver(x0 = x0, f = f, A = $A, g = g) setup = begin
73+
solver = ProximalAlgorithms.PANOC(tol = 1e-6)
74+
x0 = zeros($T, size($A, 2))
75+
f = SquaredDistance($b)
76+
g = NormL1($lam)
77+
end
78+
79+
SUITE[k]["PANOCplus"] =
80+
@benchmarkable solver(x0 = x0, f = f, A = $A, g = g) setup = begin
81+
solver = ProximalAlgorithms.PANOCplus(tol = 1e-6)
82+
x0 = zeros($T, size($A, 2))
83+
f = SquaredDistance($b)
84+
g = NormL1($lam)
85+
end
86+
87+
SUITE[k]["DouglasRachford"] =
88+
@benchmarkable solver(x0 = x0, f = f, g = g, gamma = $R(1)) setup = begin
89+
solver = ProximalAlgorithms.DouglasRachford(tol = 1e-6)
90+
x0 = zeros($T, size($A, 2))
91+
f = LeastSquares($A, $b)
92+
g = NormL1($lam)
93+
end
94+
95+
SUITE[k]["DRLS"] =
96+
@benchmarkable solver(x0 = x0, f = f, g = g, Lf = Lf) setup = begin
97+
solver = ProximalAlgorithms.DRLS(tol = 1e-6)
98+
x0 = zeros($T, size($A, 2))
99+
f = LeastSquares($A, $b)
100+
Lf = opnorm(($A)' * $A)
101+
g = NormL1($lam)
102+
end
103+
104+
SUITE[k]["AFBA-1"] =
105+
@benchmarkable solver(x0 = x0, y0 = y0, f = f, g = g, beta_f = beta_f) setup =
106+
begin
107+
beta_f = opnorm($A)^2
108+
solver =
109+
ProximalAlgorithms.AFBA(theta = $R(1), mu = $R(1), tol = $R(1e-6))
110+
x0 = zeros($T, size($A, 2))
111+
y0 = zeros($T, size($A, 2))
112+
f = LeastSquares($A, $b)
113+
g = NormL1($lam)
114+
end
115+
116+
SUITE[k]["AFBA-2"] =
117+
@benchmarkable solver(x0 = x0, y0 = y0, h = h, L = $A, g = g) setup = begin
118+
beta_f = opnorm($A)^2
119+
solver =
120+
ProximalAlgorithms.AFBA(theta = $R(1), mu = $R(1), tol = $R(1e-6))
121+
x0 = zeros($T, size($A, 2))
122+
y0 = zeros($T, size($A, 1))
123+
h = Translate(SqrNormL2(), -$b)
124+
g = NormL1($lam)
125+
end
126+
127+
SUITE[k]["SFISTA"] =
128+
@benchmarkable solver(x0 = x0, f = f, Lf = Lf, g = g) setup = begin
129+
solver = ProximalAlgorithms.SFISTA(tol = $R(1e-3))
130+
x0 = zeros($T, size($A, 2))
131+
f = LeastSquares($A, $b)
132+
g = NormL1($lam)
133+
Lf = opnorm($A)^2
134+
end
119135
end
120136
end

benchmark/runbenchmarks.jl

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function printnewsection(name)
1515
println()
1616
println()
1717
println()
18-
printstyled("" ^ displaysize(stdout)[2]; color=:blue)
18+
printstyled(""^displaysize(stdout)[2]; color = :blue)
1919
println()
20-
printstyled(name; bold=true)
20+
printstyled(name; bold = true)
2121
println()
2222
println()
2323
end
@@ -27,30 +27,25 @@ function parse_commandline()
2727

2828
@add_arg_table! s begin
2929
"--target"
30-
help = "the branch/commit/tag to use as target"
31-
default = "HEAD"
30+
help = "the branch/commit/tag to use as target"
31+
default = "HEAD"
3232
"--baseline"
33-
help = "the branch/commit/tag to use as baseline"
34-
default = "master"
33+
help = "the branch/commit/tag to use as baseline"
34+
default = "master"
3535
"--retune"
36-
help = "force re-tuning (ignore existing tuning data)"
37-
action = :store_true
36+
help = "force re-tuning (ignore existing tuning data)"
37+
action = :store_true
3838
end
3939

4040
return parse_args(s)
4141
end
4242

4343
function main()
4444
parsed_args = parse_commandline()
45-
45+
4646
mkconfig(; kwargs...) =
47-
BenchmarkConfig(
48-
env = Dict(
49-
"JULIA_NUM_THREADS" => "1",
50-
);
51-
kwargs...
52-
)
53-
47+
BenchmarkConfig(env = Dict("JULIA_NUM_THREADS" => "1"); kwargs...)
48+
5449
target = parsed_args["target"]
5550
group_target = benchmarkpkg(
5651
dirname(@__DIR__),
@@ -71,9 +66,9 @@ function main()
7166

7267
printnewsection("Baseline result")
7368
displayresult(group_baseline)
74-
69+
7570
judgement = judge(group_target, group_baseline)
76-
71+
7772
printnewsection("Judgement result")
7873
displayresult(judgement)
7974
end

docs/make.jl

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,31 @@ bib = CitationBibliography(joinpath(@__DIR__, "references.bib"))
66

77
src_path = joinpath(@__DIR__, "src/")
88

9-
literate_directories = joinpath.(
10-
src_path,
11-
[
12-
"guide",
13-
"examples",
14-
]
15-
)
9+
literate_directories = joinpath.(src_path, ["guide", "examples"])
1610

1711
for directory in literate_directories
18-
jl_files = filter(p -> endswith(p, ".jl"), readdir(directory; join=true))
12+
jl_files = filter(p -> endswith(p, ".jl"), readdir(directory; join = true))
1913
for src in jl_files
20-
Literate.markdown(src, directory, documenter=true)
14+
Literate.markdown(src, directory, documenter = true)
2115
end
2216
end
2317

2418
makedocs(
25-
modules=[ProximalAlgorithms, ProximalCore],
26-
sitename="ProximalAlgorithms.jl",
27-
pages=[
19+
modules = [ProximalAlgorithms, ProximalCore],
20+
sitename = "ProximalAlgorithms.jl",
21+
pages = [
2822
"Home" => "index.md",
2923
"User guide" => [
3024
joinpath("guide", "getting_started.md"),
3125
joinpath("guide", "implemented_algorithms.md"),
3226
joinpath("guide", "custom_objectives.md"),
3327
joinpath("guide", "custom_algorithms.md"),
3428
],
35-
"Examples" => [
36-
joinpath("examples", "sparse_linear_regression.md"),
37-
],
29+
"Examples" => [joinpath("examples", "sparse_linear_regression.md")],
3830
"Bibliography" => "bibliography.md",
3931
],
40-
plugins=[bib],
41-
checkdocs=:exported,
32+
plugins = [bib],
33+
checkdocs = :exported,
4234
)
4335

44-
deploydocs(
45-
repo="github.com/JuliaFirstOrder/ProximalAlgorithms.jl.git",
46-
)
36+
deploydocs(repo = "github.com/JuliaFirstOrder/ProximalAlgorithms.jl.git")

docs/src/examples/sparse_linear_regression.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ splitfields(s) = split(s, "\t")
1010
parsefloat64(s) = parse(Float64, s)
1111

1212
function load_diabetes_dataset()
13-
res = HTTP.request("GET", "https://www4.stat.ncsu.edu/~boos/var.select/diabetes.tab.txt")
13+
res =
14+
HTTP.request("GET", "https://www4.stat.ncsu.edu/~boos/var.select/diabetes.tab.txt")
1415
lines = res.body |> String |> strip |> splitlines
1516
return hcat((line |> splitfields .|> parsefloat64 for line in lines[2:end])...)'
1617
end
@@ -34,8 +35,8 @@ n_training, n_features = size(training_input)
3435
using LinearAlgebra
3536
using Statistics
3637

37-
input_loc = mean(training_input, dims=1) |> vec
38-
input_scale = std(training_input, dims=1) |> vec
38+
input_loc = mean(training_input, dims = 1) |> vec
39+
input_scale = std(training_input, dims = 1) |> vec
3940

4041
linear_model(wb, input) = input * wb[1:end-1] .+ wb[end]
4142

@@ -57,7 +58,7 @@ using ProximalAlgorithms
5758

5859
training_loss = ProximalAlgorithms.AutoDifferentiable(
5960
wb -> mean_squared_error(training_label, standardized_linear_model(wb, training_input)),
60-
ZygoteBackend()
61+
ZygoteBackend(),
6162
)
6263

6364
# As regularization we will use the L1 norm, implemented in [ProximalOperators](https://github.com/JuliaFirstOrder/ProximalOperators.jl):
@@ -72,7 +73,7 @@ reg = ProximalOperators.NormL1(1)
7273
# and the objective terms `f=training_loss` (smooth) and `g=reg` (non smooth).
7374

7475
ffb = ProximalAlgorithms.FastForwardBackward()
75-
solution, iterations = ffb(x0=zeros(n_features + 1), f=training_loss, g=reg)
76+
solution, iterations = ffb(x0 = zeros(n_features + 1), f = training_loss, g = reg)
7677

7778
# We can now check how well the trained model performs on the test portion of our data.
7879

docs/src/guide/custom_objectives.jl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using ProximalAlgorithms
3737

3838
rosenbrock2D = ProximalAlgorithms.AutoDifferentiable(
3939
x -> 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2,
40-
ZygoteBackend()
40+
ZygoteBackend(),
4141
)
4242

4343
# To enforce the constraint, we define the indicator of the unit ball, together with its proximal mapping:
@@ -63,15 +63,28 @@ end
6363
# We can now minimize the function, for which we will use [`PANOC`](@ref), which is a Newton-type method:
6464

6565
panoc = ProximalAlgorithms.PANOC()
66-
solution, iterations = panoc(x0=-ones(2), f=rosenbrock2D, g=IndUnitBall())
66+
solution, iterations = panoc(x0 = -ones(2), f = rosenbrock2D, g = IndUnitBall())
6767

6868
# Plotting the solution against the cost function contour and constraint, gives an idea of its correctness.
6969

7070
using Plots
7171

72-
contour(-2:0.1:2, -2:0.1:2, (x,y) -> rosenbrock2D([x, y]), fill=true, framestyle=:none, background=nothing)
73-
plot!(Shape(cos.(0:0.01:2*pi), sin.(0:0.01:2*pi)), opacity=.5, label="feasible set")
74-
scatter!([solution[1]], [solution[2]], color=:red, markershape=:star5, label="computed solution")
72+
contour(
73+
-2:0.1:2,
74+
-2:0.1:2,
75+
(x, y) -> rosenbrock2D([x, y]),
76+
fill = true,
77+
framestyle = :none,
78+
background = nothing,
79+
)
80+
plot!(Shape(cos.(0:0.01:2*pi), sin.(0:0.01:2*pi)), opacity = 0.5, label = "feasible set")
81+
scatter!(
82+
[solution[1]],
83+
[solution[2]],
84+
color = :red,
85+
markershape = :star5,
86+
label = "computed solution",
87+
)
7588

7689
# ## Example: counting operations
7790
#
@@ -90,7 +103,7 @@ mutable struct Counting{T}
90103
prox_count::Int
91104
end
92105

93-
Counting(f::T) where T = Counting{T}(f, 0, 0, 0)
106+
Counting(f::T) where {T} = Counting{T}(f, 0, 0, 0)
94107

95108
# Now we only need to intercept any call to `value_and_gradient_closure` and `prox!` and increase counters there:
96109

@@ -114,7 +127,7 @@ end
114127
f = Counting(rosenbrock2D)
115128
g = Counting(IndUnitBall())
116129

117-
solution, iterations = panoc(x0=-ones(2), f=f, g=g)
130+
solution, iterations = panoc(x0 = -ones(2), f = f, g = g)
118131

119132
# and check how many operations where actually performed:
120133

0 commit comments

Comments
 (0)