Struct rstats::TriangMat

source ·
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

Implementation of associated functions for struct TriangleMat. End type is f64, as triangular matrices will be mostly computed

source

pub fn len(&self) -> usize

Length of the data vec

source

pub fn dim(&self) -> usize

Dimension of the implied full (square) matrix from the quadratic equation: n^2 + n - 2l = 0

source

pub fn is_empty(&self) -> bool

Empty TriangMat test

source

pub fn magsq(&self) -> f64

Squared euclidian vector magnitude (norm) of the data vector

source

pub fn sum(&self) -> f64

Sum of the elements:
when applied to the wedge product a∧b, returns det(a,b)

source

pub fn diagonal(&self) -> Vec<f64>

Diagonal elements

source

pub fn unit(n: usize) -> Self

New unit (symmetric) TriangMat matrix with total data size n*(n+1)/2

source

pub fn eigenvalues(&self) -> Vec<f64>

Eigenvalues from Cholesky L matrix

source

pub fn determinant(&self) -> f64

Determinant from Cholesky L matrix

source

pub fn eigenvectors(&self) -> Vec<Vec<f64>>

Normalized full eigenvectors from triangular covariance matrix. Can be used together with eigenvalues for Principal Components Analysis.
Covariance matrix is symmetric, so we use its rows as eigenvectors (no need to transpose it)

source

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.

source

pub fn project(&self, index: &[usize]) -> Self

Project symmetric/antisymmetric triangmat to a smaller one of the same kind, into a subspace specified by an ascending index of dimensions. Deletes all rows and columns of the missing dimensions.

source

pub fn row(&self, r: usize) -> Vec<f64>

Extract one row from TriangMat

source

pub fn to_triangle(&self) -> Vec<Vec<f64>>

Unpacks flat TriangMat Vec to triangular Vec form

source

pub fn transpose(&mut self)

TriangMat trivial implicit transposition

source

pub fn to_full(&self) -> Vec<Vec<f64>>

Unpacks TriangMat to ordinary full matrix

source

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.

source

pub fn mahalanobis<U>(&self, d: &[U]) -> Result<f64, RE>
where U: Copy + PartialOrd + Display, f64: From<U>,

Mahalanobis scaled magnitude m(d) of a (column) vector d. Self is the decomposed lower triangular matrix L, as returned by cholesky decomposition of covariance/comediance positive definite matrix: C = LL’, where ’ denotes transpose. Mahalanobis distance is defined as:
m(d) = sqrt(d'inv(C)d) = sqrt(d'inv(LL')d) = sqrt(d'inv(L')inv(L)d), where inv() denotes matrix inverse, which is not explicitly computed.
Let x = inv(L)d ( and therefore also x' = d'inv(L') ). Substituting x into the above definition: `m(d) = sqrt(x’x) = |x|.
We obtain x by setting Lx = d and solving by forward substitution. All the calculations are done in the compact triangular form.

source

pub fn house_uapply<T>(&self, m: &[Vec<T>]) -> Vec<Vec<f64>>
where T: Copy + PartialOrd + Display, f64: From<T>,

Householder’s Q*M matrix product without explicitly computing Q

Trait Implementations§

source§

impl Clone for TriangMat

source§

fn clone(&self) -> TriangMat

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for TriangMat

source§

fn default() -> TriangMat

Returns the “default value” for a type. Read more
source§

impl Display for TriangMat

Display implementation for TriangMat

source§

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

Formats the value using the given formatter. Read more

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Printing<T> for T
where T: Display,

source§

fn to_str(self) -> String

Method to serialize. Decorates Vecs with square brackets and tuples with round ones. Implementation code is in printing.rs.
source§

fn to_plainstr(self) -> String

Method to serialize in minimal form (space separated, no brackets) Implementation code is in printing.rs.
source§

fn rd(self) -> String

Printable in red
source§

fn gr(self) -> String

Printable in green
source§

fn bl(self) -> String

Printable in blue
source§

fn yl(self) -> String

Printable in yellow
source§

fn mg(self) -> String

Printable in magenta
source§

fn cy(self) -> String

Printable in cyan
source§

fn wvec(self, f: &mut File) -> Result<(), Error>

Method to write vector(s) to file f (space separated, without brackets). Passes up io errors
source§

fn pvec(self)

Method to print vector(s) to stdout (space separated,without brackets).
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.