v2.0.0
Loading...
Searching...
No Matches
UTILSLIB::Linalg Class Reference

Static linear algebra utility functions. More...

#include <linalg.h>

Public Types

typedef std::pair< int, int > IdxIntValue

Public Member Functions

 ~Linalg ()=default

Static Public Member Functions

static Eigen::VectorXd combine_xyz (const Eigen::VectorXd &vec)
static double getConditionNumber (const Eigen::MatrixXd &A, Eigen::VectorXd &s)
static double getConditionSlope (const Eigen::MatrixXd &A, Eigen::VectorXd &s)
static void get_whitener (Eigen::MatrixXd &A, bool pca, QString ch_type, Eigen::VectorXd &eig, Eigen::MatrixXd &eigvec)
static void get_whitener (Eigen::MatrixXd &A, bool pca, const std::string &ch_type, Eigen::VectorXd &eig, Eigen::MatrixXd &eigvec)
static Eigen::VectorXi intersect (const Eigen::VectorXi &v1, const Eigen::VectorXi &v2, Eigen::VectorXi &idx_sel)
static Eigen::SparseMatrix< double > make_block_diag (const Eigen::MatrixXd &A, qint32 n)
template<typename T>
static Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > pinv (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a)
static qint32 rank (const Eigen::MatrixXd &A, double tol=1e-8)
template<typename T>
static Eigen::VectorXi sort (Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, bool desc=true)
template<typename T>
static Eigen::VectorXi sort (Eigen::Matrix< T, Eigen::Dynamic, 1 > &v_prime, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat, bool desc=true)
template<typename T>
static std::vector< Eigen::Triplet< T > > sortrows (const std::vector< Eigen::Triplet< T > > &A, qint32 column=0)
template<typename T>
static bool compareIdxValuePairBiggerThan (const std::pair< int, T > &lhs, const std::pair< int, T > &rhs)
template<typename T>
static bool compareIdxValuePairSmallerThan (const std::pair< int, T > &lhs, const std::pair< int, T > &rhs)
template<typename T>
static bool compareTripletFirstEntry (const Eigen::Triplet< T > &lhs, const Eigen::Triplet< T > &rhs)
template<typename T>
static bool compareTripletSecondEntry (const Eigen::Triplet< T > &lhs, const Eigen::Triplet< T > &rhs)

Detailed Description

Static linear algebra utility functions.

Linear algebra utility functions: decompositions, sorting, block-diagonal construction, etc.

Definition at line 74 of file linalg.h.

Member Typedef Documentation

◆ IdxIntValue

typedef std::pair<int,int> UTILSLIB::Linalg::IdxIntValue

Typedef of a pair of ints.

Definition at line 77 of file linalg.h.

Constructor & Destructor Documentation

◆ ~Linalg()

UTILSLIB::Linalg::~Linalg ( )
default

Destroys the Linalg object.

Member Function Documentation

◆ combine_xyz()

VectorXd Linalg::combine_xyz ( const Eigen::VectorXd & vec)
static

Compute the three Cartesian components of a vector together.

Parameters
[in]vecInput row vector [ x1 y1 z1 ... x_n y_n z_n ].
Returns
Output vector [x1^2+y1^2+z1^2 ... x_n^2+y_n^2+z_n^2 ].

Definition at line 64 of file linalg.cpp.

◆ compareIdxValuePairBiggerThan()

template<typename T>
bool UTILSLIB::Linalg::compareIdxValuePairBiggerThan ( const std::pair< int, T > & lhs,
const std::pair< int, T > & rhs )
inlinestatic

Compares two index-value-pairs (greater-than).

Definition at line 352 of file linalg.h.

◆ compareIdxValuePairSmallerThan()

template<typename T>
bool UTILSLIB::Linalg::compareIdxValuePairSmallerThan ( const std::pair< int, T > & lhs,
const std::pair< int, T > & rhs )
inlinestatic

Compares two index-value-pairs (less-than).

Definition at line 361 of file linalg.h.

◆ compareTripletFirstEntry()

template<typename T>
bool UTILSLIB::Linalg::compareTripletFirstEntry ( const Eigen::Triplet< T > & lhs,
const Eigen::Triplet< T > & rhs )
inlinestatic

Compares triplet first entry (row).

Definition at line 370 of file linalg.h.

◆ compareTripletSecondEntry()

template<typename T>
bool UTILSLIB::Linalg::compareTripletSecondEntry ( const Eigen::Triplet< T > & lhs,
const Eigen::Triplet< T > & rhs )
inlinestatic

Compares triplet second entry (column).

Definition at line 379 of file linalg.h.

◆ get_whitener() [1/2]

void UTILSLIB::Linalg::get_whitener ( Eigen::MatrixXd & A,
bool pca,
const std::string & ch_type,
Eigen::VectorXd & eig,
Eigen::MatrixXd & eigvec )
static

