NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
nc::linalg Namespace Reference

Namespaces

namespace  detail
 

Data Structures

class  SVD
 

Functions

template<typename dtype >
NdArray< double > cholesky (const NdArray< dtype > &inMatrix)
 
template<typename dtype >
auto det (const NdArray< dtype > &inArray)
 
template<typename dtype , typename... Params, std::enable_if_t< std::is_arithmetic_v< dtype >, int > = 0, std::enable_if_t< all_arithmetic_v< Params... >, int > = 0, std::enable_if_t< all_same_v< dtype, Params... >, int > = 0>
std::pair< NdArray< double >, double > gaussNewtonNlls (const uint32 numIterations, const NdArray< dtype > &coordinates, const NdArray< dtype > &measurements, const std::function< dtype(const NdArray< dtype > &, const NdArray< dtype > &)> &function, const std::array< std::function< dtype(const NdArray< dtype > &, const NdArray< dtype > &)>, sizeof...(Params)> &derivatives, Params... initialGuess)
 
template<typename dtype >
NdArray< dtype > hat (const NdArray< dtype > &inVec)
 
NdArray< double > hat (const Vec3 &inVec)
 
template<typename dtype >
NdArray< dtype > hat (dtype inX, dtype inY, dtype inZ)
 
template<typename dtype >
NdArray< double > inv (const NdArray< dtype > &inArray)
 
template<typename dtype >
NdArray< double > lstsq (const NdArray< dtype > &inA, const NdArray< dtype > &inB, double inTolerance=1e-12)
 
template<typename dtype >
std::pair< NdArray< double >, NdArray< double > > lu_decomposition (const NdArray< dtype > &inMatrix)
 
template<typename dtype >
NdArray< double > matrix_power (const NdArray< dtype > &inArray, int16 inPower)
 
template<typename dtype >
NdArray< dtype > multi_dot (const std::initializer_list< NdArray< dtype > > &inList)
 
template<typename dtype >
NdArray< double > pinv (const NdArray< dtype > &inArray)
 
template<typename dtype >
std::tuple< NdArray< double >, NdArray< double >, NdArray< double > > pivotLU_decomposition (const NdArray< dtype > &inMatrix)
 
template<typename dtype >
NdArray< double > solve (const NdArray< dtype > &inA, const NdArray< dtype > &inB)
 
template<typename dtype >
void svd (const NdArray< dtype > &inArray, NdArray< double > &outU, NdArray< double > &outS, NdArray< double > &outVt)
 

Function Documentation

◆ cholesky()

template<typename dtype >
NdArray< double > nc::linalg::cholesky ( const NdArray< dtype > &  inMatrix)

matrix cholesky decomposition A = L * L.transpose()

NumPy Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.cholesky.html#numpy.linalg.cholesky

Parameters
inMatrixNdArray to be decomposed
Returns
NdArray of the decomposed L matrix

◆ det()

template<typename dtype >
auto nc::linalg::det ( const NdArray< dtype > &  inArray)

matrix determinant. NOTE: can get verrrrry slow for large matrices (order > 10)

SciPy Reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.det.html#scipy.linalg.det

Parameters
inArray
Returns
matrix determinant
Examples
ReadMe.cpp.

◆ gaussNewtonNlls()

template<typename dtype , typename... Params, std::enable_if_t< std::is_arithmetic_v< dtype >, int > = 0, std::enable_if_t< all_arithmetic_v< Params... >, int > = 0, std::enable_if_t< all_same_v< dtype, Params... >, int > = 0>
std::pair< NdArray< double >, double > nc::linalg::gaussNewtonNlls ( const uint32  numIterations,
const NdArray< dtype > &  coordinates,
const NdArray< dtype > &  measurements,
const std::function< dtype(const NdArray< dtype > &, const NdArray< dtype > &)> &  function,
const std::array< std::function< dtype(const NdArray< dtype > &, const NdArray< dtype > &)>  ,
sizeof...  Params,
derivatives,
Params...  initialGuess 
)

The Gauss�Newton algorithm is used to solve non-linear least squares problems. It is a modification of Newton's method for finding a minimum of a function. https://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm

Parameters
numIterationsthe number of iterations to perform
coordinatesthe coordinate values. The shape needs to be [n x d], where d is the number of diminsions of the fit function (f(x) is one dimensional, f(x, y) is two dimensions, etc), and n is the number of observations that are being fit to.
measurementsthe measured values that are being fit
functiona std::function of the function that is being fit. The function takes as inputs an NdArray of a single set of the coordinate values, and an NdArray of the current values of the fit parameters
derivativesarray of std::functions to calculate the function derivatives. The function that is being fit. The function takes as inputs an NdArray of a single set of the coordinate values, and an NdArray of the current values of the fit parameters
initialGuessthe initial guess of the parameters to be solved for
Returns
std::pair of NdArray of solved parameter values, and rms of the residuals value
Examples
GaussNewtonNlls.cpp.

