pub struct TriangMat {
pub kind: usize,
pub data: Vec<f64>,
}
Expand description
Compact Triangular Matrix.
TriangMat stores and manipulates triangular matrices.
It also compactly represents square symmetric and antisymmetric matrices.
TriangMat is typically produced by some matrix calculations,
so the end-type for its data is f64.
The actual length of its data is triangmat.len() = n*(n+1)/2
.
The dimension of the implied nxn matrix is n = triangmat.dim()
.
The kind (field) of the TriangMat is encoded as 0..5. This enables
trivial transpositions by: (kind+3) % 6
.
Fields§
§kind: usize
Matrix kind encoding: 0=plain, 1=antisymmetric, 2=symmetric, +3=transposed
data: Vec<f64>
Packed 1d vector of triangular matrix data of size (n+1)*n/2
Implementations§
source§impl TriangMat
impl TriangMat
Implementation of associated functions for struct TriangleMat. End type is f64, as triangular matrices will be mostly computed
sourcepub fn dim(&self) -> usize
pub fn dim(&self) -> usize
Dimension of the implied full (square) matrix
from the quadratic equation: n^2 + n - 2l = 0
sourcepub fn sum(&self) -> f64
pub fn sum(&self) -> f64
Sum of the elements:
when applied to the wedge product a∧b, returns det(a,b)
sourcepub fn unit(n: usize) -> Self
pub fn unit(n: usize) -> Self
Generates new unit (symmetric) TriangMat matrix of size (n+1)*n/2
sourcepub fn eigenvalues(&self) -> Vec<f64>
pub fn eigenvalues(&self) -> Vec<f64>
Eigenvalues (obtainable only from Cholesky L matrix)
sourcepub fn determinant(&self) -> f64
pub fn determinant(&self) -> f64
Determinant (obtainable only from Cholesky L matrix)
sourcepub fn rowcol(s: usize) -> (usize, usize)
pub fn rowcol(s: usize) -> (usize, usize)
Translates subscripts to a 1d vector, i.e. natural numbers, to a pair of (row,column) coordinates within a lower/upper triangular matrix. Enables memory efficient representation of triangular matrices as one flat vector.
sourcepub fn to_triangle(&self) -> Vec<Vec<f64>>
pub fn to_triangle(&self) -> Vec<Vec<f64>>
Unpacks flat TriangMat Vec to triangular Vec
sourcepub fn cholesky(&self) -> Result<Self, RE>
pub fn cholesky(&self) -> Result<Self, RE>
Efficient Cholesky-Banachiewicz matrix decomposition into LL'
,
where L is the returned lower triangular matrix and L’ its upper triangular transpose.
Expects as input a symmetric positive definite matrix
in TriangMat compact form, such as a covariance matrix produced by covar
.
The computations are all done on the compact form,
making this implementation memory efficient for large (symmetric) matrices.
Reports errors if the above conditions are not satisfied.
sourcepub fn mahalanobis<U>(&self, d: &[U]) -> Result<f64, RE>
pub fn mahalanobis<U>(&self, d: &[U]) -> Result<f64, RE>
Mahalanobis scaled magnitude m(d) of a (column) vector d.
Self is a decomposed lower triangular matrix L, as returned by cholesky
from covariance/comediance positive definite matrix C = LL’.
m(d) = sqrt(d'inv(C)d) = sqrt(d'inv(LL')d) = sqrt(d'inv(L')inv(L)d)
,
where ’ denotes transpose and inv()
denotes inverse.
Putting Lx = d and solving for x by forward substitution, we obtain x = inv(L)d
substituting x into the above: `=> m(d) = sqrt(x’x) = |x|.
We stay in the compact triangular form all the way from C to m(d).
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for TriangMat
impl Send for TriangMat
impl Sync for TriangMat
impl Unpin for TriangMat
impl UnwindSafe for TriangMat
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
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Printing<T> for Twhere
T: Display,
impl<T> Printing<T> for Twhere
T: Display,
source§fn to_str(self) -> String
fn to_str(self) -> String
printing.rs
.source§fn to_plainstr(self) -> String
fn to_plainstr(self) -> String
printing.rs
.