Benchmarking

using MonotoneDecomposition

prefer Gurobi if possible

gurobi(1)

Candidate functions

fs = ["x^2" "x^3" "exp(x)" "sigmoid" "SE_1" "SE_0.1" "Mat12_1" "Mat12_0.1" "Mat32_1" "Mat32_0.1" "RQ_0.1_0.5" "Periodic_0.1_4"]

nrep = 1
nλ = 2
nfold = 2
f = fs[1]
competitor = "ss_single_lambda"
nλ = ifelse(occursin("single_lambda", competitor), 1, nλ)
one_se_rule = false
resfolder0 = "/tmp"
timestamp = replace(strip(read(`date -Iseconds`, String)), ":" => "_")
n = 100
use_snr = false
if length(ARGS) > 0
    @info "Use args passed from CLI"
    competitor = ARGS[1]
    resfolder0 = ARGS[2]
    if !isdir(resfolder0)
        mkdir(resfolder0)
    end
    nλ = parse(Int, ARGS[3])
    nrep = parse(Int, ARGS[4])
    nfold = parse(Int, ARGS[5])
    one_se_rule = parse(Bool, ARGS[6])
    f = ARGS[7]
    if length(ARGS) > 7
        timestamp = replace(strip(ARGS[8]), ":" => "_") # passed from scripts
        n = parse(Int, ARGS[9])
        use_snr = parse(Bool, ARGS[10])
    end
end
resfolder = joinpath(resfolder0, "nrep$nrep-nfold$nfold-nlam$nλ-1se_$(one_se_rule)-$competitor-$timestamp-n$n-snr_$(use_snr)")
if !isdir(resfolder)
    mkdir(resfolder)
end
@info "Results are saved into $resfolder"

benchmarking(
    f;
    n = n,
    σs = [0.1, 0.2, 0.4, 0.5, 1.0, 1.5, 2.0], # noise level to be surveyed
    snrs = [0.1, 0.5, 1, 2, 10], # SNR to be surveryed
    use_snr = use_snr,
    jplot = false, # μerr vs σs
    nrep = nrep, # NB: for fast auto-generation procedure, only use nrep = 1; in the paper, use nrep = 100
    competitor = competitor,
    nfold = nfold, # number of folds
    one_se_rule = one_se_rule,
    nλ = nλ, # the number of λ to be searched
    rλ = 0.5, # the search region of λ, (1-rλ, 1+rλ)*λ
    resfolder = resfolder,
    verbose = false,
    show_progress = true,
    multi_fix_ratio = true,
    rλs = 10.0 .^ (-1:0.05:0.1)
)
[ Info: Results are saved into /tmp/nrep1-nfold2-nlam1-1se_false-ss_single_lambda-2025-05-03T06_49_47+00_00-n100-snr_false
[ Info: Benchmarking x^2 with 1 repetitions
[ Info: σ = 0.1, resulting SNR = 9.078098062300107
[ Info: σ = 0.2, resulting SNR = 2.257812790503765

x^2 (nrep = 1), iter = 1:  29%|███████▏                 |  ETA: 0:00:22[ Info: σ = 0.4, resulting SNR = 0.5601280669974215

x^2 (nrep = 1), iter = 1:  43%|██████████▊              |  ETA: 0:00:15[ Info: σ = 0.5, resulting SNR = 0.34159056503846147

x^2 (nrep = 1), iter = 1:  57%|██████████████▎          |  ETA: 0:00:10[ Info: σ = 1.0, resulting SNR = 0.08467435798809166

x^2 (nrep = 1), iter = 1:  71%|█████████████████▉       |  ETA: 0:00:06[ Info: σ = 1.5, resulting SNR = 0.04102181510996575

x^2 (nrep = 1), iter = 1:  86%|█████████████████████▍   |  ETA: 0:00:03[ Info: σ = 2.0, resulting SNR = 0.02195467258715532
┌ Warning: the optimal is on the right boundary of λs
└ @ MonotoneDecomposition ~/work/MonotoneDecomposition.jl/MonotoneDecomposition.jl/src/mono_decomp.jl:200

x^2 (nrep = 1), iter = 1: 100%|█████████████████████████| Time: 0:00:21
run from command line
julia examples/benchmark.jl ss_single_lambda /tmp 2 1 2 false

You can also enable the debug mode to print more internal steps as follows

JULIA_DEBUG=MonotoneDecomposition julia examples/benchmark.jl ss_single_lambda /tmp 2 1 2 false
summary results

After obtaining results, we can obtain the summarized tex file (used in the manuscript) as follows.

MonotoneDecomposition.summary(resfolder = resfolder)