Thu, 26 Feb 2026 13:05:07 -0500
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
| 0 | 1 | //! Tolerance update schemes for subproblem solution quality |
|
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:
0
diff
changeset
|
2 | use crate::types::*; |
| 0 | 3 | 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:
0
diff
changeset
|
4 | use serde::{Deserialize, Serialize}; |
| 0 | 5 | |
| 6 | /// Update style for optimality system solution tolerance | |
| 7 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
| 8 | #[allow(dead_code)] | |
|
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:
0
diff
changeset
|
9 | pub enum Tolerance<F: Float> { |
| 0 | 10 | /// $ε_k = εθ^k$ for the `factor` $θ$ and initial 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:
0
diff
changeset
|
11 | Exponential { factor: F, initial: F }, |
| 0 | 12 | /// $ε_k = ε/(1+θk)^p$ for the `factor` $θ$, `exponent` $p$, and initial 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:
0
diff
changeset
|
13 | Power { factor: F, exponent: F, initial: F }, |
| 0 | 14 | /// $ε_k = εθ^{⌊k^p⌋}$ for the `factor` $θ$, initial tolerance $ε$, and exponent $p$. |
|
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:
0
diff
changeset
|
15 | SlowExp { factor: F, exponent: F, initial: F }, |
| 0 | 16 | } |
| 17 | ||
| 18 | #[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:
0
diff
changeset
|
19 | impl<F: Float> Default for Tolerance<F> { |
| 0 | 20 | fn default() -> Self { |
| 21 | Tolerance::Power { | |
|
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:
0
diff
changeset
|
22 | initial: 0.5, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
23 | factor: 0.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:
0
diff
changeset
|
24 | exponent: 1.4, // 1.5 works but is already slower in practise on our examples. |
| 0 | 25 | } |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | #[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:
0
diff
changeset
|
30 | impl<F: Float> Tolerance<F> { |
| 0 | 31 | /// Get the initial tolerance |
| 32 | pub fn initial(&self) -> F { | |
| 33 | match self { | |
| 34 | &Tolerance::Exponential { initial, .. } => initial, | |
| 35 | &Tolerance::Power { initial, .. } => initial, | |
| 36 | &Tolerance::SlowExp { initial, .. } => initial, | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | /// Get mutable reference to the initial tolerance | |
| 41 | fn initial_mut(&mut self) -> &mut F { | |
| 42 | match self { | |
| 43 | Tolerance::Exponential { ref mut initial, .. } => initial, | |
| 44 | Tolerance::Power { ref mut initial, .. } => initial, | |
| 45 | Tolerance::SlowExp { ref mut initial, .. } => initial, | |
| 46 | } | |
| 47 | } | |
| 48 | ||
| 49 | /// Set the initial 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:
0
diff
changeset
|
50 | pub fn set_initial(&mut self, set: F) { |
| 0 | 51 | *self.initial_mut() = set; |
| 52 | } | |
| 53 | ||
| 54 | /// Update `tolerance` for iteration `iter`. | |
| 55 | /// `tolerance` may or may not be used depending on the specific | |
| 56 | /// update scheme. | |
|
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:
0
diff
changeset
|
57 | pub fn update(&self, tolerance: F, iter: usize) -> F { |
| 0 | 58 | match 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:
0
diff
changeset
|
59 | &Tolerance::Exponential { factor, .. } => tolerance * factor, |
| 0 | 60 | &Tolerance::Power { factor, exponent, 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:
0
diff
changeset
|
61 | initial / (1.0 + factor * F::cast_from(iter)).powf(exponent) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
62 | } |
| 0 | 63 | &Tolerance::SlowExp { factor, exponent, initial } => { |
| 64 | // let m = (speed | |
| 65 | // * factor.powi(-(iter as i32)) | |
| 66 | // * F::cast_from(iter).powf(-exponent) | |
| 67 | // ).floor().as_(); | |
| 68 | let m = F::cast_from(iter).powf(exponent).floor().as_(); | |
| 69 | initial * factor.powi(m) | |
|
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:
0
diff
changeset
|
70 | } |
| 0 | 71 | } |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | impl<F: Float> std::ops::MulAssign<F> for Tolerance<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:
0
diff
changeset
|
76 | fn mul_assign(&mut self, factor: F) { |
| 0 | 77 | *self.initial_mut() *= factor; |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | impl<F: Float> std::ops::Mul<F> for Tolerance<F> { | |
| 82 | type Output = Tolerance<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:
0
diff
changeset
|
83 | fn mul(mut self, factor: F) -> Self::Output { |
| 0 | 84 | *self.initial_mut() *= factor; |
| 85 | self | |
| 86 | } | |
| 87 | } |