◆ hat() [1/3]

template<typename dtype >
NdArray< dtype > nc::linalg::hat ( const NdArray< dtype > &  inVec)

vector hat operator

Parameters
inVec(3x1, or 1x3 cartesian vector)
Returns
3x3 NdArray

◆ hat() [2/3]

NdArray< double > nc::linalg::hat ( const Vec3 inVec)
inline

vector hat operator

Parameters
inVec
Returns
3x3 NdArray

◆ hat() [3/3]

template<typename dtype >
NdArray< dtype > nc::linalg::hat ( dtype  inX,
dtype  inY,
dtype  inZ 
)

vector hat operator

Parameters
inX
inY
inZ
Returns
3x3 NdArray

◆ inv()

template<typename dtype >
NdArray< double > nc::linalg::inv ( const NdArray< dtype > &  inArray)

◆ lstsq()

template<typename dtype >
NdArray< double > nc::linalg::lstsq ( const NdArray< dtype > &  inA,
const NdArray< dtype > &  inB,
double  inTolerance = 1e-12 
)

Solves the equation a x = b by computing a vector x that minimizes the Euclidean 2-norm || b - a x ||^2. The equation may be under-, well-, or over- determined (i.e., the number of linearly independent rows of a can be less than, equal to, or greater than its number of linearly independent columns). If a is square and of full rank, then x (but for round-off error) is the "exact" solution of the equation.

SciPy Reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html#scipy.linalg.lstsq

Parameters
inAcoefficient matrix
inBOrdinate or "dependent variable" values
inTolerance(default 1e-12)
Returns
NdArray
Examples
ReadMe.cpp.

◆ lu_decomposition()

template<typename dtype >
std::pair< NdArray< double >, NdArray< double > > nc::linalg::lu_decomposition ( const NdArray< dtype > &  inMatrix)

matrix LU decomposition A = LU

Parameters
inMatrixNdArray to be decomposed
Returns
std::pair<NdArray, NdArray> of the decomposed L and U matrices

◆ matrix_power()

template<typename dtype >
NdArray< double > nc::linalg::matrix_power ( const NdArray< dtype > &  inArray,
int16  inPower 
)

Raise a square matrix to the (integer) power n.

For positive integers n, the power is computed by repeated matrix squarings and matrix multiplications. If n == 0, the identity matrix of the same shape as M is returned. If n < 0, the inverse is computed and then raised to the abs(n).

NumPy Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.matrix_power.html#numpy.linalg.matrix_power

Parameters
inArray
inPower
Returns
NdArray

◆ multi_dot()

template<typename dtype >
NdArray< dtype > nc::linalg::multi_dot ( const std::initializer_list< NdArray< dtype > > &  inList)

Compute the dot product of two or more arrays in a single function call.

NumPy Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.multi_dot.html#numpy.linalg.multi_dot

Parameters
inListlist of arrays
Returns
NdArray

◆ pinv()

template<typename dtype >
NdArray< double > nc::linalg::pinv ( const NdArray< dtype > &  inArray)

matrix psuedo-inverse

NumPy Reference: https://numpy.org/doc/stable/reference/generated/numpy.linalg.pinv.html

Parameters
inArray
Returns
NdArray

◆ pivotLU_decomposition()

template<typename dtype >
std::tuple< NdArray< double >, NdArray< double >, NdArray< double > > nc::linalg::pivotLU_decomposition ( const NdArray< dtype > &  inMatrix)

matrix pivot LU decomposition PA = LU

Parameters
inMatrixNdArray to be decomposed
Returns
std::tuple<NdArray, NdArray, NdArray> of the decomposed L, U, and P matrices

◆ solve()

template<typename dtype >
NdArray< double > nc::linalg::solve ( const NdArray< dtype > &  inA,
const NdArray< dtype > &  inB 
)

Solve a linear matrix equation, or system of linear scalar equations. Computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.

https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html

Parameters
inA
inB
Returns
NdArray<double> Solution to the system a x = b. Returned shape is identical to b

◆ svd()

template<typename dtype >
void nc::linalg::svd ( const NdArray< dtype > &  inArray,
NdArray< double > &  outU,
NdArray< double > &  outS,
NdArray< double > &  outVt 
)

matrix svd

NumPy Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html#numpy.linalg.svd

Parameters
inArrayNdArray to be SVDed
outUNdArray output U
outSNdArray output S
outVtNdArray output V transpose
Examples
ReadMe.cpp.