philsupertramp/game-math
Loading...
Searching...
No Matches
Functions
matrix_utils.h File Reference
#include "Matrix.h"

Go to the source code of this file.

Functions

template<typename T >
Matrix< T > HadamardMulti (const Matrix< T > &lhs, const Matrix< T > &rhs)
 
template<typename T >
Matrix< T > HadamardDiv (const Matrix< T > &lhs, const Matrix< T > &rhs)
 
template<typename T >
Matrix< T > KroneckerMulti (const Matrix< T > &lhs, const Matrix< T > &rhs)
 
template<typename T >
Matrix< T > HorizontalConcat (const Matrix< T > &lhs, const Matrix< T > &rhs)
 
template<typename T >
size_t Corr (const Matrix< T > &A, const Matrix< T > &B)
 
template<typename T >
Matrix< T > from_vptr (const T *value, MatrixDimension size)
 
template<typename T >
size_t argmax (const Matrix< T > &mat)
 
template<typename T >
size_t argmin (const Matrix< T > &mat)
 
template<typename T >
Matrix< T > where (const std::function< bool(T)> &condition, const Matrix< T > &in, const Matrix< T > &valIfTrue, const Matrix< T > &valIfFalse)
 
template<typename T >
Matrix< size_t > where_value (const Matrix< T > &in, T value)
 
template<typename T >
Matrix< size_t > where_true (const Matrix< T > &in)
 
template<typename T >
Matrix< size_t > where_false (const Matrix< T > &in)
 
template<typename T >
std::vector< std::pair< Matrix< T >, Matrix< T > > > zip (const Matrix< T > &a, const Matrix< T > &b)
 
template<typename T >
max (const Matrix< T > &mat)
 
template<typename T >
Matrix< T > max (const Matrix< T > &mat, int axis)
 
template<typename T >
min (const Matrix< T > &mat)
 
template<typename T >
Matrix< T > min (const Matrix< T > &mat, int axis)
 
template<typename T >
elemMax (const Matrix< T > &mat, const size_t &elemIndex)
 
template<typename T >
elemMin (const Matrix< T > &mat, const size_t &elemIndex)
 
template<typename T >
Matrix< T > mean (const Matrix< T > &mat, int axis=-1)
 
template<typename T >
elemMean (const Matrix< T > &mat, const size_t &elemIndex)
 
template<typename T >
Matrix< T > diag_elements (const Matrix< T > &in)
 
template<typename T >
Matrix< T > unique (const Matrix< T > &in, int axis=0)
 

Function Documentation

◆ argmax()

template<typename T >
size_t argmax ( const Matrix< T > &  mat)

Search index of value with maximum value Caution! This value does represent the index in a ongoing array.

Template Parameters
T
Parameters
mat
Returns
Examples
TestMatrix.cpp.

◆ argmin()

template<typename T >
size_t argmin ( const Matrix< T > &  mat)

Search index of value with lowest value Caution! This value does represent the index in a ongoing array.

Template Parameters
Tmatrix value type
Parameters
matelement to search in
Returns
index of minimal value
Examples
TestMatrix.cpp.

◆ Corr()

template<typename T >
size_t Corr ( const Matrix< T > &  A,
const Matrix< T > &  B 
)

Counts correlations between A and B

Template Parameters
Tvalue type of A and B
Parameters
Amatrix to compare
Bmatrix to compare with
Returns
number of element wise equal elements
Examples
TestMatrix.cpp.

◆ diag_elements()

template<typename T >
Matrix< T > diag_elements ( const Matrix< T > &  in)

Returns Vector of diagonal elements from matrix.

Template Parameters
Tgiven datatype
Parameters
ininput matrix
Returns
vector of diagonal elements

◆ elemMax()

template<typename T >
T elemMax ( const Matrix< T > &  mat,
const size_t &  elemIndex 
)

Max value from given element index in matrix

Template Parameters
Tgiven datatype
Parameters
matmatrix to search in
elemIndexindex of element to compute max value of
Returns
max value over all elements with given index
Examples
TestMatrix.cpp.

◆ elemMean()

template<typename T >
T elemMean ( const Matrix< T > &  mat,
const size_t &  elemIndex 
)

mean operation on element with given index

Template Parameters
Tgiven datatype
Parameters
matinput matrix
elemIndexindex of element to compute mean of
Returns
mean of all elements
Examples
TestMatrix.cpp.

◆ elemMin()

template<typename T >
T elemMin ( const Matrix< T > &  mat,
const size_t &  elemIndex 
)

Min value from given element index in matrix

Template Parameters
Tgiven datatype
Parameters
matmatrix to search in
elemIndexindex of element to compute max value of
Returns
min value over all elements with given index

◆ from_vptr()

template<typename T >
Matrix< T > from_vptr ( const T *  value,
MatrixDimension  size 
)

Converts array of elements of type T into matrix of given size

Template Parameters
Tvalue type
Parameters
valuepointer to array of elements of type T
sizedimension of target matrix
Returns
Examples
TestMatrix.cpp.

