pub struct LDLTMgr {
pub pos: (usize, usize),
pub wit: Array1<f64>,
pub ndim: usize,
pub storage: Array2<f64>,
}
Expand description
The LDLTMgr
struct is a manager for LDLTMgr factorization in Rust.
LDLTMgr
is a class that performs the LDLTMgr factorization for a given
symmetric matrix. The LDLTMgr factorization decomposes a symmetric matrix A into
the product of a lower triangular matrix L, a diagonal matrix D, and the
transpose of L. This factorization is useful for solving linear systems and
eigenvalue problems. The class provides methods to perform the factorization,
check if the matrix is positive definite, calculate a witness vector if it is
not positive definite, and calculate the symmetric quadratic form.
- LDL^T square-root-free version
- Option allow semidefinite
- A matrix A in R^{m x m} is positive definite iff v’ A v > 0 for all v in R^n.
- O(p^2) per iteration, independent of N
Properties:
pos
: A tuple containing two usize values. It represents the dimensions of the LDLTMgr factorization.wit
: Thewit
property is an Array1 of f64 values.ndim
: Thendim
property represents the size of the matrix that will be factorized using LDLTMgr factorization.storage
: Thestorage
property is a 2-dimensional array of typef64
. It is used to store the LDLTMgr factorization of a matrix.
Fields§
§pos: (usize, usize)
§wit: Array1<f64>
§ndim: usize
§storage: Array2<f64>
Implementations§
Source§impl LDLTMgr
impl LDLTMgr
Sourcepub fn new(ndim: usize) -> Self
pub fn new(ndim: usize) -> Self
The function new
initializes a struct with default values for its fields.
Arguments:
ndim
: The parameterndim
represents the size of the arrays and matrices being initialized in thenew
function. It is of typeusize
, which means it represents a non-negative integer.
Returns:
The new
function is returning an instance of the struct that it is defined in.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::{array, Array1};
let ldlt_mgr = LDLTMgr::new(3);
assert_eq!(ldlt_mgr.pos, (0, 0));
assert_eq!(ldlt_mgr.wit.len(), 3);
assert_eq!(ldlt_mgr.ndim, 3);
assert_eq!(ldlt_mgr.storage.len(), 9);
Sourcepub fn factorize(&mut self, mat_a: &Array2<f64>) -> bool
pub fn factorize(&mut self, mat_a: &Array2<f64>) -> bool
The factorize
function takes a 2D array of f64 values and factors it using a closure.
Arguments:
mat_a
: The parametermat_a
is a reference to a 2-dimensional array (Array2
) off64
values.
Returns:
The factorize
function returns a boolean value.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factorize(&mat_a), false);
Sourcepub fn factor<F>(&mut self, get_elem: F) -> bool
pub fn factor<F>(&mut self, get_elem: F) -> bool
The factor
function performs LDLTMgr factorization on a matrix and checks if it is symmetric
positive definite.
Arguments:
get_elem
:get_elem
is a closure that takes twousize
parameters (i
andj
) and returns af64
value. It is used to retrieve elements from a matrix-like data structure.
Returns:
The factor
function returns a boolean value.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
Sourcepub fn factor_with_allow_semidefinite<F>(&mut self, get_elem: F) -> bool
pub fn factor_with_allow_semidefinite<F>(&mut self, get_elem: F) -> bool
The function factor_with_allow_semidefinite
checks if a given matrix is symmetric positive
definite (SPD) or semidefinite.
Arguments:
get_elem
:get_elem
is a closure that takes twousize
parametersi
andstart
and returns af64
value.
Returns:
a boolean value.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor_with_allow_semidefinite(&|i, j| mat_a[[i, j]]), true);
Sourcepub fn is_spd(&self) -> bool
pub fn is_spd(&self) -> bool
The function is_spd
checks if the second element of the tuple pos
is equal to 0.
Returns:
A boolean value is being returned.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.is_spd(), false);
Sourcepub fn witness(&mut self) -> f64
pub fn witness(&mut self) -> f64
The function calculates the witness vector of a matrix.
Returns:
The function witness
returns a f64
(a 64-bit floating-point number).
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.witness(), 0.0);
assert_eq!(ldlt_mgr.wit[0], -2.0);
assert_eq!(ldlt_mgr.wit[1], 1.0);
assert_eq!(ldlt_mgr.pos.1, 2);
Sourcepub fn sym_quad(&self, mat_a: &Array2<f64>) -> f64
pub fn sym_quad(&self, mat_a: &Array2<f64>) -> f64
The sym_quad
function calculates the quadratic form of a symmetric matrix and a vector.
Arguments:
mat_a
: A 2-dimensional array of type f64.
Returns:
The function sym_quad
returns a f64
value.
§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
[1.0, 2.0, 3.0],
[2.0, 4.0, 5.0],
[3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.witness(), 0.0);
let mat_b = array![
[1.0, 2.0, 3.0],
[2.0, 6.0, 5.0],
[3.0, 5.0, 4.0],
];
assert_eq!(ldlt_mgr.sym_quad(&mat_b), 2.0);