6666function solve (solver:: ASP , A, y, Aval= A, yval= y)
6767 # Apply preconditioning
6868 AP = A / solver. P
69+ AvalP = Aval / solver. P
6970
7071 tracer = asp_homotopy (AP, y; solver. params... )
7172
7273 q = length (tracer)
73- every = max (1 , q ÷ solver. nstore)
74- istore = unique ([1 : every: q; q])
75- new_tracer = [ (solution = solver . P \ tracer[i][1 ], λ = tracer[i][2 ], σ = 0.0 )
74+ every = max (1 , q / solver. nstore)
75+ istore = unique (round .(Int, [1 : every: q; q]) )
76+ new_tracer = [ (solution = tracer[i][1 ], λ = tracer[i][2 ], σ = 0.0 )
7677 for i in istore ]
7778
7879 if solver. tsvd # Post-processing if tsvd is true
79- post = post_asp_tsvd (new_tracer, A, y, Aval, yval)
80- new_post = [ (solution = p. θ, λ = p. λ, σ = p. σ) for p in post ]
80+ post = post_asp_tsvd (new_tracer, AP, y, AvalP, yval)
81+ new_post = [ (solution = solver. P \ p. θ, λ = p. λ, σ = p. σ)
82+ for p in post ]
8183 else
82- new_post = new_tracer
84+ new_post = [ (solution = solver. P \ p. solution, λ = p. λ, σ = 0.0 )
85+ for p in new_tracer ]
8386 end
8487
8588 xs, in = select_solution (new_post, solver, Aval, yval)
@@ -124,34 +127,6 @@ function select_solution(tracer, solver, A, y)
124127end
125128
126129
127-
128- using SparseArrays
129-
130- function solve_tsvd (At, yt, Av, yv)
131- Ut, Σt, Vt = svd (At); zt = Ut' * yt
132- Qv, Rv = qr (Av); zv = Matrix (Qv)' * yv
133- @assert issorted (Σt, rev= true )
134-
135- Rv_Vt = Rv * Vt
136-
137- θv = zeros (size (Av, 2 ))
138- θv[1 ] = zt[1 ] / Σt[1 ]
139- rv = Rv_Vt[:, 1 ] * θv[1 ] - zv
140-
141- tsvd_errs = Float64[]
142- push! (tsvd_errs, norm (rv))
143-
144- for k = 2 : length (Σt)
145- θv[k] = zt[k] / Σt[k]
146- rv += Rv_Vt[:, k] * θv[k]
147- push! (tsvd_errs, norm (rv))
148- end
149-
150- imin = argmin (tsvd_errs)
151- θv[imin+ 1 : end ] .= 0
152- return Vt * θv, Σt[imin]
153- end
154-
155130function post_asp_tsvd (path, At, yt, Av, yv)
156131 Qt, Rt = qr (At); zt = Matrix (Qt)' * yt
157132 Qv, Rv = qr (Av); zv = Matrix (Qv)' * yv
@@ -166,14 +141,4 @@ function post_asp_tsvd(path, At, yt, Av, yv)
166141 end
167142
168143 return _post .(path)
169-
170- # post = []
171- # for (θ, λ) in path
172- # if isempty(θ.nzind); push!(post, (θ = θ, λ = λ, σ = Inf)); continue; end
173- # inz = θ.nzind
174- # θ1, σ = solve_tsvd(Rt[:, inz], zt, Rv[:, inz], zv)
175- # θ2 = copy(θ); θ2[inz] .= θ1
176- # push!(post, (θ = θ2, λ = λ, σ = σ))
177- # end
178- # return identity.(post)
179144end
0 commit comments