From 0910d0d58ddaae9a0c72ab15149685f0ddfcc9df Mon Sep 17 00:00:00 2001 From: Christoph Ortner Date: Wed, 11 Sep 2024 21:17:24 -0700 Subject: [PATCH] asp bugfixes --- src/asp.jl | 20 +++++++++----------- test/test_asp.jl | 15 +++++++++------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/asp.jl b/src/asp.jl index c5a6cbb..6006128 100644 --- a/src/asp.jl +++ b/src/asp.jl @@ -13,8 +13,9 @@ subject to ``` ### Constructor Keyword arguments + ```julia -ACEfit.ASP(; P = I, select = (:byerror, 1.0), +ACEfit.ASP(; P = I, select = (:byerror, 1.0), tsvd = false, nstore=100, params...) ``` @@ -42,33 +43,30 @@ solve(solver::ASP, A, y, Aval=A, yval=y) ``` * `A` : `m`-by-`n` design matrix. (required) * `b` : `m`-vector. (required) -* `Aval = nothing` : `p`-by-`n` validation matrix (only for `validate` mode). -* `bval = nothing` : `p`- validation vector (only for `validate` mode). +* `Aval = nothing` : `p`-by-`n` validation matrix +* `bval = nothing` : `p`- validation vector If independent `Aval` and `yval` are provided (instead of detaults `A, y`), then the solver will use this separate validation set instead of the training set to select the best solution along the model path. -# """ - +""" struct ASP P select - mode::Symbol tsvd::Bool nstore::Integer params end -function ASP(; P = I, select, mode=:train, tsvd=false, nstore=100, params...) - return ASP(P, select, mode, tsvd, nstore, params) +function ASP(; P = I, select, tsvd=false, nstore=100, params...) + return ASP(P, select, tsvd, nstore, params) end function solve(solver::ASP, A, y, Aval=A, yval=y) # Apply preconditioning AP = A / solver.P AvalP = Aval / solver.P - - tracer = asp_homotopy(AP, y; solver.params...) + tracer = asp_homotopy(AP, y; solver.params..., traceFlag = true) q = length(tracer) every = max(1, q / solver.nstore) @@ -89,7 +87,7 @@ function solve(solver::ASP, A, y, Aval=A, yval=y) return Dict( "C" => xs, "path" => new_post, - "nnzs" => length( (new_tracer[in][:solution]).nzind) ) + "nnzs" => length( (new_post[in][:solution]).nzind) ) end diff --git a/test/test_asp.jl b/test/test_asp.jl index e607bed..6930ca6 100644 --- a/test/test_asp.jl +++ b/test/test_asp.jl @@ -28,18 +28,21 @@ Av = A[val_indices,:] yt = y[train_indices] yv = y[val_indices] + for (nstore, n1) in [ (20, 21), (100, 101), (200, 165)] - solver = ACEfit.ASP(P=I, select = :final, nstore = nstore, loglevel=0, traceFlag=true) + solver = ACEfit.ASP(; P=I, select = :final, nstore = nstore, loglevel=0) results = ACEfit.solve(solver, A, y) @test length(results["path"]) == n1 end +## + for (select, tolr, tolc) in [ (:final, 10*epsn, 1), ( (:byerror,1.3), 10*epsn, 1), ( (:bysize,73), 1, 10) ] @show select local solver, results, C - solver = ACEfit.ASP(P=I, select = select, loglevel=0, traceFlag=true) + solver = ACEfit.ASP(P=I, select = select, loglevel=0) # without validation results = ACEfit.solve(solver, A, y) C = results["C"] @@ -77,11 +80,11 @@ for (select, tolr, tolc) in [ (:final, 20*epsn, 1.5), ( (:bysize,73), 1, 10) ] @show select local solver, results, C - solver_tsvd = ACEfit.ASP(P=I, select=select, mode=:train, tsvd=true, - nstore=100, loglevel=0, traceFlag=true) + solver_tsvd = ACEfit.ASP(P=I, select=select, tsvd=true, + nstore=100, loglevel=0) - solver = ACEfit.ASP(P=I, select=select, mode=:train, tsvd=false, - nstore=100, loglevel=0, traceFlag=true) + solver = ACEfit.ASP(P=I, select=select, tsvd=false, + nstore=100, loglevel=0) # without validation results_tsvd = ACEfit.solve(solver_tsvd, A, y) results = ACEfit.solve(solver, A, y)