Sun, 02 Feb 2025 15:21:16 -0500
Symbol rename
35 | 1 | /*! |
2 | Solver for the point source localisation problem using a sliding | |
3 | primal-dual proximal splitting method. | |
4 | */ | |
5 | ||
6 | use numeric_literals::replace_float_literals; | |
7 | use serde::{Serialize, Deserialize}; | |
8 | //use colored::Colorize; | |
9 | //use nalgebra::{DVector, DMatrix}; | |
10 | use std::iter::Iterator; | |
11 | ||
12 | use alg_tools::iterate::AlgIteratorFactory; | |
13 | use alg_tools::euclidean::Euclidean; | |
14 | use alg_tools::mapping::{Mapping, DifferentiableRealMapping, Instance}; | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
15 | use alg_tools::norms::{Norm, Dist}; |
35 | 16 | use alg_tools::direct_product::Pair; |
17 | use alg_tools::nalgebra_support::ToNalgebraRealField; | |
18 | use alg_tools::linops::{ | |
19 | BoundedLinear, AXPY, GEMV, Adjointable, IdOp, | |
20 | }; | |
21 | use alg_tools::convex::{Conjugable, Prox}; | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
22 | use alg_tools::norms::{L2, PairNorm}; |
35 | 23 | |
24 | use crate::types::*; | |
25 | use crate::measures::{DiscreteMeasure, Radon, RNDM}; | |
26 | use crate::measures::merging::SpikeMerging; | |
27 | use crate::forward_model::{ | |
28 | ForwardModel, | |
29 | AdjointProductPairBoundedBy, | |
44 | 30 | BoundedCurvature, |
35 | 31 | }; |
32 | // use crate::transport::TransportLipschitz; | |
33 | //use crate::tolerance::Tolerance; | |
34 | use crate::plot::{ | |
35 | SeqPlotter, | |
36 | Plotting, | |
37 | PlotLookup | |
38 | }; | |
39 | use crate::fb::*; | |
40 | use crate::regularisation::SlidingRegTerm; | |
41 | // use crate::dataterm::L2Squared; | |
42 | use crate::sliding_fb::{ | |
43 | TransportConfig, | |
44 | TransportStepLength, | |
45 | initial_transport, | |
46 | aposteriori_transport, | |
47 | }; | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
48 | use crate::dataterm::{ |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
49 | calculate_residual2, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
50 | calculate_residual, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
51 | }; |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
52 | |
35 | 53 | |
54 | /// Settings for [`pointsource_sliding_pdps_pair`]. | |
55 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
56 | #[serde(default)] | |
57 | pub struct SlidingPDPSConfig<F : Float> { | |
58 | /// Primal step length scaling. | |
59 | pub τ0 : F, | |
60 | /// Primal step length scaling. | |
61 | pub σp0 : F, | |
62 | /// Dual step length scaling. | |
63 | pub σd0 : F, | |
64 | /// Transport parameters | |
65 | pub transport : TransportConfig<F>, | |
66 | /// Generic parameters | |
67 | pub insertion : FBGenericConfig<F>, | |
68 | } | |
69 | ||
70 | #[replace_float_literals(F::cast_from(literal))] | |
71 | impl<F : Float> Default for SlidingPDPSConfig<F> { | |
72 | fn default() -> Self { | |
73 | SlidingPDPSConfig { | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
74 | τ0 : 0.99, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
75 | σd0 : 0.05, |
35 | 76 | σp0 : 0.99, |
45 | 77 | transport : TransportConfig { θ0 : 0.9, ..Default::default()}, |
35 | 78 | insertion : Default::default() |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | type MeasureZ<F, Z, const N : usize> = Pair<RNDM<F, N>, Z>; | |
84 | ||
85 | /// Iteratively solve the pointsource localisation with an additional variable | |
86 | /// using sliding primal-dual proximal splitting | |
87 | /// | |
88 | /// The parametrisation is as for [`crate::forward_pdps::pointsource_forward_pdps_pair`]. | |
89 | #[replace_float_literals(F::cast_from(literal))] | |
90 | pub fn pointsource_sliding_pdps_pair< | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
91 | F, I, A, S, Reg, P, Z, R, Y, /*KOpM, */ KOpZ, H, const N : usize |
35 | 92 | >( |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
93 | opA : &A, |
35 | 94 | b : &A::Observable, |
95 | reg : Reg, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
96 | prox_penalty : &P, |
35 | 97 | config : &SlidingPDPSConfig<F>, |
98 | iterator : I, | |
99 | mut plotter : SeqPlotter<F, N>, | |
100 | //opKμ : KOpM, | |
101 | opKz : &KOpZ, | |
102 | fnR : &R, | |
103 | fnH : &H, | |
104 | mut z : Z, | |
105 | mut y : Y, | |
106 | ) -> MeasureZ<F, Z, N> | |
107 | where | |
108 | F : Float + ToNalgebraRealField, | |
109 | I : AlgIteratorFactory<IterInfo<F, N>>, | |
110 | A : ForwardModel< | |
111 | MeasureZ<F, Z, N>, | |
112 | F, | |
113 | PairNorm<Radon, L2, L2>, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
114 | PreadjointCodomain = Pair<S, Z>, |
35 | 115 | > |
44 | 116 | + AdjointProductPairBoundedBy<MeasureZ<F, Z, N>, P, IdOp<Z>, FloatType=F> |
117 | + BoundedCurvature<FloatType=F>, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
118 | S : DifferentiableRealMapping<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
119 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable> + Instance<A::Observable>, |
35 | 120 | PlotLookup : Plotting<N>, |
121 | RNDM<F, N> : SpikeMerging<F>, | |
122 | Reg : SlidingRegTerm<F, N>, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
123 | P : ProxPenalty<F, S, Reg, N>, |
35 | 124 | // KOpM : Linear<RNDM<F, N>, Codomain=Y> |
125 | // + GEMV<F, RNDM<F, N>> | |
126 | // + Preadjointable< | |
127 | // RNDM<F, N>, Y, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
128 | // PreadjointCodomain = S, |
35 | 129 | // > |
130 | // + TransportLipschitz<L2Squared, FloatType=F> | |
131 | // + AdjointProductBoundedBy<RNDM<F, N>, 𝒟, FloatType=F>, | |
132 | // for<'b> KOpM::Preadjoint<'b> : GEMV<F, Y>, | |
133 | // Since Z is Hilbert, we may just as well use adjoints for K_z. | |
134 | KOpZ : BoundedLinear<Z, L2, L2, F, Codomain=Y> | |
135 | + GEMV<F, Z> | |
136 | + Adjointable<Z, Y, AdjointCodomain = Z>, | |
137 | for<'b> KOpZ::Adjoint<'b> : GEMV<F, Y>, | |
138 | Y : AXPY<F> + Euclidean<F, Output=Y> + Clone + ClosedAdd, | |
139 | for<'b> &'b Y : Instance<Y>, | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
140 | Z : AXPY<F, Owned=Z> + Euclidean<F, Output=Z> + Clone + Norm<F, L2> + Dist<F, L2>, |
35 | 141 | for<'b> &'b Z : Instance<Z>, |
142 | R : Prox<Z, Codomain=F>, | |
143 | H : Conjugable<Y, F, Codomain=F>, | |
144 | for<'b> H::Conjugate<'b> : Prox<Y>, | |
145 | { | |
146 | ||
147 | // Check parameters | |
148 | assert!(config.τ0 > 0.0 && | |
149 | config.τ0 < 1.0 && | |
150 | config.σp0 > 0.0 && | |
151 | config.σp0 < 1.0 && | |
152 | config.σd0 > 0.0 && | |
153 | config.σp0 * config.σd0 <= 1.0, | |
154 | "Invalid step length parameters"); | |
155 | config.transport.check(); | |
156 | ||
157 | // Initialise iterates | |
158 | let mut μ = DiscreteMeasure::new(); | |
159 | let mut γ1 = DiscreteMeasure::new(); | |
160 | let mut residual = calculate_residual(Pair(&μ, &z), opA, b); | |
161 | let zero_z = z.similar_origin(); | |
162 | ||
163 | // Set up parameters | |
164 | // TODO: maybe this PairNorm doesn't make sense here? | |
41
b6bdb6cb4d44
Remove initial transport adaptation—it is not needed, after all
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
165 | // let opAnorm = opA.opnorm_bound(PairNorm(Radon, L2, L2), L2); |
35 | 166 | let bigθ = 0.0; //opKμ.transport_lipschitz_factor(L2Squared); |
167 | let bigM = 0.0; //opKμ.adjoint_product_bound(&op𝒟).unwrap().sqrt(); | |
168 | let nKz = opKz.opnorm_bound(L2, L2); | |
169 | let ℓ = 0.0; | |
170 | let opIdZ = IdOp::new(); | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
171 | let (l, l_z) = opA.adjoint_product_pair_bound(prox_penalty, &opIdZ).unwrap(); |
35 | 172 | // We need to satisfy |
173 | // | |
174 | // τσ_dM(1-σ_p L_z)/(1 - τ L) + [σ_p L_z + σ_pσ_d‖K_z‖^2] < 1 | |
175 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ | |
176 | // with 1 > σ_p L_z and 1 > τ L. | |
177 | // | |
178 | // To do so, we first solve σ_p and σ_d from standard PDPS step length condition | |
179 | // ^^^^^ < 1. then we solve τ from the rest. | |
180 | let σ_d = config.σd0 / nKz; | |
181 | let σ_p = config.σp0 / (l_z + config.σd0 * nKz); | |
182 | // Observe that = 1 - ^^^^^^^^^^^^^^^^^^^^^ = 1 - σ_{p,0} | |
183 | // We get the condition τσ_d M (1-σ_p L_z) < (1-σ_{p,0})*(1-τ L) | |
184 | // ⟺ τ [ σ_d M (1-σ_p L_z) + (1-σ_{p,0}) L ] < (1-σ_{p,0}) | |
185 | let φ = 1.0 - config.σp0; | |
186 | let a = 1.0 - σ_p * l_z; | |
187 | let τ = config.τ0 * φ / ( σ_d * bigM * a + φ * l ); | |
188 | let ψ = 1.0 - τ * l; | |
189 | let β = σ_p * config.σd0 * nKz / a; // σ_p * σ_d * (nKz * nK_z) / a; | |
190 | assert!(β < 1.0); | |
44 | 191 | // Now we need κ‖K_μ(π_♯^1 - π_♯^0)γ‖^2 ≤ (1/θ - τ[ℓ_F + ℓ]) ∫ c_2 dγ for κ defined as: |
36 | 192 | let κ = τ * σ_d * ψ / ((1.0 - β) * ψ - τ * σ_d * bigM); |
35 | 193 | // The factor two in the manuscript disappears due to the definition of 𝚹 being |
194 | // for ‖x-y‖₂² instead of c_2(x, y)=‖x-y‖₂²/2. | |
44 | 195 | let (maybe_ℓ_v0, maybe_transport_lip) = opA.curvature_bound_components(); |
196 | let transport_lip = maybe_transport_lip.unwrap(); | |
35 | 197 | let calculate_θ = |ℓ_v, max_transport| { |
44 | 198 | let ℓ_F = ℓ_v + transport_lip * max_transport; |
199 | config.transport.θ0 / (τ*(ℓ + ℓ_F) + κ * bigθ * max_transport) | |
35 | 200 | }; |
44 | 201 | let mut θ_or_adaptive = match maybe_ℓ_v0 { |
35 | 202 | // We assume that the residual is decreasing. |
44 | 203 | Some(ℓ_v0) => TransportStepLength::AdaptiveMax { |
204 | l: ℓ_v0 * b.norm2(), // TODO: could estimate computing the real reesidual | |
35 | 205 | max_transport : 0.0, |
206 | g : calculate_θ | |
207 | }, | |
44 | 208 | None => TransportStepLength::FullyAdaptive { |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
209 | l : F::EPSILON, |
35 | 210 | max_transport : 0.0, |
211 | g : calculate_θ | |
212 | }, | |
213 | }; | |
214 | // Acceleration is not currently supported | |
215 | // let γ = dataterm.factor_of_strong_convexity(); | |
216 | let ω = 1.0; | |
217 | ||
218 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
219 | // by τ compared to the conditional gradient approach. | |
220 | let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling(); | |
221 | let mut ε = tolerance.initial(); | |
222 | ||
223 | let starH = fnH.conjugate(); | |
224 | ||
225 | // Statistics | |
226 | let full_stats = |residual : &A::Observable, μ : &RNDM<F, N>, z : &Z, ε, stats| IterInfo { | |
227 | value : residual.norm2_squared_div2() + fnR.apply(z) | |
228 | + reg.apply(μ) + fnH.apply(/* opKμ.apply(μ) + */ opKz.apply(z)), | |
229 | n_spikes : μ.len(), | |
230 | ε, | |
231 | // postprocessing: config.insertion.postprocessing.then(|| μ.clone()), | |
232 | .. stats | |
233 | }; | |
234 | let mut stats = IterInfo::new(); | |
235 | ||
236 | // Run the algorithm | |
237 | for state in iterator.iter_init(|| full_stats(&residual, &μ, &z, ε, stats.clone())) { | |
238 | // Calculate initial transport | |
239 | let Pair(v, _) = opA.preadjoint().apply(&residual); | |
240 | //opKμ.preadjoint().apply_add(&mut v, y); | |
241 | // We want to proceed as in Example 4.12 but with v and v̆ as in §5. | |
242 | // With A(ν, z) = A_μ ν + A_z z, following Example 5.1, we have | |
243 | // P_ℳ[F'(ν, z) + Ξ(ν, z, y)]= A_ν^*[A_ν ν + A_z z] + K_μ ν = A_ν^*A(ν, z) + K_μ ν, | |
244 | // where A_ν^* becomes a multiplier. | |
245 | // This is much easier with K_μ = 0, which is the only reason why are enforcing it. | |
246 | // TODO: Write a version of initial_transport that can deal with K_μ ≠ 0. | |
247 | ||
248 | let (μ_base_masses, mut μ_base_minus_γ0) = initial_transport( | |
41
b6bdb6cb4d44
Remove initial transport adaptation—it is not needed, after all
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
249 | &mut γ1, &mut μ, τ, &mut θ_or_adaptive, v, |
35 | 250 | ); |
251 | ||
252 | // Solve finite-dimensional subproblem several times until the dual variable for the | |
253 | // regularisation term conforms to the assumptions made for the transport above. | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
254 | let (maybe_d, _within_tolerances, mut τv̆, z_new) = 'adapt_transport: loop { |
35 | 255 | // Calculate τv̆ = τA_*(A[μ_transported + μ_transported_base]-b) |
256 | let residual_μ̆ = calculate_residual2(Pair(&γ1, &z), | |
257 | Pair(&μ_base_minus_γ0, &zero_z), | |
258 | opA, b); | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
259 | let Pair(mut τv̆, τz̆) = opA.preadjoint().apply(residual_μ̆ * τ); |
35 | 260 | // opKμ.preadjoint().gemv(&mut τv̆, τ, y, 1.0); |
261 | ||
262 | // Construct μ^{k+1} by solving finite-dimensional subproblems and insert new spikes. | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
263 | let (maybe_d, within_tolerances) = prox_penalty.insert_and_reweigh( |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
264 | &mut μ, &mut τv̆, &γ1, Some(&μ_base_minus_γ0), |
35 | 265 | τ, ε, &config.insertion, |
266 | ®, &state, &mut stats, | |
267 | ); | |
268 | ||
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
269 | // Do z variable primal update here to able to estimate B_{v̆^k-v^{k+1}} |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
270 | let mut z_new = τz̆; |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
271 | opKz.adjoint().gemv(&mut z_new, -σ_p, &y, -σ_p/τ); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
272 | z_new = fnR.prox(σ_p, z_new + &z); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
273 | |
35 | 274 | // A posteriori transport adaptation. |
275 | if aposteriori_transport( | |
276 | &mut γ1, &mut μ, &mut μ_base_minus_γ0, &μ_base_masses, | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
277 | Some(z_new.dist(&z, L2)), |
35 | 278 | ε, &config.transport |
279 | ) { | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
280 | break 'adapt_transport (maybe_d, within_tolerances, τv̆, z_new) |
35 | 281 | } |
282 | }; | |
283 | ||
284 | stats.untransported_fraction = Some({ | |
285 | assert_eq!(μ_base_masses.len(), γ1.len()); | |
286 | let (a, b) = stats.untransported_fraction.unwrap_or((0.0, 0.0)); | |
287 | let source = μ_base_masses.iter().map(|v| v.abs()).sum(); | |
288 | (a + μ_base_minus_γ0.norm(Radon), b + source) | |
289 | }); | |
290 | stats.transport_error = Some({ | |
291 | assert_eq!(μ_base_masses.len(), γ1.len()); | |
292 | let (a, b) = stats.transport_error.unwrap_or((0.0, 0.0)); | |
293 | (a + μ.dist_matching(&γ1), b + γ1.norm(Radon)) | |
294 | }); | |
295 | ||
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
296 | // Merge spikes. |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
297 | // This crucially expects the merge routine to be stable with respect to spike locations, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
298 | // and not to performing any pruning. That is be to done below simultaneously for γ. |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
299 | let ins = &config.insertion; |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
300 | if ins.merge_now(&state) { |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
301 | stats.merged += prox_penalty.merge_spikes_no_fitness( |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
302 | &mut μ, &mut τv̆, &γ1, Some(&μ_base_minus_γ0), τ, ε, ins, ®, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
303 | //Some(|μ̃ : &RNDM<F, N>| calculate_residual(Pair(μ̃, &z), opA, b).norm2_squared_div2()), |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
304 | ); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
305 | } |
35 | 306 | |
307 | // Prune spikes with zero weight. To maintain correct ordering between μ and γ1, also the | |
308 | // latter needs to be pruned when μ is. | |
309 | // TODO: This could do with a two-vector Vec::retain to avoid copies. | |
310 | let μ_new = DiscreteMeasure::from_iter(μ.iter_spikes().filter(|δ| δ.α != F::ZERO).cloned()); | |
311 | if μ_new.len() != μ.len() { | |
312 | let mut μ_iter = μ.iter_spikes(); | |
313 | γ1.prune_by(|_| μ_iter.next().unwrap().α != F::ZERO); | |
314 | stats.pruned += μ.len() - μ_new.len(); | |
315 | μ = μ_new; | |
316 | } | |
317 | ||
318 | // Do dual update | |
319 | // opKμ.gemv(&mut y, σ_d*(1.0 + ω), &μ, 1.0); // y = y + σ_d K[(1+ω)(μ,z)^{k+1}] | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
320 | opKz.gemv(&mut y, σ_d*(1.0 + ω), &z_new, 1.0); |
35 | 321 | // opKμ.gemv(&mut y, -σ_d*ω, μ_base, 1.0);// y = y + σ_d K[(1+ω)(μ,z)^{k+1} - ω (μ,z)^k]-b |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
322 | opKz.gemv(&mut y, -σ_d*ω, z, 1.0);// y = y + σ_d K[(1+ω)(μ,z)^{k+1} - ω (μ,z)^k]-b |
35 | 323 | y = starH.prox(σ_d, y); |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
324 | z = z_new; |
35 | 325 | |
326 | // Update residual | |
327 | residual = calculate_residual(Pair(&μ, &z), opA, b); | |
328 | ||
329 | // Update step length parameters | |
330 | // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ); | |
331 | ||
332 | // Give statistics if requested | |
333 | let iter = state.iteration(); | |
334 | stats.this_iters += 1; | |
335 | ||
336 | state.if_verbose(|| { | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
36
diff
changeset
|
337 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv̆), &μ); |
35 | 338 | full_stats(&residual, &μ, &z, ε, std::mem::replace(&mut stats, IterInfo::new())) |
339 | }); | |
340 | ||
341 | // Update main tolerance for next iteration | |
342 | ε = tolerance.update(ε, iter); | |
343 | } | |
344 | ||
345 | let fit = |μ̃ : &RNDM<F, N>| { | |
346 | (opA.apply(Pair(μ̃, &z))-b).norm2_squared_div2() | |
347 | //+ fnR.apply(z) + reg.apply(μ) | |
348 | + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z)) | |
349 | }; | |
350 | ||
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
351 | μ.merge_spikes_fitness(config.insertion.final_merging_method(), fit, |&v| v); |
35 | 352 | μ.prune(); |
353 | Pair(μ, z) | |
354 | } |