Thu, 06 Aug 2026 11:14:15 -0500
Generalise algorithms to arbitrary domains
| 0 | 1 | /*! |
| 2 | Solver for the point source localisation problem using a conditional gradient method. | |
| 3 | ||
| 4 | We implement two variants, the “fully corrective” method from | |
| 5 | ||
| 6 | * Pieper K., Walter D. _Linear convergence of accelerated conditional gradient algorithms | |
| 7 | in spaces of measures_, DOI: [10.1051/cocv/2021042](https://doi.org/10.1051/cocv/2021042), | |
| 8 | arXiv: [1904.09218](https://doi.org/10.48550/arXiv.1904.09218). | |
| 9 | ||
| 10 | and what we call the “relaxed” method from | |
| 11 | ||
| 12 | * Bredies K., Pikkarainen H. - _Inverse problems in spaces of measures_, | |
| 13 | DOI: [10.1051/cocv/2011205](https://doi.org/0.1051/cocv/2011205). | |
| 14 | */ | |
| 15 | ||
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
16 | use nalgebra::{DMatrix, DVector}; |
| 0 | 17 | use numeric_literals::replace_float_literals; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
18 | use serde::{Deserialize, Serialize}; |
| 0 | 19 | //use colored::Colorize; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
20 | use crate::dataterm::QuadraticDataTerm; |
| 0 | 21 | use crate::forward_model::ForwardModel; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
22 | use crate::measures::merging::{SpikeMerging, SpikeMergingMethod}; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
23 | use crate::measures::{DeltaMeasure, DiscreteMeasure, Radon}; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
24 | use crate::plot::Plotter; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
25 | use crate::regularisation::{NonnegRadonRegTerm, RadonRegTerm, RegTerm}; |
| 0 | 26 | #[allow(unused_imports)] // Used in documentation |
| 27 | use crate::subproblem::{ | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
28 | nonneg::quadratic_nonneg, unconstrained::quadratic_unconstrained, InnerMethod, InnerSettings, |
| 0 | 29 | }; |
| 30 | use crate::tolerance::Tolerance; | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
31 | use crate::types::*; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
32 | use alg_tools::bounds::MinMaxMapping; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
33 | use alg_tools::error::DynResult; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
34 | use alg_tools::euclidean::Euclidean; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
35 | use alg_tools::instance::Instance; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
36 | use alg_tools::iterate::{AlgIteratorFactory, AlgIteratorOptions, ValueIteratorFactory}; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
37 | use alg_tools::linops::{Mapping, Space}; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
38 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
39 | use alg_tools::norms::Norm; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
40 | use alg_tools::norms::L2; |
| 0 | 41 | |
| 35 | 42 | /// Settings for [`pointsource_fw_reg`]. |
| 0 | 43 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
| 44 | #[serde(default)] | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
45 | pub struct FWConfig<F: Float> { |
| 0 | 46 | /// Tolerance for branch-and-bound new spike location discovery |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
47 | pub tolerance: Tolerance<F>, |
| 0 | 48 | /// Inner problem solution configuration. Has to have `method` set to [`InnerMethod::FB`] |
| 49 | /// as the conditional gradient subproblems' optimality conditions do not in general have an | |
| 50 | /// invertible Newton derivative for SSN. | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
51 | pub inner: InnerSettings<F>, |
| 0 | 52 | /// Variant of the conditional gradient method |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
53 | pub variant: FWVariant, |
| 0 | 54 | /// Settings for branch and bound refinement when looking for predual maxima |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
55 | pub refinement: RefinementSettings<F>, |
| 0 | 56 | /// Spike merging heuristic |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
57 | pub merging: SpikeMergingMethod<F>, |
| 0 | 58 | } |
| 59 | ||
| 60 | /// Conditional gradient method variant; see also [`FWConfig`]. | |
| 61 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
| 62 | #[allow(dead_code)] | |
| 63 | pub enum FWVariant { | |
| 64 | /// Algorithm 2 of Walter-Pieper | |
| 65 | FullyCorrective, | |
| 66 | /// Bredies–Pikkarainen. Forces `FWConfig.inner.max_iter = 1`. | |
| 67 | Relaxed, | |
| 68 | } | |
| 69 | ||
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
70 | impl<F: Float> Default for FWConfig<F> { |
| 0 | 71 | fn default() -> Self { |
| 72 | FWConfig { | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
73 | tolerance: Default::default(), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
74 | refinement: Default::default(), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
75 | inner: Default::default(), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
76 | variant: FWVariant::FullyCorrective, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
77 | merging: SpikeMergingMethod { enabled: true, ..Default::default() }, |
| 0 | 78 | } |
| 79 | } | |
| 80 | } | |
| 81 | ||
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
82 | pub trait FindimQuadraticModel<Domain, F>: ForwardModel<DiscreteMeasure<Domain, F>, F> |
| 35 | 83 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
84 | F: Float + ToNalgebraRealField, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
85 | Domain: Clone + PartialEq, |
| 35 | 86 | { |
| 87 | /// Return A_*A and A_* b | |
| 88 | fn findim_quadratic_model( | |
| 89 | &self, | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
90 | μ: &DiscreteMeasure<Domain, F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
91 | b: &Self::Observable, |
| 35 | 92 | ) -> (DMatrix<F::MixedType>, DVector<F::MixedType>); |
| 93 | } | |
| 94 | ||
| 95 | /// Helper struct for pre-initialising the finite-dimensional subproblem solver. | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
96 | pub struct FindimData<F: Float> { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
97 | /// ‖A‖^2 |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
98 | opAnorm_squared: F, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
99 | /// Bound $M_0$ from the Bredies–Pikkarainen article. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
100 | m0: F, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
101 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
102 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
103 | /// Trait for finite dimensional weight optimisation. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
104 | pub trait WeightOptim< |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
105 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
106 | U: Space + Clone + PartialEq, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
107 | A: ForwardModel<DiscreteMeasure<U, F>, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
108 | I: AlgIteratorFactory<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
109 | > |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
110 | { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
111 | /// Return a pre-initialisation struct for [`Self::optimise_weights`]. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
112 | /// |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
113 | /// The parameter `opA` is the forward operator $A$. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
114 | fn prepare_optimise_weights(&self, opA: &A, b: &A::Observable) -> DynResult<FindimData<F>>; |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
115 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
116 | /// Solve the finite-dimensional weight optimisation problem for the 2-norm-squared data fidelity |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
117 | /// point source localisation problem. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
118 | /// |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
119 | /// That is, we minimise |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
120 | /// <div>$$ |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
121 | /// μ ↦ \frac{1}{2}\|Aμ-b\|_w^2 + G(μ) |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
122 | /// $$</div> |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
123 | /// only with respect to the weights of $μ$. Here $G$ is a regulariser modelled by `Self`. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
124 | /// |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
125 | /// The parameter `μ` is the discrete measure whose weights are to be optimised. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
126 | /// The `opA` parameter is the forward operator $A$, while `b`$ and `α` are as in the |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
127 | /// objective above. The method parameter are set in `inner` (see [`InnerSettings`]), while |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
128 | /// `iterator` is used to iterate the steps of the method, and `plotter` may be used to |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
129 | /// save intermediate iteration states as images. The parameter `findim_data` should be |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
130 | /// prepared using [`Self::prepare_optimise_weights`]: |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
131 | /// |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
132 | /// Returns the number of iterations taken by the method configured in `inner`. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
133 | fn optimise_weights<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
134 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
135 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
136 | opA: &'a A, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
137 | b: &A::Observable, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
138 | findim_data: &FindimData<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
139 | inner: &InnerSettings<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
140 | iterator: I, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
141 | ) -> usize; |
| 0 | 142 | } |
| 143 | ||
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
144 | /// Trait for regularisation terms supported by [`pointsource_fw_reg`]. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
145 | pub trait RegTermFW< |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
146 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
147 | U: Space + Clone + PartialEq, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
148 | A: ForwardModel<DiscreteMeasure<U, F>, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
149 | I: AlgIteratorFactory<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
150 | >: RegTerm<U, F> + WeightOptim<F, U, A, I> + Mapping<DiscreteMeasure<U, F>, Codomain = F> |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
151 | { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
152 | /// With $g = A\_\*(Aμ-b)$, returns $(x, g(x))$ for $x$ a new point to be inserted |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
153 | /// into $μ$, as determined by the regulariser. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
154 | /// |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
155 | /// The parameters `refinement_tolerance` and `max_steps` are passed to relevant |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
156 | /// [`MinMaxMapping`] minimisation and maximisation routines. |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
157 | fn find_insertion( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
158 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
159 | g: &mut A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
160 | refinement_tolerance: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
161 | max_steps: usize, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
162 | ) -> (U, F); |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
163 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
164 | /// Insert point `ξ` into `μ` for the relaxed algorithm from Bredies–Pikkarainen. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
165 | fn relaxed_insert<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
166 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
167 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
168 | g: &A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
169 | opA: &'a A, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
170 | ξ: U, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
171 | v_ξ: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
172 | findim_data: &FindimData<F>, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
173 | ); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
174 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
175 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
176 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
177 | impl<F: Float + ToNalgebraRealField, U, A, I> WeightOptim<F, U, A, I> for RadonRegTerm<F> |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
178 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
179 | U: Space + Clone + PartialEq, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
180 | I: AlgIteratorFactory<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
181 | A: FindimQuadraticModel<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
182 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
183 | fn prepare_optimise_weights(&self, opA: &A, b: &A::Observable) -> DynResult<FindimData<F>> { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
184 | Ok(FindimData { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
185 | opAnorm_squared: opA.opnorm_bound(Radon, L2)?.powi(2), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
186 | m0: b.norm2_squared() / (2.0 * self.α()), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
187 | }) |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
188 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
189 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
190 | fn optimise_weights<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
191 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
192 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
193 | opA: &'a A, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
194 | b: &A::Observable, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
195 | findim_data: &FindimData<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
196 | inner: &InnerSettings<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
197 | iterator: I, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
198 | ) -> usize { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
199 | // Form and solve finite-dimensional subproblem. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
200 | let (Ã, g̃) = opA.findim_quadratic_model(&μ, b); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
201 | let mut x = μ.masses_dvector(); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
202 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
203 | // `inner_τ1` is based on an estimate of the operator norm of $A$ from ℳ(Ω) to |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
204 | // ℝ^n. This estimate is a good one for the matrix norm from ℝ^m to ℝ^n when the |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
205 | // former is equipped with the 1-norm. We need the 2-norm. To pass from 1-norm to |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
206 | // 2-norm, we estimate |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
207 | // ‖A‖_{2,2} := sup_{‖x‖_2 ≤ 1} ‖Ax‖_2 ≤ sup_{‖x‖_1 ≤ C} ‖Ax‖_2 |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
208 | // = C sup_{‖x‖_1 ≤ 1} ‖Ax‖_2 = C ‖A‖_{1,2}, |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
209 | // where C = √m satisfies ‖x‖_1 ≤ C ‖x‖_2. Since we are intested in ‖A_*A‖, no |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
210 | // square root is needed when we scale: |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
211 | let normest = findim_data.opAnorm_squared * F::cast_from(μ.len()); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
212 | let iters = quadratic_unconstrained(&Ã, &g̃, self.α(), &mut x, normest, inner, iterator); |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
213 | // Update masses of μ based on solution of finite-dimensional subproblem. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
214 | μ.set_masses_dvector(&x); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
215 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
216 | iters |
| 0 | 217 | } |
| 218 | } | |
| 219 | ||
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
220 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
221 | impl<F: Float + ToNalgebraRealField, U, A, I> RegTermFW<F, U, A, I> for RadonRegTerm<F> |
| 35 | 222 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
223 | U: Space + Clone + PartialEq, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
224 | RadonRegTerm<F>: RegTerm<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
225 | I: AlgIteratorFactory<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
226 | A: FindimQuadraticModel<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
227 | A::PreadjointCodomain: MinMaxMapping<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
228 | for<'a> &'a A::PreadjointCodomain: Instance<A::PreadjointCodomain>, |
| 35 | 229 | // FIXME: the following *should not* be needed, they are already implied |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
230 | DiscreteMeasure<U, F>: Mapping<A::PreadjointCodomain, Codomain = F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
231 | DeltaMeasure<U, F>: Copy + Mapping<A::PreadjointCodomain, Codomain = F>, |
| 35 | 232 | { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
233 | fn find_insertion( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
234 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
235 | g: &mut A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
236 | refinement_tolerance: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
237 | max_steps: usize, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
238 | ) -> (U, F) { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
239 | let (ξmax, v_ξmax) = g.maximise(refinement_tolerance, max_steps); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
240 | let (ξmin, v_ξmin) = g.minimise(refinement_tolerance, max_steps); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
241 | if v_ξmin < 0.0 && -v_ξmin > v_ξmax { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
242 | (ξmin, v_ξmin) |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
243 | } else { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
244 | (ξmax, v_ξmax) |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
245 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
246 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
247 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
248 | fn relaxed_insert<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
249 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
250 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
251 | g: &A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
252 | opA: &'a A, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
253 | ξ: U, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
254 | v_ξ: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
255 | findim_data: &FindimData<F>, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
256 | ) { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
257 | let α = self.0; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
258 | let m0 = findim_data.m0; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
259 | let φ = |t| { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
260 | if t <= m0 { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
261 | α * t |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
262 | } else { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
263 | α / (2.0 * m0) * (t * t + m0 * m0) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
264 | } |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
265 | }; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
266 | let v = if v_ξ.abs() <= α { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
267 | 0.0 |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
268 | } else { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
269 | m0 / α * v_ξ |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
270 | }; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
271 | let δ = DeltaMeasure { x: ξ, α: v }; |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
272 | let dp = μ.apply(g) - δ.apply(g); |
| 35 | 273 | let d = opA.apply(&*μ) - opA.apply(δ); |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
274 | let r = d.norm2_squared(); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
275 | let s = if r == 0.0 { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
276 | 1.0 |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
277 | } else { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
278 | 1.0.min((α * μ.norm(Radon) - φ(v.abs()) - dp) / r) |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
279 | }; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
280 | *μ *= 1.0 - s; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
281 | *μ += δ * s; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
282 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
283 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
284 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
285 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
286 | impl<F: Float + ToNalgebraRealField, A, U, I> WeightOptim<F, U, A, I> for NonnegRadonRegTerm<F> |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
287 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
288 | U: Space + Clone + PartialEq, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
289 | I: AlgIteratorFactory<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
290 | A: FindimQuadraticModel<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
291 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
292 | fn prepare_optimise_weights(&self, opA: &A, b: &A::Observable) -> DynResult<FindimData<F>> { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
293 | Ok(FindimData { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
294 | opAnorm_squared: opA.opnorm_bound(Radon, L2)?.powi(2), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
295 | m0: b.norm2_squared() / (2.0 * self.α()), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
296 | }) |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
297 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
298 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
299 | fn optimise_weights<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
300 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
301 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
302 | opA: &'a A, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
303 | b: &A::Observable, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
304 | findim_data: &FindimData<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
305 | inner: &InnerSettings<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
306 | iterator: I, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
307 | ) -> usize { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
308 | // Form and solve finite-dimensional subproblem. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
309 | let (Ã, g̃) = opA.findim_quadratic_model(&μ, b); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
310 | let mut x = μ.masses_dvector(); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
311 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
312 | // `inner_τ1` is based on an estimate of the operator norm of $A$ from ℳ(Ω) to |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
313 | // ℝ^n. This estimate is a good one for the matrix norm from ℝ^m to ℝ^n when the |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
314 | // former is equipped with the 1-norm. We need the 2-norm. To pass from 1-norm to |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
315 | // 2-norm, we estimate |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
316 | // ‖A‖_{2,2} := sup_{‖x‖_2 ≤ 1} ‖Ax‖_2 ≤ sup_{‖x‖_1 ≤ C} ‖Ax‖_2 |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
317 | // = C sup_{‖x‖_1 ≤ 1} ‖Ax‖_2 = C ‖A‖_{1,2}, |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
318 | // where C = √m satisfies ‖x‖_1 ≤ C ‖x‖_2. Since we are intested in ‖A_*A‖, no |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
319 | // square root is needed when we scale: |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
320 | let normest = findim_data.opAnorm_squared * F::cast_from(μ.len()); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
321 | let iters = quadratic_nonneg(&Ã, &g̃, self.α(), &mut x, normest, inner, iterator); |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
322 | // Update masses of μ based on solution of finite-dimensional subproblem. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
323 | μ.set_masses_dvector(&x); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
324 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
325 | iters |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
326 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
327 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
328 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
329 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
330 | impl<F: Float + ToNalgebraRealField, U, A, I> RegTermFW<F, U, A, I> for NonnegRadonRegTerm<F> |
| 35 | 331 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
332 | U: Space + Clone + PartialEq, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
333 | NonnegRadonRegTerm<F>: RegTerm<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
334 | I: AlgIteratorFactory<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
335 | A: FindimQuadraticModel<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
336 | A::PreadjointCodomain: MinMaxMapping<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
337 | for<'a> &'a A::PreadjointCodomain: Instance<A::PreadjointCodomain>, |
| 35 | 338 | // FIXME: the following *should not* be needed, they are already implied |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
339 | DiscreteMeasure<U, F>: Mapping<A::PreadjointCodomain, Codomain = F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
340 | DeltaMeasure<U, F>: Mapping<A::PreadjointCodomain, Codomain = F>, |
| 35 | 341 | { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
342 | fn find_insertion( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
343 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
344 | g: &mut A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
345 | refinement_tolerance: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
346 | max_steps: usize, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
347 | ) -> (U, F) { |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
348 | g.maximise(refinement_tolerance, max_steps) |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
349 | } |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
350 | |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
351 | fn relaxed_insert<'a>( |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
352 | &self, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
353 | μ: &mut DiscreteMeasure<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
354 | g: &A::PreadjointCodomain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
355 | opA: &'a A, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
356 | ξ: U, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
357 | v_ξ: F, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
358 | findim_data: &FindimData<F>, |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
359 | ) { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
360 | // This is just a verbatim copy of RadonRegTerm::relaxed_insert. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
361 | let α = self.0; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
362 | let m0 = findim_data.m0; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
363 | let φ = |t| { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
364 | if t <= m0 { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
365 | α * t |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
366 | } else { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
367 | α / (2.0 * m0) * (t * t + m0 * m0) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
368 | } |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
369 | }; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
370 | let v = if v_ξ.abs() <= α { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
371 | 0.0 |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
372 | } else { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
373 | m0 / α * v_ξ |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
374 | }; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
375 | let δ = DeltaMeasure { x: ξ, α: v }; |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
376 | let dp = μ.apply(g) - δ.apply(g); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
377 | let d = opA.apply(&*μ) - opA.apply(&δ); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
378 | let r = d.norm2_squared(); |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
379 | let s = if r == 0.0 { |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
380 | 1.0 |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
381 | } else { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
382 | 1.0.min((α * μ.norm(Radon) - φ(v.abs()) - dp) / r) |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
383 | }; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
384 | *μ *= 1.0 - s; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
385 | *μ += δ * s; |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
386 | } |
| 0 | 387 | } |
| 388 | ||
| 389 | /// Solve point source localisation problem using a conditional gradient method | |
| 390 | /// for the 2-norm-squared data fidelity, i.e., the problem | |
| 391 | /// <div>$$ | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
392 | /// \min_μ \frac{1}{2}\|Aμ-b\|_w^2 + G(μ), |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
393 | /// $$ |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
394 | /// where $G$ is the regularisation term modelled by `reg`. |
|
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
395 | /// </div> |
| 0 | 396 | /// |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
397 | /// The `opA` parameter is the forward operator $A$, while `b`$ is as in the |
| 0 | 398 | /// objective above. The method parameter are set in `config` (see [`FWConfig`]), while |
| 399 | /// `iterator` is used to iterate the steps of the method, and `plotter` may be used to | |
| 400 | /// save intermediate iteration states as images. | |
| 401 | #[replace_float_literals(F::cast_from(literal))] | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
402 | pub fn pointsource_fw_reg<'a, F, U, I, A, Reg, Plot>( |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
403 | f: &'a QuadraticDataTerm<F, DiscreteMeasure<U, F>, A>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
404 | reg: &Reg, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
405 | config: &FWConfig<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
406 | iterator: I, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
407 | mut plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
408 | μ0: Option<DiscreteMeasure<U, F>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
409 | ) -> DynResult<DiscreteMeasure<U, F>> |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
410 | where |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
411 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
412 | U: Space + Clone + PartialEq, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
413 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
414 | A: ForwardModel<DiscreteMeasure<U, F>, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
415 | A::PreadjointCodomain: MinMaxMapping<U, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
416 | &'a A::PreadjointCodomain: Instance<A::PreadjointCodomain>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
417 | //Cube<N, F>: P2Minimise<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
418 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
419 | Reg: RegTermFW<F, U, A, ValueIteratorFactory<F, AlgIteratorOptions>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
420 | Plot: Plotter<A::PreadjointCodomain, A::PreadjointCodomain, DiscreteMeasure<U, F>>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
421 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
422 | let opA = f.operator(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
423 | let b = f.data(); |
| 0 | 424 | |
| 425 | // Set up parameters | |
| 426 | // We multiply tolerance by α for all algoritms. | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
427 | let tolerance = config.tolerance * reg.tolerance_scaling(); |
| 0 | 428 | let mut ε = tolerance.initial(); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
429 | let findim_data = reg.prepare_optimise_weights(opA, b)?; |
| 0 | 430 | |
| 431 | // Initialise operators | |
| 432 | let preadjA = opA.preadjoint(); | |
| 433 | ||
| 434 | // Initialise iterates | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
435 | let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new()); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
436 | let mut residual = f.residual(&μ); |
| 0 | 437 | |
| 35 | 438 | // Statistics |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
439 | let full_stats = |residual: &A::Observable, ν: &DiscreteMeasure<U, F>, ε, stats| IterInfo { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
440 | value: residual.norm2_squared_div2() + reg.apply(ν), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
441 | n_spikes: ν.len(), |
| 35 | 442 | ε, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
443 | ..stats |
| 35 | 444 | }; |
| 445 | let mut stats = IterInfo::new(); | |
| 0 | 446 | |
| 447 | // Run the algorithm | |
| 35 | 448 | for state in iterator.iter_init(|| full_stats(&residual, &μ, ε, stats.clone())) { |
| 0 | 449 | let inner_tolerance = ε * config.inner.tolerance_mult; |
| 450 | let refinement_tolerance = ε * config.refinement.tolerance_mult; | |
| 451 | ||
| 452 | // Calculate smooth part of surrogate model. | |
| 35 | 453 | let mut g = preadjA.apply(residual * (-1.0)); |
| 0 | 454 | |
| 455 | // Find absolute value maximising point | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
456 | let (ξ, v_ξ) = |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
457 | reg.find_insertion(&mut g, refinement_tolerance, config.refinement.max_steps); |
| 0 | 458 | |
| 459 | let inner_it = match config.variant { | |
| 460 | FWVariant::FullyCorrective => { | |
| 461 | // No point in optimising the weight here: the finite-dimensional algorithm is fast. | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
462 | μ += DeltaMeasure { x: ξ, α: 0.0 }; |
| 35 | 463 | stats.inserted += 1; |
| 0 | 464 | config.inner.iterator_options.stop_target(inner_tolerance) |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
465 | } |
| 0 | 466 | FWVariant::Relaxed => { |
| 467 | // Perform a relaxed initialisation of μ | |
|
25
79943be70720
Implement non-negativity constraints for the conditional gradient methods
Tuomo Valkonen <tuomov@iki.fi>
parents:
24
diff
changeset
|
468 | reg.relaxed_insert(&mut μ, &g, opA, ξ, v_ξ, &findim_data); |
| 35 | 469 | stats.inserted += 1; |
| 0 | 470 | // The stop_target is only needed for the type system. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
471 | AlgIteratorOptions { max_iter: 1, ..config.inner.iterator_options }.stop_target(0.0) |
| 0 | 472 | } |
| 473 | }; | |
| 474 | ||
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
475 | stats.inner_iters += |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
476 | reg.optimise_weights(&mut μ, opA, b, &findim_data, &config.inner, inner_it); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
477 | |
| 0 | 478 | // Merge spikes and update residual for next step and `if_verbose` below. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
479 | let (r, count) = μ.merge_spikes_fitness( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
480 | config.merging, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
481 | |μ̃| f.residual(μ̃), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
482 | A::Observable::norm2_squared, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
483 | ); |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
484 | residual = r; |
| 35 | 485 | stats.merged += count; |
| 0 | 486 | |
| 487 | // Prune points with zero mass | |
| 488 | let n_before_prune = μ.len(); | |
| 489 | μ.prune(); | |
| 490 | debug_assert!(μ.len() <= n_before_prune); | |
| 35 | 491 | stats.pruned += n_before_prune - μ.len(); |
| 0 | 492 | |
| 35 | 493 | stats.this_iters += 1; |
| 494 | let iter = state.iteration(); | |
| 0 | 495 | |
| 35 | 496 | // Give statistics if needed |
| 0 | 497 | state.if_verbose(|| { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
498 | plotter.plot_spikes(iter, Some(&g), Option::<&A::PreadjointCodomain>::None, &μ); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
499 | full_stats( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
500 | &residual, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
501 | &μ, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
502 | ε, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
503 | std::mem::replace(&mut stats, IterInfo::new()), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
504 | ) |
| 35 | 505 | }); |
| 506 | ||
| 507 | // Update tolerance | |
| 508 | ε = tolerance.update(ε, iter); | |
| 509 | } | |
| 0 | 510 | |
| 511 | // Return final iterate | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
512 | Ok(μ) |
| 0 | 513 | } |