NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

Static Public Member Functions | List of all members
NeuralEngine::MachineLearning::CommonUtil< Scalar > Class Template Reference

## Static Public Member Functions
static Scalar | Euclidean (const af::array &a)
| Gets the Euclidean norm for a vector. More...
static af::array | Euclidean (const af::array &a, const af::array &b)
| Gets the Euclidean norm for two vectors. More...
static Scalar | SquareEuclidean (const af::array &a)
| Gets the Square Euclidean norm for two vectors. More...
static af::array | SquareEuclidean (const af::array &a, const af::array &b)
| Gets the Square Euclidean norm for a vector. More...
static Scalar | Max (Scalar a, Scalar b, Scalar c)
| Gets the maximum value among three values. More...
static af::array | Covariance (const af::array &M)
| Covariance. More...
static af::array | CorrelationCoefficients (const af::array &inX, const af::array &inY=af::array())
| Correlation coefficients. More...
static af::array | SquareDistance (const af::array &inX1, const af::array &inX2)
| Gets standardized Square Euclidean distance. More...
static af::array | UnscaledDistance (const af::array &inX1, const af::array &inX2)
| Unscaled distance. More...
static af::array | ScaledDistance (const af::array &inX1, const af::array &inX2, const af::array &inLengtScale)
| Scaled distance. More...
static af::array | NormalPDF (const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
| Normal probability density function. More...
static af::array | LogNormalPDF (const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
| Log normal probability density function. More...
static af::array | NormalCDF (const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
| Normal cumulative distribution function.. More...
static af::array | LogNormalCDF (const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
| Log normal cumulative distribution function. More...
static af::array | TriUpperIdx (int size, int dimension=0)
| Computes indexes of upper triangular matrix. More...
static af::array | TriLowerIdx (int size)
| Computes indexes of lower triangular matrix. More...
static af::array | DiagIdx (int size)
| Indexes of matrix diagonal. More...
static af::array | LinSpace (Scalar start, Scalar stop, int num, bool endpoint=true)
| Implementation of NumPy's Linspace. More...
static af::array | JitChol (const af::array &inA)
| Cholesky decomposition. More...
static Scalar | LogDet (af::array inA)
| Log determinant of the input matrix. More...
static void | MergeMaps (std::map< std::string, af::array > &lhs, const std::map< std::string, af::array > &rhs)
static af::array | SortRows (af::array inA)
| Sort rows. More...
static af::array | Join (const af::array &inA, const af::array &inB, int dimension=0)
| Joins matrices and vectors along specific dimension. More...
static af::array | SolveQR (const af::array &A, const af::array &b)
| Linear solve usingQR decomposition. More...
static af::array | PDInverse (const af::array &inA)
| Computes the pseudo inverse of a matrix. More...
static af::array | ReadTXT (std::string filename, char delimiter=' ')
| Loads an array from a text file. More...
static bool | WriteTXT (const af::array &data, std::string filename, char delimiter=' ')
| Writes an array to a text file. More...
static bool | IsEqual (const af::array &a, const af::array &b)
| Query if 'a' is equal to 'b'. More...
static af::dtype | CheckDType ()
| Checks af::array precision flag. More...

## Detailed Description

template<typename Scalar>
class NeuralEngine::MachineLearning::CommonUtil< Scalar >

Definition at line 36 of file CommonUtil.h.

## Member Function Documentation

## ◆ Euclidean() [1/2]

template<typename Scalar >

static Scalar NeuralEngine::MachineLearning::CommonUtil< Scalar >::Euclidean | ( | const af::array & | a | ) |
| static

Gets the Euclidean norm for a vector.

Admin, 3/27/2017.

Parameters

  a | [in,out] The af::array to process.

Returns
  A Scalar.

## ◆ Euclidean() [2/2]

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::Euclidean | ( | const af::array & | a,
|  | const af::array & | b
| ) |  |
| static

Gets the Euclidean norm for two vectors.

Hmetal T, 29/03/2018.

Parameters

  a | [in,out] The af::array to process.
  b | [in,out] The af::array to process.

Returns
  A Scalar.

## ◆ SquareEuclidean() [1/2]

template<typename Scalar >

static Scalar NeuralEngine::MachineLearning::CommonUtil< Scalar >::SquareEuclidean | ( | const af::array & | a | ) |
| static

Gets the Square Euclidean norm for two vectors.

Admin, 3/28/2017.

Parameters

  a | [in,out] The af::array to process.

Returns
  A Scalar.

## ◆ SquareEuclidean() [2/2]

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::SquareEuclidean | ( | const af::array & | a,
|  | const af::array & | b
| ) |  |
| static

Gets the Square Euclidean norm for a vector.

Hmetal T, 29/03/2018.

Parameters

  a | [in,out] The af::array to process.
  b | [in,out] The af::array to process.

Returns
  A Scalar.

## ◆ Max()

template<typename Scalar >

static Scalar NeuralEngine::MachineLearning::CommonUtil< Scalar >::Max | ( | Scalar | a,
|  | Scalar | b,
|  | Scalar | c
| ) |  |
| static

Gets the maximum value among three values.

Hmetal T, 03.04.2017.

Parameters

  a | The first value `a`.
  b | The second value `b`.
  c | The third value `c`.

Returns
  The maximum value among a , b and c .

## ◆ Covariance()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::Covariance | ( | const af::array & | M | ) |
| static

Covariance.

Hmetal T, 14.04.2017.

Parameters

  a | [in,out] Data matrix with row observation vectors.

Returns
  An af::array.

## ◆ CorrelationCoefficients()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::CorrelationCoefficients | ( | const af::array & | inX,
|  | const af::array & | inY = `af::array()`
| ) |  |
| static

Correlation coefficients.

calculates a matrix R of correlation coefficients for an array X, in which each row is an observation and each column is a variable.

Parameters

  inX | [in,out] The in x coordinate.
  inY | [in,out] (Optional) the in y coordinate.

Returns
  An af::array.

## ◆ SquareDistance()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::SquareDistance | ( | const af::array & | inX1,
|  | const af::array & | inX2
| ) |  |
| static

Gets standardized Square Euclidean distance.

Computation has the form of,

        \|\mathbf{x1}-\mathbf{x2}\|^2.

Admin, 5/24/2017.

Parameters

  inX1 | [in,out] The first x coordinate.
  inX2 | [in,out] The second x coordinate.

Returns
  An af::array.

## ◆ UnscaledDistance()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::UnscaledDistance | ( | const af::array & | inX1,
|  | const af::array & | inX2
| ) |  |
| static

Unscaled distance.

Computation has the form of,

        \sqrt{\|\mathbf{x1}-\mathbf{x2}\|^2}.

Admin, 5/24/2017.

Parameters

  inX1 | [in,out] The first x coordinate.
  inX2 | [in,out] The second x coordinate.

Returns
  An af::array.

## ◆ ScaledDistance()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::ScaledDistance | ( | const af::array & | inX1,
|  | const af::array & | inX2,
|  | const af::array & | inLengtScale
| ) |  |
| static

