philsupertramp/game-math
Loading...
Searching...
No Matches
Macros | Functions
utils.h File Reference
#include "../Matrix.h"
#include "../sorting.h"
#include <vector>

Go to the source code of this file.

Macros

#define EPS   1e-8
 accuracy of calculated results More...
 

Functions

Matrix< double > linspace (double start, double end, unsigned long num_elements)
 
Matrix< double > zeros (size_t rows, size_t columns, size_t elements=1)
 
Matrix< double > zerosV (size_t rows)
 
Matrix< double > ones (size_t rows, size_t columns=1, size_t elements=1)
 
Matrix< double > eye (size_t rows, size_t columns=0)
 
Matrix< double > tridiag (size_t rows, size_t columns, double left, double center, double right)
 
double norm (const Matrix< double > &in)
 
Matrix< double > norm (const Matrix< double > &in, int axis)
 
Matrix< size_t > argsort (const Matrix< double > &in)
 
Matrix< size_t > nonzero (const std::function< bool(const double &)> &validation, const Matrix< double > &x)
 
template<typename T >
Matrix< T > diag (const Matrix< T > &in)
 

Detailed Description

Requires:

Numerical helper methods.

This header includes numerical methods used to simplify computation of numerical algorithms. It mostly contains generator like functions to generate a specific kind of Matrix

Macro Definition Documentation

◆ EPS

#define EPS   1e-8

accuracy of calculated results

Function Documentation

◆ argsort()

Matrix< size_t > argsort ( const Matrix< double > &  in)

Computes indices of ordered vector. Orders vector, than builds resulting vector by selecting indices.

Parameters
ingiven matrix to sort
Returns
indices of sorted version of given matrix

◆ diag()

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

Method to extract diagonal elements of given matrix into dedicated vector

Parameters
ingiven matrix to extract diagonal elements from
Returns
vector of diagonal elements
Examples
numerics/lin_alg/TestSVD.cpp.

◆ eye()

Matrix< double > eye ( size_t  rows,
size_t  columns = 0 
)

creates unit matrix of dimension rows, columns

Parameters
rows
columnsif 0, then columns = rows
Returns
Examples
TestMatrix.cpp, TestUtils.cpp, numerics/TestUtils.cpp, numerics/lin_alg/TestGaussSeidel.cpp, and numerics/lin_alg/TestSVD.cpp.

◆ linspace()

Matrix< double > linspace ( double  start,
double  end,
unsigned long  num_elements 
)

generates a vector with equidistant values, [start:(end-start)/num_elements:end]

Parameters
startstart value
endend value
num_elementsnumber of elements within the resulting vector
Returns
vector of equidistant values from start to end
Examples
numerics/TestUtils.cpp, numerics/analysis/TestDifferentiation.cpp, numerics/analysis/TestSupportValues.cpp, numerics/lin_alg/TestSVD.cpp, and plot/TestPlot.cpp.

◆ nonzero()

Matrix< size_t > nonzero ( const std::function< bool(const double &)> &  validation,
const Matrix< double > &  x 
)

Index-Getter for validated values

Examples: validation function x<=0 returns indices of values <= 0

Parameters
validationvalidation function, this method validates your data
xvector to test
Returns
index vectors of values true to the validation function

◆ norm() [1/2]

double norm ( const Matrix< double > &  in)

Calculates the p=2-Norm for a given matrix

\[ \sqrt{\sum x_i^2} \]

In 2D this is equal to the pythagorean theorem.

Parameters
ininput matrix to calculate norm of
Returns
2-norm of given matrix
Examples
numerics/TestUtils.cpp, and statistics/TestProbability.cpp.

◆ norm() [2/2]

Matrix< double > norm ( const Matrix< double > &  in,
int  axis 
)

Helper method to calculate 2-Norm on given axis

Parameters
ininput matrix to calculate norm(s) of
axisalong which to calculate norm on (options: 0 (row-wise), 1 (column-wise)) @returnss norm on given axis

◆ ones()

Matrix< double > ones ( size_t  rows,
size_t  columns = 1,
size_t  elements = 1 
)

Generates a matrix with each element = 1 for given size

Parameters
rowsnumber rows for resulting matrix
columnsnumber columns for resulting matrix
elementsnumber of elements per cell
Returns
rows x columns-Matrix with 1 as each value
Examples
ds/preprocessing/TestScaler.cpp, numerics/TestUtils.cpp, numerics/lin_alg/TestSVD.cpp, and plot/TestPlot.cpp.

◆ tridiag()

Matrix< double > tridiag ( size_t  rows,
size_t  columns,
double  left,
double  center,
double  right 
)

creates tri-diagonal-matrix with given values and dimensions

Parameters
rowsrow dimension
columnscolumn dimension
leftleft/lower diagonal element value
centerdiagonal element value
rightright/upper diagonal element value
Returns
tri-diagonal-matrix

◆ zeros()

Matrix< double > zeros ( size_t  rows,
size_t  columns,
size_t  elements = 1 
)

Generates a matrix with each element = 0 for given size

Parameters
rowsnumber rows for resulting matrix
columnsnumber columns for resulting matrix
elementsnumber of elements per cell
Returns
rows x columns-Matrix with 0 as each value
Examples
ds/preprocessing/TestScaler.cpp, numerics/TestUtils.cpp, and plot/TestPlot.cpp.

◆ zerosV()

Matrix< double > zerosV ( size_t  rows)

Generates a matrix with each element = 0 for given size

Parameters
rowsnumber of rows in resulting vetor
Returns
zero-vector of size rows
Examples
numerics/TestUtils.cpp.