Skip to main content

Linalg

Namespace: MATHLIB  ·  Library: Math Library

Python equivalent

numpy.linalg / scipy.linalg in MNE-Python.

#include <math/linalg.h>

class UTILSLIB::Linalg

Static linear-algebra utilities (condition numbers, block-diagonal sparse assembly, xyz reductions, stable index sort) layered on top of Eigen for use across MATHLIB, FWDLIB and INVERSELIB.

Static Eigen-based linear-algebra helpers used across MATHLIB and the inverse solvers.


Public Methods

~Linalg()

Destroys the Linalg object.


Static Methods

combine_xyz(vec)

Compute the three Cartesian components of a vector together.

Parameters:

  • vec : const Eigen::VectorXd & Input row vector [ x1 y1 z1 ... x_n y_n z_n ].

Returns:

  • Eigen::VectorXd — Output vector [x1^2+y1^2+z1^2 ... x_n^2+y_n^2+z_n^2 ].

getConditionNumber(A, s)

Returns the condition number of a given matrix.

Parameters:

  • A : const Eigen::MatrixXd & Matrix to compute the condition number from.

  • s : Eigen::VectorXd & Singular values of A.

Returns:

  • double — the condition number.

getConditionSlope(A, s)

Returns the condition slope of a given matrix.

Parameters:

  • A : const Eigen::MatrixXd & Matrix to compute the condition number from.

  • s : Eigen::VectorXd & Singular values of A.

Returns:

  • double — the condition slope.

get_whitener(A, pca, ch_type, eig, eigvec)

Returns the whitener of a given matrix.

Parameters:

  • A : Eigen::MatrixXd & Matrix to compute the whitener from.

  • pca : bool Perform a PCA.

  • ch_type : QString Channel type string.

  • eig : Eigen::VectorXd & Eigenvalues.

  • eigvec : Eigen::MatrixXd & Eigenvectors (transposed).


get_whitener(A, pca, ch_type, eig, eigvec)

Returns the whitener of a given matrix.

Parameters:

  • A : Eigen::MatrixXd & Matrix to compute the whitener from.

  • pca : bool Perform a PCA.

  • ch_type : const std::string & Channel type string.

  • eig : Eigen::VectorXd & Eigenvalues.

  • eigvec : Eigen::MatrixXd & Eigenvectors (transposed).


intersect(v1, v2, idx_sel)

Find the intersection of two vectors.

Parameters:

  • v1 : const Eigen::VectorXi & Input vector 1.

  • v2 : const Eigen::VectorXi & Input vector 2.

  • idx_sel : Eigen::VectorXi & Index of intersection based on v1.

Returns:

  • Eigen::VectorXi — the sorted, unique values that are in both of the input arrays.

make_block_diag(A, n)

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:

  • A : const Eigen::MatrixXd & Matrix which should be diagonalized.

  • n : qint32 Columns of the submatrices.

Returns:

  • Eigen::SparseMatrix< double > — A sparse block diagonal, diagonalized from the elements in "A".

pinv(a)

Creates the pseudo inverse of a matrix.

Parameters:

  • a : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix to compute the pseudo inverse of.

Returns:

  • Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > — the pseudo inverse of a.

rank(A, tol)

Returns the rank of a matrix A.

Parameters:

  • A : const Eigen::MatrixXd & Matrix to get the rank from.

  • tol : double Relative threshold: biggest singular value multiplied with tol is smallest singular value considered non-zero.

Returns:

  • qint32 — rank of matrix A.

sort(v, desc)

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

Parameters:

  • v : Eigen::Matrix< T, Eigen::Dynamic, 1 > & Vector to sort; it's sorted in place.

  • desc : bool If true its sorted in a descending order, otherwise ascending (default = true).

Returns:

  • Eigen::VectorXi — Vector of the original indices in the new order.

sort(v_prime, mat, desc)

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:

  • v_prime : Eigen::Matrix< T, Eigen::Dynamic, 1 > & Vector to sort (sorted in place).

  • mat : Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix to sort (sorted in place).

  • desc : bool If true its sorted in a descending order, otherwise ascending (default = true).

Returns:

  • Eigen::VectorXi — Vector of the original indices in the new order.

sortrows(A, column)

Sort rows in ascending order.

Parameters:

  • A : const std::vector< Eigen::Triplet< T > > & Triplet vector to sort.

  • column : qint32 Sorts the triplet vector based on the column specified.

Returns:

  • std::vector< Eigen::Triplet< T > > — Sorted copy of the triplet vector.

compareIdxValuePairBiggerThan(lhs, rhs)

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


compareIdxValuePairSmallerThan(lhs, rhs)

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


compareTripletFirstEntry(lhs, rhs)

Compares triplet first entry (row).


compareTripletSecondEntry(lhs, rhs)

Compares triplet second entry (column).


Authors of this file