Scaled distance.

Computation has the form of,

        \sqrt{\sum_{d=1}^D{(x1_d-x2_d)^2/v_d}}.

Admin, 5/24/2017.

Parameters

  inX1 | The first x coordinate.
  inX2 | The second x coordinate.
  inLengtScale | The lengt scale.

Returns
  An af::array.

## ◆ NormalPDF()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::NormalPDF | ( | const af::array & | inX,
|  | const af::array & | inMu = `af::array()`,
|  | const af::array & | inSigma = `af::array()`
| ) |  |
| static

Normal probability density function.

Normal PDF is defined as follows:

    $$f(x;mu,sigma)=\frac{1}{x\sqrt{2\pi\sigma^2}}\exp{-\frac{(x-mu)^2}{2\sigma^2}}.$$

Hmetal T, 22/11/2019.

Parameters

  inX | The in x coordinate.
  inMu | (Optional) The in mu.
  inSigma | (Optional) The in sigma.

Returns
  An af::array.

## ◆ LogNormalPDF()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::LogNormalPDF | ( | const af::array & | inX,
|  | const af::array & | inMu = `af::array()`,
|  | const af::array & | inSigma = `af::array()`
| ) |  |
| static

Log normal probability density function.

Log normal PDF is defined as follows:

    $$f(x;mu,sigma)=\frac{1}{x\sqrt{2\pi\sigma^2}}\exp{-\frac{(\log(x)-mu)^2}{2\sigma^2}}.$$

Hmetal T, 22/11/2019.

Parameters

  inX | The in x coordinate.
  inMu | (Optional) The in mu.
  inSigma | (Optional) The in sigma.

Returns
  An af::array.

## ◆ NormalCDF()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::NormalCDF | ( | const af::array & | inX,
|  | const af::array & | inMu = `af::array()`,
|  | const af::array & | inSigma = `af::array()`
| ) |  |
| static

Normal cumulative distribution function..

Normal CDF is defined as follows:

    $$f(x;mu,sigma)=\frac{1}{2}\left[1 + erf\left(\frac{x-mu}{\sigma\sqrt{2}}\right)\right].$$

Hmetal T, 22/11/2019.

Parameters

  inX | The in x coordinate.
  inMu | (Optional) The in mu.
  inSigma | (Optional) The in sigma.

Returns
  An af::array.

## ◆ LogNormalCDF()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::LogNormalCDF | ( | const af::array & | inX,
|  | const af::array & | inMu = `af::array()`,
|  | const af::array & | inSigma = `af::array()`
| ) |  |
| static

Log normal cumulative distribution function.

Log normal CDF is defined as follows:

    $$f(x;mu,sigma)=\frac{1}{2}\left[1 + erf\left(\frac{\ln{x}-mu}{\sigma\sqrt{2}}\right)\right].$$

