pub struct LinearSolveStep { /* private fields */ }Expand description
One residual-projection conditioning step.
Implementations§
Source§impl LinearSolveStep
impl LinearSolveStep
Sourcepub const fn residual_norm_before(&self) -> f64
pub const fn residual_norm_before(&self) -> f64
Residual norm ||b - A m|| of the belief mean before this projection.
Examples found in repository?
examples/probabilistic_linear_solver.rs (line 30)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // A x = b with A symmetric positive definite, stored row-major.
12 let system = SpdLinearSystem::new(
13 &[4.0, 1.0, 0.0, 1.0, 3.0, 1.0, 0.0, 1.0, 2.0],
14 &[1.0, 2.0, 3.0],
15 3,
16 )?;
17 // Prior belief x ~ N(0, I).
18 let identity = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
19 let prior = GaussianLinearBelief::new(&[0.0; 3], &identity, 3)?;
20
21 // Residual-driven policy: each step observes the projection along the normalized residual.
22 let solver = ResidualProjectionSolver::new(1.0e-10, 0.0, 3)?;
23 let result = solver.solve(&system, &prior)?;
24 println!("residual policy");
25 println!(" mean = {:?}", result.belief().mean());
26 println!(" stopped because = {:?}", result.termination());
27 for (index, step) in result.steps().iter().enumerate() {
28 println!(
29 " step {index}: residual {:.3e} -> {:.3e}, covariance trace {:.3e}",
30 step.residual_norm_before(),
31 step.residual_norm_after(),
32 step.covariance_trace_after(),
33 );
34 }
35
36 // A-conjugate policy: the same information subspace in an A-orthogonal basis.
37 let conjugate = AConjugateProjectionSolver::new(1.0e-10, 0.0, 3)?;
38 let result = conjugate.solve(&system, &prior)?;
39 println!("A-conjugate policy");
40 println!(" mean = {:?}", result.belief().mean());
41 println!(" stopped because = {:?}", result.termination());
42
43 // Covariance-greedy policy: directions are chosen without looking at b, so the
44 // posterior covariance keeps its calibrated interpretation under the assumed prior.
45 let candidates: Vec<Vec<f64>> = (0..3)
46 .map(|axis| {
47 let mut direction = vec![0.0; 3];
48 direction[axis] = 1.0;
49 direction
50 })
51 .collect();
52 let greedy = CovarianceGreedyProjectionSolver::new(0.0, 2)?;
53 let result = greedy.solve(&system, &prior, &candidates)?;
54 println!("covariance-greedy policy (budget of two projections)");
55 println!(" mean = {:?}", result.belief().mean());
56 println!(" stopped because = {:?}", result.termination());
57 for (index, step) in result.steps().iter().enumerate() {
58 println!(
59 " step {index}: direction {:?}, predicted trace reduction {:.3e}, posterior trace {:.3e}",
60 step.direction(),
61 step.predicted_trace_reduction(),
62 step.posterior_trace(),
63 );
64 }
65 Ok(())
66}Sourcepub const fn residual_norm_after(&self) -> f64
pub const fn residual_norm_after(&self) -> f64
Residual norm of the updated belief mean after this projection.
Examples found in repository?
examples/probabilistic_linear_solver.rs (line 31)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // A x = b with A symmetric positive definite, stored row-major.
12 let system = SpdLinearSystem::new(
13 &[4.0, 1.0, 0.0, 1.0, 3.0, 1.0, 0.0, 1.0, 2.0],
14 &[1.0, 2.0, 3.0],
15 3,
16 )?;
17 // Prior belief x ~ N(0, I).
18 let identity = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
19 let prior = GaussianLinearBelief::new(&[0.0; 3], &identity, 3)?;
20
21 // Residual-driven policy: each step observes the projection along the normalized residual.
22 let solver = ResidualProjectionSolver::new(1.0e-10, 0.0, 3)?;
23 let result = solver.solve(&system, &prior)?;
24 println!("residual policy");
25 println!(" mean = {:?}", result.belief().mean());
26 println!(" stopped because = {:?}", result.termination());
27 for (index, step) in result.steps().iter().enumerate() {
28 println!(
29 " step {index}: residual {:.3e} -> {:.3e}, covariance trace {:.3e}",
30 step.residual_norm_before(),
31 step.residual_norm_after(),
32 step.covariance_trace_after(),
33 );
34 }
35
36 // A-conjugate policy: the same information subspace in an A-orthogonal basis.
37 let conjugate = AConjugateProjectionSolver::new(1.0e-10, 0.0, 3)?;
38 let result = conjugate.solve(&system, &prior)?;
39 println!("A-conjugate policy");
40 println!(" mean = {:?}", result.belief().mean());
41 println!(" stopped because = {:?}", result.termination());
42
43 // Covariance-greedy policy: directions are chosen without looking at b, so the
44 // posterior covariance keeps its calibrated interpretation under the assumed prior.
45 let candidates: Vec<Vec<f64>> = (0..3)
46 .map(|axis| {
47 let mut direction = vec![0.0; 3];
48 direction[axis] = 1.0;
49 direction
50 })
51 .collect();
52 let greedy = CovarianceGreedyProjectionSolver::new(0.0, 2)?;
53 let result = greedy.solve(&system, &prior, &candidates)?;
54 println!("covariance-greedy policy (budget of two projections)");
55 println!(" mean = {:?}", result.belief().mean());
56 println!(" stopped because = {:?}", result.termination());
57 for (index, step) in result.steps().iter().enumerate() {
58 println!(
59 " step {index}: direction {:?}, predicted trace reduction {:.3e}, posterior trace {:.3e}",
60 step.direction(),
61 step.predicted_trace_reduction(),
62 step.posterior_trace(),
63 );
64 }
65 Ok(())
66}Sourcepub const fn covariance_trace_after(&self) -> f64
pub const fn covariance_trace_after(&self) -> f64
Trace of the posterior covariance after this projection.
Examples found in repository?
examples/probabilistic_linear_solver.rs (line 32)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // A x = b with A symmetric positive definite, stored row-major.
12 let system = SpdLinearSystem::new(
13 &[4.0, 1.0, 0.0, 1.0, 3.0, 1.0, 0.0, 1.0, 2.0],
14 &[1.0, 2.0, 3.0],
15 3,
16 )?;
17 // Prior belief x ~ N(0, I).
18 let identity = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
19 let prior = GaussianLinearBelief::new(&[0.0; 3], &identity, 3)?;
20
21 // Residual-driven policy: each step observes the projection along the normalized residual.
22 let solver = ResidualProjectionSolver::new(1.0e-10, 0.0, 3)?;
23 let result = solver.solve(&system, &prior)?;
24 println!("residual policy");
25 println!(" mean = {:?}", result.belief().mean());
26 println!(" stopped because = {:?}", result.termination());
27 for (index, step) in result.steps().iter().enumerate() {
28 println!(
29 " step {index}: residual {:.3e} -> {:.3e}, covariance trace {:.3e}",
30 step.residual_norm_before(),
31 step.residual_norm_after(),
32 step.covariance_trace_after(),
33 );
34 }
35
36 // A-conjugate policy: the same information subspace in an A-orthogonal basis.
37 let conjugate = AConjugateProjectionSolver::new(1.0e-10, 0.0, 3)?;
38 let result = conjugate.solve(&system, &prior)?;
39 println!("A-conjugate policy");
40 println!(" mean = {:?}", result.belief().mean());
41 println!(" stopped because = {:?}", result.termination());
42
43 // Covariance-greedy policy: directions are chosen without looking at b, so the
44 // posterior covariance keeps its calibrated interpretation under the assumed prior.
45 let candidates: Vec<Vec<f64>> = (0..3)
46 .map(|axis| {
47 let mut direction = vec![0.0; 3];
48 direction[axis] = 1.0;
49 direction
50 })
51 .collect();
52 let greedy = CovarianceGreedyProjectionSolver::new(0.0, 2)?;
53 let result = greedy.solve(&system, &prior, &candidates)?;
54 println!("covariance-greedy policy (budget of two projections)");
55 println!(" mean = {:?}", result.belief().mean());
56 println!(" stopped because = {:?}", result.termination());
57 for (index, step) in result.steps().iter().enumerate() {
58 println!(
59 " step {index}: direction {:?}, predicted trace reduction {:.3e}, posterior trace {:.3e}",
60 step.direction(),
61 step.predicted_trace_reduction(),
62 step.posterior_trace(),
63 );
64 }
65 Ok(())
66}Sourcepub fn search_direction(&self) -> &[f64]
pub fn search_direction(&self) -> &[f64]
Unit search direction s defining the projection s^T A x = s^T b.
Trait Implementations§
Source§impl Clone for LinearSolveStep
impl Clone for LinearSolveStep
Source§fn clone(&self) -> LinearSolveStep
fn clone(&self) -> LinearSolveStep
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LinearSolveStep
impl Debug for LinearSolveStep
Source§impl PartialEq for LinearSolveStep
impl PartialEq for LinearSolveStep
impl StructuralPartialEq for LinearSolveStep
Auto Trait Implementations§
impl Freeze for LinearSolveStep
impl RefUnwindSafe for LinearSolveStep
impl Send for LinearSolveStep
impl Sync for LinearSolveStep
impl Unpin for LinearSolveStep
impl UnsafeUnpin for LinearSolveStep
impl UnwindSafe for LinearSolveStep
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.