◆ HadamardDiv()

template<typename T >
Matrix< T > HadamardDiv ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Element wise division

Template Parameters
Tvalue type
Parameters
lhsleft hand side with dimension n1, m1
rhsright hand side with dimension n1, m1
Returns
product of element wise multiplication of lhs * rhs with dimension n1, m1

◆ HadamardMulti()

template<typename T >
Matrix< T > HadamardMulti ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Helper utilities Element wise multiplication

Template Parameters
Tvalue type
Parameters
lhsleft hand side with dimension n1, m1
rhsright hand side with dimension n1, m1
Returns
product of element wise multiplication of lhs * rhs with dimension n1, m1
Examples
TestMatrix.cpp.

◆ HorizontalConcat()

template<typename T >
Matrix< T > HorizontalConcat ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Horizontal concatenation of 2 matrices of same Row size

Template Parameters
Tvalue type
Parameters
lhsleft hand side with dimension n1, m1
rhsright hand side with dimension n1, m2
Returns
concatenated matrix [lhs, rhs] of dimension n1, m1 + m2
Examples
TestMatrix.cpp, numerics/analysis/TestDifferentiation.cpp, numerics/lin_alg/TestSVD.cpp, and plot/TestPlot.cpp.

◆ KroneckerMulti()

template<typename T >
Matrix< T > KroneckerMulti ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

A form of matrix multiplication For explicit reference please consult https://en.wikipedia.org/wiki/Kronecker_product

Template Parameters
Tvalue type
Parameters
lhsleft hand side with dimension n1, m1
rhsright hand side with dimension n2, m2
Returns
resulting matrix with dimension n1 * n2, m1 * m2
Examples
TestMatrix.cpp.

◆ max() [1/2]

template<typename T >
T max ( const Matrix< T > &  mat)

Max value of given Matrix

Template Parameters
Tgiven datatype
Parameters
matmatrix to search max value in
Returns
max value of given matrix
Examples
ds/TestLogRegSGD.cpp.

◆ max() [2/2]

template<typename T >
Matrix< T > max ( const Matrix< T > &  mat,
int  axis 
)

◆ mean()

template<typename T >
Matrix< T > mean ( const Matrix< T > &  mat,
int  axis = -1 
)

Calculates mean over given axis

Template Parameters
Tgiven dataatype
Parameters
matmatrix to calculate mean of
axisaxis along which to calculate the mean (-1: no axis - over all elements, 0: row wise, 1: column wise)
Returns
mean of elements inside given matrix along given axis
Examples
TestMatrix.cpp, and numerics/lin_alg/TestSVD.cpp.

◆ min() [1/2]

template<typename T >
T min ( const Matrix< T > &  mat)

Min value of given matrix

Template Parameters
Tgiven datatype
Parameters
matmatrix to search min value in
Returns
min value of matrix
Examples
ds/TestLogRegSGD.cpp.

◆ min() [2/2]

template<typename T >
Matrix< T > min ( const Matrix< T > &  mat,
int  axis 
)

◆ unique()

template<typename T >
Matrix< T > unique ( const Matrix< T > &  in,
int  axis = 0 
)

Returns unique values of given matrix.

Template Parameters
Tgiven datatype
Parameters
ininput matrix
Returns
matrix of unique values
Examples
TestMatrix.cpp.

◆ where()

template<typename T >
Matrix< T > where ( const std::function< bool(T)> &  condition,
const Matrix< T > &  in,
const Matrix< T > &  valIfTrue,
const Matrix< T > &  valIfFalse 
)

Returns elements chosen from valIfTrue or valIfFalse depending on condition

Template Parameters
Tvalue type
Parameters
conditionlambda/function to test a condition on every element of in
ininput values
valIfTruevalue vector with values in case in meets condition
valIfFalsevalue vector with values in case in does not meet condition
Returns
Examples
TestMatrix.cpp, and ds/TestLogRegSGD.cpp.

◆ where_false()

template<typename T >
Matrix< size_t > where_false ( const Matrix< T > &  in)

Evaluates elements of a given vector. Responds with indices of true values.

Parameters
invector to evaluate in
Returns
vector of indices where element has true value

◆ where_true()

template<typename T >
Matrix< size_t > where_true ( const Matrix< T > &  in)

Evaluates elements of a given vector. Responds with indices of true values.

Parameters
invector to evaluate in
Returns
vector of indices where element has true value

◆ where_value()

template<typename T >
Matrix< size_t > where_value ( const Matrix< T > &  in,
value 
)

Evaluates elements of a given vector. Responds with indices of true values.

Parameters
invector to evaluate in
Returns
vector of indices where element has true value

◆ zip()

template<typename T >
std::vector< std::pair< Matrix< T >, Matrix< T > > > zip ( const Matrix< T > &  a,
const Matrix< T > &  b 
)

Converts two input matrices into a vector of row-wise pairs of a and b

Template Parameters
Tvalue type
Parameters
a
b
Returns