Mon, 05 Dec 2022 23:50:22 +0200
Zenodo packaging hacks
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | /*! |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | Basic proximal penalty based on convolution operators $๐$. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | */ |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
|
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
|
5 | use super::{InsertionConfig, ProxPenalty, ProxTerm, StepLengthBound, StepLengthBoundPD}; |
|
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
|
6 | use crate::dataterm::QuadraticDataTerm; |
|
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
|
7 | use crate::forward_model::ForwardModel; |
|
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
|
8 | use crate::measures::merging::SpikeMerging; |
|
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
|
9 | use crate::measures::{DeltaMeasure, DiscreteMeasure, Radon}; |
|
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
|
10 | use crate::regularisation::RegTerm; |
|
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
|
11 | use crate::seminorms::DiscreteMeasureOp; |
|
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
|
12 | use crate::types::IterInfo; |
|
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
|
13 | 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
|
14 | 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
|
15 | use alg_tools::iterate::{AlgIterator, AlgIteratorIteration}; |
|
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 alg_tools::linops::BoundedLinear; |
|
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
|
17 | use alg_tools::mapping::{Instance, Mapping, Space}; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
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
|
19 | use alg_tools::norms::{Linfinity, Norm, NormExponent, L2}; |
|
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 alg_tools::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
|
21 | use colored::Colorize; |
|
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 nalgebra::DVector; |
|
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
|
23 | use numeric_literals::replace_float_literals; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | #[replace_float_literals(F::cast_from(literal))] |
|
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
|
26 | impl<F, M, Reg, ๐, O, Domain> ProxPenalty<Domain, M, Reg, F> for ๐ |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | 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
|
28 | Domain: Space + Clone + PartialEq + 'static, |
|
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
|
29 | for<'a> &'a Domain: Instance<Domain>, |
|
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
|
30 | 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
|
31 | ๐: DiscreteMeasureOp<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
|
32 | ๐::Codomain: Mapping<Domain, Codomain = 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
|
33 | M: Mapping<Domain, Codomain = 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
|
34 | for<'a> &'a M: std::ops::Add<๐::PreCodomain, Output = O>, |
|
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 | O: MinMaxMapping<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
|
36 | Reg: RegTerm<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
|
37 | DiscreteMeasure<Domain, F>: SpikeMerging<F>, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | { |
|
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
|
39 | type ReturnMapping = O; |
|
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 | |
|
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
|
41 | fn prox_type() -> ProxTerm { |
|
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
|
42 | ProxTerm::Wave |
|
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
|
43 | } |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | fn insert_and_reweigh<I>( |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | &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
|
47 | ฮผ: &mut 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
|
48 | ฯv: &mut M, |
|
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
|
49 | ฯ: 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
|
50 | ฮต: 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
|
51 | config: &InsertionConfig<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
|
52 | 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
|
53 | state: &AlgIteratorIteration<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
|
54 | stats: &mut IterInfo<F>, |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
55 | ) -> DynResult<bool> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | 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
|
57 | I: AlgIterator, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | { |
|
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
|
59 | let op๐norm = self.opnorm_bound(Radon, Linfinity)?; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | // Maximum insertion count and measure difference calculation depend on insertion style. |
|
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
|
62 | let (max_insertions, warn_insertions) = |
|
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
|
63 | match (state.iteration(), config.bootstrap_insertions) { |
|
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
|
64 | (i, Some((l, k))) if i <= l => (k, false), |
|
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
|
65 | _ => (config.max_insertions, !state.is_quiet()), |
|
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
|
66 | }; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
68 | let ฮผ_base = ฮผ.clone(); |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
69 | let ฯ0 = self.apply(&ฮผ_base); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | // Add points to support until within error tolerance or maximum insertion count reached. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | let mut count = 0; |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
73 | let within_tolerances = 'insertion: loop { |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | if ฮผ.len() > 0 { |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | // Form finite-dimensional subproblem. The subproblem references to the original ฮผ^k |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
76 | // from the beginning of the iteration are all contained in the immutable c and g. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
77 | // TODO: observe negation of -ฯv after switch from minus_ฯv: finite-dimensional |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
78 | // problems have not yet been updated to sign change. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | let Aฬ = self.findim_matrix(ฮผ.iter_locations()); |
|
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
|
80 | let gฬ = DVector::from_iterator( |
|
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
|
81 | ฮผ.len(), |
|
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 | ฮผ.iter_locations() |
|
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
|
83 | .map(|ฮถ| ฯ0.apply(ฮถ) - ฯv.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
|
84 | .map(F::to_nalgebra_mixed), |
|
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 | ); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | let mut x = ฮผ.masses_dvector(); |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | // The gradient of the forward component of the inner objective is C^*๐Cx - gฬ. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | // We have |C^*๐Cx|_2 = sup_{|z|_2 โค 1} โจz, C^*๐Cxโฉ = sup_{|z|_2 โค 1} โจCz|๐Cxโฉ |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
90 | // โค sup_{|z|_2 โค 1} |Cz|_โณ |๐Cx|_โ โค sup_{|z|_2 โค 1} |Cz|_โณ |๐| |Cx|_โณ |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
91 | // โค sup_{|z|_2 โค 1} |z|_1 |๐| |x|_1 โค sup_{|z|_2 โค 1} n |z|_2 |๐| |x|_2 |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
92 | // = n |๐| |x|_2, where n is the number of points. Therefore |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
93 | let Aฬ_normest = op๐norm * F::cast_from(ฮผ.len()); |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
94 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
95 | // Solve finite-dimensional subproblem. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
96 | stats.inner_iters += reg.solve_findim(&Aฬ, &gฬ, ฯ, &mut x, Aฬ_normest, ฮต, config); |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | // Update masses of ฮผ based on solution of finite-dimensional subproblem. |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | ฮผ.set_masses_dvector(&x); |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | } |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | // Form d = ฯv + ๐ฮผ - ฯ0 = ฯv + ๐(ฮผ - ฮผ^k) for checking the proximate optimality |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
103 | // conditions in the predual space, and finding new points for insertion, if necessary. |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
104 | let mut d = &*ฯv + self.preapply(ฮผ.sub_matching(&ฮผ_base)); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
105 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
106 | // If no merging heuristic is used, let's be more conservative about spike insertion, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
107 | // and skip it after first round. If merging is done, being more greedy about spike |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
108 | // insertion also seems to improve performance. |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
109 | let skip_by_rough_check = if config.merging.enabled { |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
110 | false |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
111 | } else { |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
112 | count > 0 |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
113 | }; |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
114 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
115 | // Find a spike to insert, if needed |
|
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
|
116 | let (ฮพ, _v_ฮพ, in_bounds) = |
|
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
|
117 | match reg.find_tolerance_violation(&mut d, ฯ, ฮต, skip_by_rough_check, config) { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
118 | None => break 'insertion true, |
|
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
|
119 | Some(res) => res, |
|
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
|
120 | }; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
121 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
122 | // Break if maximum insertion count reached |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
123 | if count >= max_insertions { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
124 | break 'insertion in_bounds; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
125 | } |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
126 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
127 | // 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
|
128 | *ฮผ += DeltaMeasure { x: ฮพ, ฮฑ: 0.0 }; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
129 | count += 1; |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
130 | }; |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
131 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
132 | if !within_tolerances && warn_insertions { |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
133 | // Complain (but continue) if we failed to get within tolerances |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
134 | // by inserting more points. |
|
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
|
135 | let err = format!( |
|
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 | "Maximum insertions reached without achieving \ |
|
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 | subproblem solution tolerance" |
|
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 | ); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
139 | println!("{}", err.red()); |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
140 | } |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
141 | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
142 | Ok(within_tolerances) |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
143 | } |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
144 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
145 | fn reweigh<I>( |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
146 | &self, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
147 | ฮผ: &mut DiscreteMeasure<Domain, F>, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
148 | ฯv: &mut M, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
149 | ฯ: F, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
150 | ฮต: F, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
151 | config: &InsertionConfig<F>, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
152 | reg: &Reg, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
153 | _state: &AlgIteratorIteration<I>, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
154 | stats: &mut IterInfo<F>, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
155 | ) -> DynResult<()> |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
156 | where |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
157 | I: AlgIterator, |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
158 | { |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
159 | if ฮผ.len() > 0 { |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
160 | let op๐norm = self.opnorm_bound(Radon, Linfinity)?; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
161 | let ฯ0 = self.apply(&*ฮผ); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
162 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
163 | // Form finite-dimensional subproblem. The subproblem references to the original ฮผ^k |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
164 | // from the beginning of the iteration are all contained in the immutable c and g. |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
165 | // TODO: observe negation of -ฯv after switch from minus_ฯv: finite-dimensional |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
166 | // problems have not yet been updated to sign change. |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
167 | let Aฬ = self.findim_matrix(ฮผ.iter_locations()); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
168 | let gฬ = DVector::from_iterator( |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
169 | ฮผ.len(), |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
170 | ฮผ.iter_locations() |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
171 | .map(|ฮถ| ฯ0.apply(ฮถ) - ฯv.apply(ฮถ)) |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
172 | .map(F::to_nalgebra_mixed), |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
173 | ); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
174 | let mut x = ฮผ.masses_dvector(); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
175 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
176 | // The gradient of the forward component of the inner objective is C^*๐Cx - gฬ. |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
177 | // We have |C^*๐Cx|_2 = sup_{|z|_2 โค 1} โจz, C^*๐Cxโฉ = sup_{|z|_2 โค 1} โจCz|๐Cxโฉ |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
178 | // โค sup_{|z|_2 โค 1} |Cz|_โณ |๐Cx|_โ โค sup_{|z|_2 โค 1} |Cz|_โณ |๐| |Cx|_โณ |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
179 | // โค sup_{|z|_2 โค 1} |z|_1 |๐| |x|_1 โค sup_{|z|_2 โค 1} n |z|_2 |๐| |x|_2 |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
180 | // = n |๐| |x|_2, where n is the number of points. Therefore |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
181 | let Aฬ_normest = op๐norm * F::cast_from(ฮผ.len()); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
182 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
183 | // Solve finite-dimensional subproblem. |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
184 | stats.inner_iters += reg.solve_findim(&Aฬ, &gฬ, ฯ, &mut x, Aฬ_normest, ฮต, config); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
185 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
186 | // Update masses of ฮผ based on solution of finite-dimensional subproblem. |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
187 | ฮผ.set_masses_dvector(&x); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
188 | } |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
189 | |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
190 | Ok(()) |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
191 | } |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
192 | |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
193 | fn merge_spikes( |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
194 | &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
|
195 | ฮผ: &mut 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
|
196 | ฯv: &mut M, |
|
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 | ฮผ_base: &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
|
198 | ฯ: 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
|
199 | ฮต: 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
|
200 | config: &InsertionConfig<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
|
201 | 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
|
202 | fitness: Option<impl Fn(&DiscreteMeasure<Domain, F>) -> 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
|
203 | ) -> usize { |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
204 | if config.fitness_merging { |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
205 | if let Some(f) = fitness { |
|
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
|
206 | return ฮผ.merge_spikes_fitness(config.merging, f, |&v| v).1; |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
207 | } |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
208 | } |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
209 | ฮผ.merge_spikes(config.merging, |ฮผ_candidate| { |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
210 | let mut d = &*ฯv + self.preapply(ฮผ_candidate.sub_matching(ฮผ_base)); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
211 | reg.verify_merge_candidate(&mut d, ฮผ_candidate, ฯ, ฮต, config) |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
212 | }) |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
213 | } |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
214 | } |
|
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
|
215 | |
|
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
|
216 | #[replace_float_literals(F::cast_from(literal))] |
|
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
|
217 | impl<'a, F, A, ๐, Domain> StepLengthBound<F, QuadraticDataTerm<F, DiscreteMeasure<Domain, F>, 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
|
218 | for ๐ |
|
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
|
219 | 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
|
220 | Domain: Space + Clone + PartialEq + 'static, |
|
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
|
221 | 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
|
222 | ๐: DiscreteMeasureOp<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
|
223 | A: ForwardModel<DiscreteMeasure<Domain, F>, 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
|
224 | + for<'b> BoundedLinear<DiscreteMeasure<Domain, F>, &'b ๐, L2, 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
|
225 | DiscreteMeasure<Domain, F>: for<'b> Norm<&'b ๐, 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
|
226 | for<'b> &'b ๐: NormExponent, |
|
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
|
227 | { |
|
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 | fn step_length_bound( |
|
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
|
229 | &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
|
230 | f: &QuadraticDataTerm<F, DiscreteMeasure<Domain, F>, 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
|
231 | ) -> DynResult<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
|
232 | // TODO: direct squared calculation |
|
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
|
233 | Ok(f.operator().opnorm_bound(self, 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
|
234 | } |
|
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 | } |
|
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 | |
|
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 | #[replace_float_literals(F::cast_from(literal))] |
|
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
|
238 | impl<F, A, ๐, Domain> StepLengthBoundPD<F, A, DiscreteMeasure<Domain, F>> for ๐ |
|
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
|
239 | 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
|
240 | Domain: Space + Clone + PartialEq + 'static, |
|
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
|
241 | 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
|
242 | ๐: DiscreteMeasureOp<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
|
243 | A: for<'a> BoundedLinear<DiscreteMeasure<Domain, F>, &'a ๐, L2, 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
|
244 | DiscreteMeasure<Domain, F>: for<'a> Norm<&'a ๐, 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
|
245 | for<'b> &'b ๐: NormExponent, |
|
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
|
246 | { |
|
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
|
247 | fn step_length_bound_pd(&self, opA: &A) -> DynResult<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
|
248 | opA.opnorm_bound(self, L2) |
|
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
|
249 | } |
|
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
|
250 | } |