pub struct Cholesky<T: Real = f64, K: DenseKernel<T> = NaiveDense> {
r: DenseBlock<T>,
kernel: K,
opts: CholOptions,
}Expand description
The upper Cholesky factor R of a symmetric positive definite A = RᵀR, kept up to date under A ← A ± x xᵀ (Chapter 12.2: Algorithms
F, U, C).
use xingo_statla::{CholOptions, Cholesky, MatRef};
// A = [[4, 2], [2, 3]] (upper triangle read).
let a = [4.0, 0.0, 2.0, 3.0];
let mut c = Cholesky::factor(MatRef::new(2, 2, 2, &a)?, &CholOptions::default())?;
c.update(&[1.0, 1.0])?; // A + x xᵀ = [[5, 3], [3, 4]]
let info = c.downdate(&[1.0, 1.0])?; // back to A
assert!(info.margin > 0.0 && info.margin <= 1.0);
let mut b = [6.0, 5.0]; // A · (1, 1)
c.solve(&mut b)?;
assert!((b[0] - 1.0).abs() < 1e-14 && (b[1] - 1.0).abs() < 1e-14);
assert!(c.downdate(&[3.0, 0.0]).is_err()); // A − 9 e₀e₀ᵀ is indefiniteFields§
§r: DenseBlock<T>§kernel: K§opts: CholOptionsImplementations§
Source§impl<T: Real> Cholesky<T, NaiveDense>
impl<T: Real> Cholesky<T, NaiveDense>
Sourcepub fn factor(a: MatRef<'_, T>, opts: &CholOptions) -> Result<Self, StatlaError>
pub fn factor(a: MatRef<'_, T>, opts: &CholOptions) -> Result<Self, StatlaError>
Factor the symmetric positive definite A (upper triangle read)
with the reference kernel.
§Errors
StatlaError::InvalidArgument (not square, invalid options),
StatlaError::NonFinite, StatlaError::NotPositiveDefinite.
Source§impl<T: Real, K: DenseKernel<T>> Cholesky<T, K>
impl<T: Real, K: DenseKernel<T>> Cholesky<T, K>
Sourcepub fn factor_with(
a: MatRef<'_, T>,
kernel: K,
opts: &CholOptions,
) -> Result<Self, StatlaError>
pub fn factor_with( a: MatRef<'_, T>, kernel: K, opts: &CholOptions, ) -> Result<Self, StatlaError>
Sourcepub fn from_upper(
r: DenseBlock<T>,
kernel: K,
opts: &CholOptions,
) -> Result<Self, StatlaError>
pub fn from_upper( r: DenseBlock<T>, kernel: K, opts: &CholOptions, ) -> Result<Self, StatlaError>
Adopt an existing upper factor (for instance the R of a
crate::Qr: the Q-less QR of streaming regression is this type).
§Errors
StatlaError::InvalidArgument if r is not square upper
triangular with positive diagonal (or the options are invalid);
StatlaError::NonFinite.
Sourcepub fn into_upper(self) -> DenseBlock<T>
pub fn into_upper(self) -> DenseBlock<T>
R, owned.
Sourcepub fn update(&mut self, x: &[T]) -> Result<(), StatlaError>
pub fn update(&mut self, x: &[T]) -> Result<(), StatlaError>
A ← A + x xᵀ (Algorithm U).
§Errors
StatlaError::Dimension, StatlaError::NonFinite; the factor
is unchanged on error (H3).
Sourcepub fn downdate(&mut self, x: &[T]) -> Result<DowndateInfo, StatlaError>
pub fn downdate(&mut self, x: &[T]) -> Result<DowndateInfo, StatlaError>
A ← A − x xᵀ (Algorithm C).
§Errors
StatlaError::Dimension, StatlaError::NonFinite,
StatlaError::DowndateIndefinite; unchanged on error (H3).
Sourcepub fn solve_block(&self, b: MatMut<'_, T>) -> Result<(), StatlaError>
pub fn solve_block(&self, b: MatMut<'_, T>) -> Result<(), StatlaError>
Sourcepub fn solve_upper_t(&self, b: &mut [T]) -> Result<(), StatlaError>
pub fn solve_upper_t(&self, b: &mut [T]) -> Result<(), StatlaError>
Sourcepub fn log2_det_parts(&self) -> (T, i64)
pub fn log2_det_parts(&self) -> (T, i64)
ln det A = 2 Σ ln r_jj, returned as (m, e) with det R = Π r_jj = m · 2^e exactly split, m ∈ [1, 2) ((1, 0) for n = 0): no ln
in Real, so the caller forms ln det A = 2 (ln m + e ln 2) in
its own precision (log₂ det R = log₂ m + e).