Returns the whitener of a given matrix.

Parameters
[in]AMatrix to compute the whitener from.
[in]pcaPerform a PCA.
[in]ch_typeChannel type string.
[out]eigEigenvalues.
[out]eigvecEigenvectors (transposed).

◆ get_whitener() [2/2]

void UTILSLIB::Linalg::get_whitener ( Eigen::MatrixXd & A,
bool pca,
QString ch_type,
Eigen::VectorXd & eig,
Eigen::MatrixXd & eigvec )
static

Returns the whitener of a given matrix.

Parameters
[in]AMatrix to compute the whitener from.
[in]pcaPerform a PCA.
[in]ch_typeChannel type string.
[out]eigEigenvalues.
[out]eigvecEigenvectors (transposed).

◆ getConditionNumber()

double Linalg::getConditionNumber ( const Eigen::MatrixXd & A,
Eigen::VectorXd & s )
static

Returns the condition number of a given matrix.

Parameters
[in]AMatrix to compute the condition number from.
[out]sSingular values of A.
Returns
the condition number.

Definition at line 86 of file linalg.cpp.

◆ getConditionSlope()

double Linalg::getConditionSlope ( const Eigen::MatrixXd & A,
Eigen::VectorXd & s )
static

Returns the condition slope of a given matrix.

Parameters
[in]AMatrix to compute the condition number from.
[out]sSingular values of A.
Returns
the condition slope.

Definition at line 99 of file linalg.cpp.

◆ intersect()

VectorXi Linalg::intersect ( const Eigen::VectorXi & v1,
const Eigen::VectorXi & v2,
Eigen::VectorXi & idx_sel )
static

Find the intersection of two vectors.

Parameters
[in]v1Input vector 1.
[in]v2Input vector 2.
[out]idx_selIndex of intersection based on v1.
Returns
the sorted, unique values that are in both of the input arrays.

Definition at line 170 of file linalg.cpp.

◆ make_block_diag()

SparseMatrix< double > Linalg::make_block_diag ( const Eigen::MatrixXd & A,
qint32 n )
static

Make a sparse block diagonal matrix.

Returns a sparse block diagonal, diagonalized from the elements in "A". "A" is ma x na, comprising bdn=(na/"n") blocks of submatrices. Each submatrix is ma x "n", and these submatrices are placed down the diagonal of the matrix.

Parameters
[in]AMatrix which should be diagonalized.
[in]nColumns of the submatrices.
Returns
A sparse block diagonal, diagonalized from the elements in "A".

Definition at line 205 of file linalg.cpp.

◆ pinv()

template<typename T>
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > UTILSLIB::Linalg::pinv ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & a)
static

Creates the pseudo inverse of a matrix.

Parameters
[in]aMatrix to compute the pseudo inverse of.
Returns
the pseudo inverse of a.

Definition at line 388 of file linalg.h.

◆ rank()

qint32 Linalg::rank ( const Eigen::MatrixXd & A,
double tol = 1e-8 )
static

Returns the rank of a matrix A.

Parameters
[in]AMatrix to get the rank from.
[in]tolRelative threshold: biggest singular value multiplied with tol is smallest singular value considered non-zero.
Returns
rank of matrix A.

Definition at line 240 of file linalg.cpp.

◆ sort() [1/2]

template<typename T>
Eigen::VectorXi UTILSLIB::Linalg::sort ( Eigen::Matrix< T, Eigen::Dynamic, 1 > & v,
bool desc = true )
static

Sorts a vector (ascending order) in place and returns the track of the original indices.

Parameters
[in,out]vVector to sort; it's sorted in place.
[in]descIf true its sorted in a descending order, otherwise ascending (default = true).
Returns
Vector of the original indices in the new order.

Definition at line 284 of file linalg.h.

◆ sort() [2/2]

template<typename T>
Eigen::VectorXi UTILSLIB::Linalg::sort ( Eigen::Matrix< T, Eigen::Dynamic, 1 > & v_prime,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & mat,
bool desc = true )
static

Sorts a vector and a corresponding matrix in place and returns the track of the original indices. The matrix is sorted along the columns using the vector values for comparison.

Parameters
[in,out]v_primeVector to sort (sorted in place).
[in,out]matMatrix to sort (sorted in place).
[in]descIf true its sorted in a descending order, otherwise ascending (default = true).
Returns
Vector of the original indices in the new order.

Definition at line 313 of file linalg.h.

◆ sortrows()

template<typename T>
std::vector< Eigen::Triplet< T > > UTILSLIB::Linalg::sortrows ( const std::vector< Eigen::Triplet< T > > & A,
qint32 column = 0 )
static

Sort rows in ascending order.

Parameters
[in]ATriplet vector to sort.
[in]columnSorts the triplet vector based on the column specified.
Returns
Sorted copy of the triplet vector.

Definition at line 333 of file linalg.h.


The documentation for this class was generated from the following files: