Sun, 19 Jul 2026 07:34:39 +0200
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
| 34 | 1 | /*! |
| 2 | Iterative algorithms for solving the finite-dimensional subproblem without constraints. | |
| 3 | */ | |
| 4 | ||
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
5 | use itertools::izip; |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
6 | use nalgebra::{constraint::ShapeConstraint, DVector, Dyn, Storage, StorageMut, Vector, U1}; |
| 34 | 7 | use numeric_literals::replace_float_literals; |
| 8 | use std::cmp::Ordering::*; | |
| 9 | ||
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
10 | use alg_tools::iterate::{AlgIteratorFactory, AlgIteratorState}; |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
11 | use alg_tools::nalgebra_support::{StridesOk, ToNalgebraRealField}; |
| 34 | 12 | use alg_tools::norms::{Dist, L1}; |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
13 | use std::iter::zip; |
| 34 | 14 | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
15 | use super::l1squared_nonneg::max_interval_dist_to_zero; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
16 | use super::unconstrained::soft_thresholding; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
17 | use super::{InnerMethod, InnerSettings}; |
| 34 | 18 | use crate::types::*; |
| 19 | ||
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
20 | /// Calculate $\prox_f(x)$ for $f(x)=\frac{β}{2}\norm{x-y}_1^2$. |
| 34 | 21 | /// |
| 22 | /// To derive an algorithm for this, we can assume that $y=0$, as | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
23 | /// $\prox\_f(x) = \prox\_{f_0}(x - y) - y$ for $f\_0=\frac{β}{2}\norm{x}\_1^2$. |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
24 | /// Now, the optimality conditions for $w = \prox\_f(x)$ are |
| 34 | 25 | /// $$ |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
26 | /// 0 ∈ w-x + β\norm{w}\_1\sign w. |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
27 | /// $$ |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
28 | /// Clearly then $w = \soft\_{β\norm{w}\_1}(x)$. |
| 34 | 29 | /// Thus the components of $x$ with smallest absolute value will be zeroed out. |
| 30 | /// Denoting by $w'$ the non-zero components, and by $x'$ the corresponding components | |
| 31 | /// of $x$, and by $m$ their count, multipying the corresponding lines of (*) by $\sign x'$, | |
| 32 | /// we obtain | |
| 33 | /// $$ | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
34 | /// \norm{x'}\_1 = (1+βm)\norm{w'}\_1. |
| 34 | 35 | /// $$ |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
36 | /// That is, $\norm{w}\_1=\norm{w'}\_1=\norm{x'}\_1/(1+βm)$. |
| 34 | 37 | /// Thus, sorting $x$ by absolute value, and sequentially in order eliminating the smallest |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
38 | /// elements, we can easily calculate what $\norm{w}\_1$ should be for that choice, and |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
39 | /// then easily calculate $w = \soft_{β\norm{w}\_1}(x)$. We just have to verify that |
| 34 | 40 | /// the resulting $w$ has the same norm. There's a shortcut to this, as we work |
| 41 | /// sequentially: just check that the smallest assumed-nonzero component $i$ satisfies the | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
42 | /// condition of soft-thresholding to remain non-zero: $|x\_i|>τ\norm{x'}/(1+τm)$. |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
43 | /// Clearly, if this condition fails for $x\_i$, it will fail for all the components |
| 34 | 44 | /// already exluced. While, if it holds, it will hold for all components not excluded. |
| 45 | #[replace_float_literals(F::cast_from(literal))] | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
46 | pub(super) fn l1squared_prox<F: Float + nalgebra::RealField, S1, S2>( |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
47 | sorted_abs: &mut DVector<F>, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
48 | x: &mut Vector<F, Dyn, S1>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
49 | y: &Vector<F, Dyn, S2>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
50 | β: F, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
51 | ) where |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
52 | S2: Storage<F, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
53 | S1: StorageMut<F, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
54 | { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
55 | //let orig_x = x.clone(); |
| 34 | 56 | sorted_abs.copy_from(x); |
| 57 | sorted_abs.axpy(-1.0, y, 1.0); | |
| 58 | sorted_abs.apply(|z_i| *z_i = num_traits::abs(*z_i)); | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
59 | sorted_abs.as_mut_slice().sort_unstable_by(F::total_cmp); |
| 34 | 60 | |
| 61 | let mut n = sorted_abs.sum(); | |
| 62 | for (m, az_i) in zip((1..=x.len() as u32).rev(), sorted_abs) { | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
63 | // test first. This is just *az_i <= tmp, for tmp defined below, without the division. |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
64 | if *az_i <= β * (n - F::cast_from(m) * *az_i) { |
| 34 | 65 | // Fail |
| 66 | n -= *az_i; | |
| 67 | } else { | |
| 68 | // Success | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
69 | let tmp = β * n / (1.0 + β * F::cast_from(m)); |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
70 | x.zip_apply(y, |x_i, y_i| { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
71 | *x_i = y_i + soft_thresholding(*x_i - y_i, tmp) |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
72 | }); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
73 | // //Check 0 ∈ w-x + β\norm{w-y}\_1\sign (w-y). |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
74 | // let n: F = izip!(x.iter(), y) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
75 | // .map(|(&w_i, &y_i)| NumTraitsFloat::abs(w_i - y_i)) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
76 | // .sum(); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
77 | // for (&mut w_i, &x_i, &y_i) in izip!(x, &orig_x, y) { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
78 | // if w_i > y_i { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
79 | // assert_lt!(NumTraitsFloat::abs(w_i - x_i + n * β), 10.0 * F::EPSILON); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
80 | // } else if w_i < y_i { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
81 | // assert_lt!(NumTraitsFloat::abs(w_i - x_i - n * β), 10.0 * F::EPSILON); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
82 | // } else { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
83 | // assert_lt!(-n * β - 10.0 * F::EPSILON, w_i - x_i); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
84 | // assert_lt!(w_i - x_i, n * β + 10.0 * F::EPSILON); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
85 | // } |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
86 | // } |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
87 | return; |
| 34 | 88 | } |
| 89 | } | |
| 90 | // m = 0 should always work, but x is zero. | |
| 91 | x.fill(0.0); | |
| 92 | } | |
| 93 | ||
| 94 | /// Returns the ∞-norm minimal subdifferential of $x ↦ (β/2)|x-y|_1^2 - g^⊤ x + λ\|x\|₁$ at $x$. | |
| 95 | /// | |
| 96 | /// `v` will be modified and cannot be trusted to contain useful values afterwards. | |
| 97 | #[replace_float_literals(F::cast_from(literal))] | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
98 | fn min_subdifferential<F: Float + nalgebra::RealField, S1, S2, S3>( |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
99 | y: &Vector<F, Dyn, S1>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
100 | x: &Vector<F, Dyn, S2>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
101 | g: &Vector<F, Dyn, S3>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
102 | λ: F, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
103 | ) -> F |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
104 | where |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
105 | S1: Storage<F, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
106 | S2: Storage<F, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
107 | S3: Storage<F, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
108 | ShapeConstraint: StridesOk<F, Dyn, U1, S2>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
109 | { |
| 34 | 110 | let mut val = 0.0; |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
111 | let tmp = y.dist(x, L1); |
| 34 | 112 | for (&g_i, &x_i, y_i) in izip!(g.iter(), x.iter(), y.iter()) { |
| 113 | let (mut lb, mut ub) = (-g_i, -g_i); | |
| 114 | match x_i.partial_cmp(y_i) { | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
115 | Some(Greater) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
116 | lb += tmp; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
117 | ub += tmp |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
118 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
119 | Some(Less) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
120 | lb -= tmp; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
121 | ub -= tmp |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
122 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
123 | Some(Equal) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
124 | lb -= tmp; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
125 | ub += tmp |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
126 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
127 | None => {} |
| 34 | 128 | } |
| 129 | match x_i.partial_cmp(&0.0) { | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
130 | Some(Greater) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
131 | lb += λ; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
132 | ub += λ |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
133 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
134 | Some(Less) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
135 | lb -= λ; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
136 | ub -= λ |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
137 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
138 | Some(Equal) => { |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
139 | lb -= λ; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
140 | ub += λ |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
141 | } |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
142 | None => {} |
| 34 | 143 | }; |
| 144 | val = max_interval_dist_to_zero(val, lb, ub); | |
| 145 | } | |
| 146 | val | |
| 147 | } | |
| 148 | ||
| 149 | /// PDPS implementation of [`l1squared_unconstrained`]. | |
| 150 | /// For detailed documentation of the inputs and outputs, refer to there. | |
| 151 | /// | |
| 152 | /// The `λ` component of the model is handled in the proximal step instead of the gradient step | |
| 153 | /// for potential performance improvements. | |
| 154 | #[replace_float_literals(F::cast_from(literal).to_nalgebra_mixed())] | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
155 | pub fn l1squared_unconstrained_pdps<F, I, S1, S2, S3>( |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
156 | y: &Vector<F::MixedType, Dyn, S1>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
157 | g: &Vector<F::MixedType, Dyn, S2>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
158 | λ_: F, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
159 | x: &mut Vector<F::MixedType, Dyn, S3>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
160 | τ_: F, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
161 | σ_: F, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
162 | iterator: I, |
| 34 | 163 | ) -> usize |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
164 | where |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
165 | F: Float + ToNalgebraRealField, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
166 | I: AlgIteratorFactory<F>, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
167 | S1: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
168 | S2: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
169 | S3: StorageMut<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
170 | ShapeConstraint: StridesOk<F::MixedType, Dyn, U1, S3>, |
| 34 | 171 | { |
| 172 | let λ = λ_.to_nalgebra_mixed(); | |
| 173 | let τ = τ_.to_nalgebra_mixed(); | |
| 174 | let σ = σ_.to_nalgebra_mixed(); | |
| 175 | let mut w = DVector::zeros(x.len()); | |
| 176 | let mut tmp = DVector::zeros(x.len()); | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
177 | let mut xprev = x.clone_owned(); |
| 34 | 178 | let mut iters = 0; |
| 179 | ||
| 180 | iterator.iterate(|state| { | |
| 181 | // Primal step: x^{k+1} = prox_{τ|.-y|_1^2}(x^k - τ (w^k - g)) | |
| 182 | x.axpy(-τ, &w, 1.0); | |
| 183 | x.axpy(τ, g, 1.0); | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
184 | l1squared_prox(&mut tmp, x, y, τ); |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
185 | |
| 34 | 186 | // Dual step: w^{k+1} = proj_{[-λ,λ]}(w^k + σ(2x^{k+1}-x^k)) |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
187 | w.axpy(2.0 * σ, x, 1.0); |
| 34 | 188 | w.axpy(-σ, &xprev, 1.0); |
| 189 | w.apply(|w_i| *w_i = num_traits::clamp(*w_i, -λ, λ)); | |
| 190 | xprev.copy_from(x); | |
| 191 | ||
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
192 | iters += 1; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
193 | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
194 | state.if_verbose(|| F::from_nalgebra_mixed(min_subdifferential(y, x, g, λ))) |
| 34 | 195 | }); |
| 196 | ||
| 197 | iters | |
| 198 | } | |
| 199 | ||
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
200 | /// Alternative PDPS implementation of [`l1squared_unconstrained`]. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
201 | /// For detailed documentation of the inputs and outputs, refer to there. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
202 | /// |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
203 | /// By not dualising the 1-norm, this should produce more sparse solutions than |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
204 | /// [`l1squared_unconstrained_pdps`]. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
205 | /// |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
206 | /// The `λ` component of the model is handled in the proximal step instead of the gradient step |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
207 | /// for potential performance improvements. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
208 | /// The parameter `θ` is used to multiply the rescale the operator (identity) of the PDPS model. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
209 | /// We rewrite |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
210 | /// <div>$$ |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
211 | /// \begin{split} |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
212 | /// & \min_{x ∈ ℝ^n} \frac{β}{2} |x-y|_1^2 - g^⊤ x + λ\|x\|₁ \\ |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
213 | /// & = \min_{x ∈ ℝ^n} \max_{w} ⟨θ w, x⟩ - g^⊤ x + λ\|x\|₁ |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
214 | /// - \left(x ↦ \frac{β}{2θ} |x-y|_1^2 \right)^*(w). |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
215 | /// \end{split} |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
216 | /// $$</div> |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
217 | #[replace_float_literals(F::cast_from(literal).to_nalgebra_mixed())] |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
218 | pub fn l1squared_unconstrained_pdps_alt<F, I, S1, S2, S3>( |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
219 | y: &Vector<F::MixedType, Dyn, S1>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
220 | g: &Vector<F::MixedType, Dyn, S2>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
221 | λ_: F, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
222 | x: &mut Vector<F::MixedType, Dyn, S3>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
223 | τ_: F, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
224 | σ_: F, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
225 | θ_: F, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
226 | iterator: I, |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
227 | ) -> usize |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
228 | where |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
229 | F: Float + ToNalgebraRealField, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
230 | I: AlgIteratorFactory<F>, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
231 | S1: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
232 | S2: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
233 | S3: StorageMut<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
234 | ShapeConstraint: StridesOk<F::MixedType, Dyn, U1, S3>, |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
235 | { |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
236 | let λ = λ_.to_nalgebra_mixed(); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
237 | let τ = τ_.to_nalgebra_mixed(); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
238 | let σ = σ_.to_nalgebra_mixed(); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
239 | let θ = θ_.to_nalgebra_mixed(); |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
240 | let σθ = σ * θ; |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
241 | let τθ = τ * θ; |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
242 | let mut w = DVector::zeros(x.len()); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
243 | let mut tmp = DVector::zeros(x.len()); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
244 | let mut xprev = x.clone_owned(); |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
245 | let mut iters = 0; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
246 | |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
247 | iterator.iterate(|state| { |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
248 | // Primal step: x^{k+1} = soft_τλ(x^k - τ(θ w^k -g)) |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
249 | x.axpy(-τθ, &w, 1.0); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
250 | x.axpy(τ, g, 1.0); |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
251 | x.apply(|x_i| *x_i = soft_thresholding(*x_i, τ * λ)); |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
252 | |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
253 | // Dual step: with g(x) = (β/(2θ))‖x-y‖₁² and q = w^k + σ(2x^{k+1}-x^k), |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
254 | // we compute w^{k+1} = prox_{σg^*}(q) for |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
255 | // = q - σ prox_{g/σ}(q/σ) |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
256 | // = q - σ prox_{(β/(2θσ))‖.-y‖₁²}(q/σ) |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
257 | // = σ(q/σ - prox_{(β/(2θσ))‖.-y‖₁²}(q/σ)) |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
258 | // where q/σ = w^k/σ + (2x^{k+1}-x^k), |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
259 | w /= σ; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
260 | w.axpy(2.0, x, 1.0); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
261 | w.axpy(-1.0, &xprev, 1.0); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
262 | xprev.copy_from(&w); // use xprev as temporary variable |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
263 | l1squared_prox(&mut tmp, &mut xprev, y, 1.0 / σθ); |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
264 | w -= &xprev; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
265 | w *= σ; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
266 | xprev.copy_from(x); |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
267 | |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
268 | iters += 1; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
269 | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
270 | state.if_verbose(|| F::from_nalgebra_mixed(min_subdifferential(y, x, g, λ))) |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
271 | }); |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
272 | |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
273 | iters |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
274 | } |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
275 | |
| 34 | 276 | /// This function applies an iterative method for the solution of the problem |
| 277 | /// <div>$$ | |
| 278 | /// \min_{x ∈ ℝ^n} \frac{β}{2} |x-y|_1^2 - g^⊤ x + λ\|x\|₁. | |
| 279 | /// $$</div> | |
| 280 | /// Only PDPS is supported. | |
| 281 | /// | |
| 282 | /// This function returns the number of iterations taken. | |
| 283 | #[replace_float_literals(F::cast_from(literal))] | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
284 | pub fn l1squared_unconstrained<F, I, S1, S2, S3>( |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
285 | y: &Vector<F::MixedType, Dyn, S1>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
286 | g: &Vector<F::MixedType, Dyn, S2>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
287 | λ: F, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
288 | x: &mut Vector<F::MixedType, Dyn, S3>, |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
289 | inner: &InnerSettings<F>, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
290 | iterator: I, |
| 34 | 291 | ) -> usize |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
292 | where |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
293 | F: Float + ToNalgebraRealField, |
|
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
294 | I: AlgIteratorFactory<F>, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
295 | S1: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
296 | S2: Storage<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
297 | S3: StorageMut<F::MixedType, Dyn>, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
298 | ShapeConstraint: StridesOk<F::MixedType, Dyn, U1, S3>, |
| 34 | 299 | { |
|
42
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
300 | // Estimate of ‖K‖ for K=θ Id. |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
301 | let inner_θ = 1.0; |
|
6a7365d73e4c
Fixes to Radon norm prox term inner algorithm
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
302 | let normest = inner_θ; |
| 34 | 303 | |
| 304 | let (inner_τ, inner_σ) = (inner.pdps_τσ0.0 / normest, inner.pdps_τσ0.1 / normest); | |
| 305 | ||
| 306 | match inner.method { | |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
307 | InnerMethod::PDPS => { |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
54
diff
changeset
|
308 | l1squared_unconstrained_pdps_alt(y, g, λ, x, inner_τ, inner_σ, inner_θ, iterator) |
|
54
b3312eee105c
Make some math in documentation render
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
309 | } |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
34
diff
changeset
|
310 | other => unimplemented!("${other:?} is unimplemented"), |
| 34 | 311 | } |
| 312 | } |