Skip to main content

CovarianceGreedyProjectionSolver

Struct CovarianceGreedyProjectionSolver 

Source
pub struct CovarianceGreedyProjectionSolver { /* private fields */ }
Expand description

Sequential probabilistic linear solver with data-independent covariance-greedy directions.

Implementations§

Source§

impl CovarianceGreedyProjectionSolver

Source

pub fn new( covariance_trace_tolerance: f64, max_projections: usize, ) -> Result<Self, LinearSolverError>

Construct the solver with explicit uncertainty tolerance and projection budget.

§Errors

Returns LinearSolverError when the covariance-trace tolerance is invalid.

Examples found in repository?
examples/probabilistic_linear_solver.rs (line 52)
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}
Source

pub fn solve( &self, system: &SpdLinearSystem, initial_belief: &GaussianLinearBelief, candidates: &[Vec<f64>], ) -> Result<CovarianceGreedySolveResult, LinearSolverError>

Run covariance-greedy sequential conditioning from an initial Gaussian belief.

Direction selection and stopping depend only on A, the candidate set, the covariance state, and the configured budget/tolerance. They do not depend on the observed right-hand side.

§Errors

Returns LinearSolverError for incompatible dimensions or invalid candidates.

Examples found in repository?
examples/probabilistic_linear_solver.rs (line 53)
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}

Trait Implementations§

Source§

impl Clone for CovarianceGreedyProjectionSolver

Source§

fn clone(&self) -> CovarianceGreedyProjectionSolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CovarianceGreedyProjectionSolver

Source§

impl Debug for CovarianceGreedyProjectionSolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CovarianceGreedyProjectionSolver

Source§

fn eq(&self, other: &CovarianceGreedyProjectionSolver) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CovarianceGreedyProjectionSolver

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.