Pseudo-invert (Moore-Penrose) a matrix. More...
Functions | |
AFAPI array | pinverse (const array &in, const double tol=1E-6, const matProp options=AF_MAT_NONE) |
C++ Interface to pseudo-invert (Moore-Penrose) a matrix. More... | |
AFAPI af_err | af_pinverse (af_array *out, const af_array in, const double tol, const af_mat_prop options) |
C Interface to pseudo-invert (Moore-Penrose) a matrix. More... | |
Pseudo-invert (Moore-Penrose) a matrix.
This function calculates the Moore-Penrose pseudoinverse of a matrix \(A\), using af::svd at its core. If \(A\) is of size \(M \times N\), then its pseudoinverse \(A^+\) will be of size \(N \times M\).
This calculation can be batched if the input array is three or four-dimensional \((M \times N \times P \times Q\), with \(Q=1\) for only three dimensions \()\). Each \(M \times N\) slice along the third dimension will have its own pseudoinverse, for a total of \(P \times Q\) pseudoinverses in the output array \((N \times M \times P \times Q)\).
Below is an example snippet of its usage. In this example, we have a matrix \(A\) and compute its pseudoinverse \(A^+\). This condition must hold: \(AA^+A=A\), given that the two matrices are pseudoinverses of each other (in fact, this is one of the Moore-Penrose conditions):
AFAPI af_err af_pinverse | ( | af_array * | out, |
const af_array | in, | ||
const double | tol, | ||
const af_mat_prop | options | ||
) |
C Interface to pseudo-invert (Moore-Penrose) a matrix.
Currently uses the SVD-based approach.
Parameter tol
is not the actual lower threshold, but it is passed in as a parameter to the calculation of the actual threshold relative to the shape and contents of in
.
Suggested parameters for tol
: 1e-6 for single precision and 1e-12 for double precision.
[out] | out | pseudo-inverse matrix |
[in] | in | input matrix |
[in] | tol | defines the lower threshold for singular values from SVD |
[in] | options | must be AF_MAT_NONE (more options might be supported in the future) |
AFAPI array pinverse | ( | const array & | in, |
const double | tol = 1E-6 , |
||
const matProp | options = AF_MAT_NONE |
||
) |
C++ Interface to pseudo-invert (Moore-Penrose) a matrix.
Currently uses the SVD-based approach.
Parameter tol
is not the actual lower threshold, but it is passed in as a parameter to the calculation of the actual threshold relative to the shape and contents of in
.
This function is not supported in GFOR.
[in] | in | input matrix |
[in] | tol | defines the lower threshold for singular values from SVD |
[in] | options | must be AF_MAT_NONE (more options might be supported in the future) |