From 93608237674ca4b24b43a528a8a6cb1e9bbab080 Mon Sep 17 00:00:00 2001 From: Daniel Vainsencher Date: Tue, 21 Jun 2022 10:03:15 -0400 Subject: [PATCH] Update TotalVariation.jl to run, defining benchmark project. --- benchmarks/Project.toml | 12 ++++++++++++ benchmarks/TotalVariation.jl | 34 ++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 benchmarks/Project.toml diff --git a/benchmarks/Project.toml b/benchmarks/Project.toml new file mode 100644 index 0000000..3404db4 --- /dev/null +++ b/benchmarks/Project.toml @@ -0,0 +1,12 @@ +[deps] +AbstractOperators = "d9c5613a-d543-52d8-9afd-8f241a8c3f1c" +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438" +ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199" +ImageView = "86fae568-95e7-573e-a6b2-d8a6b900c9ef" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73" +SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13" +StructuredOptimization = "46cd3e9d-64ff-517d-a929-236bc1a1fc9d" +TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990" diff --git a/benchmarks/TotalVariation.jl b/benchmarks/TotalVariation.jl index 8834040..5a31e6f 100644 --- a/benchmarks/TotalVariation.jl +++ b/benchmarks/TotalVariation.jl @@ -6,13 +6,14 @@ using AbstractOperators using Images using ImageView using TestImages +using Random function set_up() - srand(123) + Random.seed!(1234) img = testimage("cameraman") X = convert(Array{Float64},img) # convert image to array - Xt = X.+sqrt(0.006*vecnorm(X,Inf))*randn(size(X)) # add noise + Xt = X.+sqrt(0.006*norm(X,Inf))*randn(size(X)) # add noise Xt[Xt .< 0] .= 0. #make sure pixels are in range Xt[Xt .> 1] .= 1. @@ -32,7 +33,7 @@ function run_demo() end function solve_problem!(slv,V, Y, Xt, X, lambda) - it, = @minimize ls(-V'*Y+Xt)+conj(lambda*norm(Y,2,1,2)) with slv + it = @minimize ls(-V'*Y+Xt)+conj(lambda*norm(Y,2,1,2)) with slv return it end @@ -42,10 +43,8 @@ function benchmark(;verb = 0, samples = 5, seconds = 100, tol = 1e-3, maxit = 50 solvers = ["ZeroFPR", "PANOC", - "FPG", - "PG"] + "ForwardBackward"] slv_opt = ["(verbose = $verb, tol = $tol, gamma = 1/8, maxit = $maxit)", - "(verbose = $verb, tol = $tol, gamma = 1/8, maxit = $maxit)", "(verbose = $verb, tol = $tol, gamma = 1/8, maxit = $maxit)", "(verbose = $verb, tol = $tol, gamma = 1/8, maxit = $maxit)"] @@ -53,20 +52,23 @@ function benchmark(;verb = 0, samples = 5, seconds = 100, tol = 1e-3, maxit = 50 for i in eachindex(solvers) setup = set_up() - solver = eval(parse(solvers[i]*slv_opt[i])) + solver = eval(Meta.parse(solvers[i]*slv_opt[i])) suite[solvers[i]] = - @benchmarkable(it = solve_problem!(solver, setup...), - setup = ( - it = 0; - setup = deepcopy($setup); - solver = deepcopy($solver) ), - teardown = ( - $its[$solvers[$i]] = it; - ), - evals = 1, samples = samples, seconds = seconds) + @benchmarkable( + it = solve_problem!(solver, setup...), + setup = ( + it = 0; + setup = deepcopy($setup); + solver = deepcopy($solver) + ), + teardown = ( + $its[$solvers[$i]] = it[2]; + ), + evals = 1, samples = samples, seconds = seconds) end + println("Starting run") results = run(suite, verbose = (verb != 0)) println("TotalVariation its") println(its)