Hmetal T, 22/11/2019.

Parameters

  inX | The in x coordinate.
  inMu | (Optional) The in mu.
  inSigma | (Optional) The in sigma.

Returns
  An af::array.

## ◆ TriUpperIdx()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::TriUpperIdx | ( | int | size,
|  | int | dimension = `0`
| ) |  |
| static

Computes indexes of upper triangular matrix.

Hmetal T, 03/07/2018.

Parameters

  size | Size of the matrix.

Returns
  An af::array of indexes.

## ◆ TriLowerIdx()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::TriLowerIdx | ( | int | size | ) |
| static

Computes indexes of lower triangular matrix.

Hmetal T, 03/07/2018.

Parameters

  size | Size of the matrix.

Returns
  An af::array of indexes.

## ◆ DiagIdx()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::DiagIdx | ( | int | size | ) |
| static

Indexes of matrix diagonal.

Hmetal T, 23/04/2019.

Parameters

  size | Size of the matrix.

Returns
  An af::array.

## ◆ LinSpace()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::LinSpace | ( | Scalar | start,
|  | Scalar | stop,
|  | int | num,
|  | bool | endpoint = `true`
| ) |  |
| static

Implementation of NumPy's Linspace.

Hmetal T, 05/07/2018.

Parameters

  start | The start value.
  stop | The stop vale.
  num | Number of steps.
  endpoint | (Optional) true to endpoint.

Returns
  An af::array.

## ◆ JitChol()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::JitChol | ( | const af::array & | inA | ) |
| static

Cholesky decomposition.

If needed, adds jitter to the diagonal to ensure semipositive definitness.

Hmetal T, 05/07/2018.

Parameters

  inA | [in,out] The in a.

Returns
  An af::array.

## ◆ LogDet()

template<typename Scalar >

static Scalar NeuralEngine::MachineLearning::CommonUtil< Scalar >::LogDet | ( | af::array | inA | ) |
| static

Log determinant of the input matrix.

Hmetal T, 05/07/2018.

Parameters

  inA | The in a.

Returns
  A Scalar.

## ◆ SortRows()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::SortRows | ( | af::array | inA | ) |
| static

Sort rows.

Hmetal T, 03.05.2019.

Parameters

  inA | The in a.

Returns
  The sorted rows.

## ◆ Join()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::Join | ( | const af::array & | inA,
|  | const af::array & | inB,
|  | int | dimension = `0`
| ) |  |
| static

Joins matrices and vectors along specific dimension.

Hmetal T, 06.05.2019.

Parameters

  inA | The in a.
  inB | The in b.

Returns
  An af::array.

## ◆ SolveQR()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::SolveQR | ( | const af::array & | A,
|  | const af::array & | b
| ) |  |
| static

Linear solve usingQR decomposition.

Equivalent of Matlabs mldivide x = A.

Hmetal T, 27/05/2019.

Parameters

  A | [in,out] The af::array to process.
  b | [in,out] The af::array to process.

Returns
  Solution x.

## ◆ PDInverse()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::PDInverse | ( | const af::array & | inA | ) |
| static

Computes the pseudo inverse of a matrix.

Hmetal T, 06/01/2020.

Parameters

  inA | [in,out] The in symetric matrix.

Returns
  An af::array.

## ◆ ReadTXT()

template<typename Scalar >

static af::array NeuralEngine::MachineLearning::CommonUtil< Scalar >::ReadTXT | ( | std::string | filename,
|  | char | delimiter = `' '`
| ) |  |
| static

Loads an array from a text file.

Hmetal T, 20/12/2019.

Parameters

  filename | Filename of the file.

Returns
  The text.

## ◆ WriteTXT()

template<typename Scalar >

static bool NeuralEngine::MachineLearning::CommonUtil< Scalar >::WriteTXT | ( | const af::array & | data,
|  | std::string | filename,
|  | char | delimiter = `' '`
| ) |  |
| static

Writes an array to a text file.

Hmetal T, 20/12/2019.

Parameters

  data | The data array to write.
  filename | Filename of the file.
  delimiter | (Optional) The delimiter.

Returns
  True if it succeeds, false if it fails.

## ◆ IsEqual()

template<typename Scalar >

static bool NeuralEngine::MachineLearning::CommonUtil< Scalar >::IsEqual | ( | const af::array & | a,
|  | const af::array & | b
| ) |  |
| static

Query if 'a' is equal to 'b'.

Hmetal T, 29/04/2021.

Parameters

  a | An af::array to process.
  b | An af::array to process.

Returns
  True if equal, false if not.

## ◆ CheckDType()

template<typename Scalar >

static af::dtype NeuralEngine::MachineLearning::CommonUtil< Scalar >::CheckDType | ( |  | ) |
| static

Checks af::array precision flag.

Hmetal T, 17/06/2019.

Returns
  A dtype.

The documentation for this class was generated from the following file:

- CommonUtil.h