NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
CommonUtil.h
1
11#pragma once
12
13#include <NeMachineLearningLib.h>
14#include <Core/NeLogger.h>
15#include <MachineLearning/FgArrayFireSerialization.h>
16
17
18
19namespace NeuralEngine
20{
21 namespace MachineLearning
22 {
23 template<class T>
24 struct is_Scalar
25 : std::integral_constant<
26 bool,
27 std::is_same<double, typename std::remove_cv<T>::type>::value> {};
28
29 template<class T>
30 struct is_float
31 : std::integral_constant<
32 bool,
33 std::is_same<float, typename std::remove_cv<T>::type>::value> {};
34
35 template<typename Scalar>
36 class NE_IMPEXP CommonUtil
37 {
38 public:
39
49 static Scalar Euclidean(const af::array& a);
50
61 static af::array Euclidean(const af::array& a, const af::array& b);
62
72 static Scalar SquareEuclidean(const af::array& a);
73
84 static af::array SquareEuclidean(const af::array& a, const af::array& b);
85
100 static Scalar Max(Scalar a, Scalar b, Scalar c);
101
111 static af::array Covariance(const af::array& M);
112
126 static af::array CorrelationCoefficients(const af::array& inX, const af::array& inY = af::array());
127
144 static af::array SquareDistance(const af::array& inX1, const af::array& inX2);
145
162 static af::array UnscaledDistance(const af::array& inX1, const af::array& inX2);
163
181 static af::array ScaledDistance(const af::array& inX1, const af::array& inX2, const af::array& inLengtScale);
182
200 static af::array NormalPDF(const af::array& inX, const af::array& inMu = af::array(), const af::array& inSigma = af::array());
201
219 static af::array LogNormalPDF(const af::array& inX, const af::array& inMu = af::array(), const af::array& inSigma = af::array());
220
238 static af::array NormalCDF(const af::array& inX, const af::array& inMu = af::array(), const af::array& inSigma = af::array());
239
257 static af::array LogNormalCDF(const af::array& inX, const af::array& inMu = af::array(), const af::array& inSigma = af::array());
258
268 static af::array TriUpperIdx(int size, int dimension = 0);
269
279 static af::array TriLowerIdx(int size);
280
290 static af::array DiagIdx(int size);
291
304 static af::array LinSpace(Scalar start, Scalar stop, int num, bool endpoint = true);
305
319 static af::array JitChol(const af::array& inA);
320
330 static Scalar LogDet(af::array inA);
331
332 static void MergeMaps(std::map<std::string, af::array>& lhs, const std::map<std::string, af::array>& rhs);
333
343 static af::array SortRows(af::array inA);
344
355 static af::array Join(const af::array& inA, const af::array& inB, int dimension = 0);
356
371 static af::array SolveQR(const af::array& A, const af::array& b);
372
382 static af::array PDInverse(const af::array& inA);
383
393 static af::array ReadTXT(std::string filename, char delimiter = ' ');
394
406 static bool WriteTXT(const af::array& data, std::string filename, char delimiter = ' ');
407
418 static bool IsEqual(const af::array& a, const af::array& b);
419
427 static af::dtype CheckDType();
428 };
429 }
430}
static af::array LinSpace(Scalar start, Scalar stop, int num, bool endpoint=true)
Implementation of NumPy's Linspace.
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.
static bool IsEqual(const af::array &a, const af::array &b)
Query if 'a' is equal to 'b'.
static af::array NormalCDF(const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
Normal cumulative distribution function..
static Scalar Max(Scalar a, Scalar b, Scalar c)
Gets the maximum value among three values.
static af::array SquareEuclidean(const af::array &a, const af::array &b)
Gets the Square Euclidean norm for a vector.
static af::dtype CheckDType()
Checks af::array precision flag.
static af::array TriLowerIdx(int size)
Computes indexes of lower triangular matrix.
static af::array ScaledDistance(const af::array &inX1, const af::array &inX2, const af::array &inLengtScale)
Scaled distance.
static Scalar LogDet(af::array inA)
Log determinant of the input matrix.
static af::array SortRows(af::array inA)
Sort rows.
static Scalar SquareEuclidean(const af::array &a)
Gets the Square Euclidean norm for two vectors.
static af::array ReadTXT(std::string filename, char delimiter=' ')
Loads an array from a text file.
static af::array TriUpperIdx(int size, int dimension=0)
Computes indexes of upper triangular matrix.
static af::array SolveQR(const af::array &A, const af::array &b)
Linear solve usingQR decomposition.
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.
static af::array DiagIdx(int size)
Indexes of matrix diagonal.
static af::array CorrelationCoefficients(const af::array &inX, const af::array &inY=af::array())
Correlation coefficients.
static bool WriteTXT(const af::array &data, std::string filename, char delimiter=' ')
Writes an array to a text file.
static af::array Euclidean(const af::array &a, const af::array &b)
Gets the Euclidean norm for two vectors.
static af::array Join(const af::array &inA, const af::array &inB, int dimension=0)
Joins matrices and vectors along specific dimension.
static af::array NormalPDF(const af::array &inX, const af::array &inMu=af::array(), const af::array &inSigma=af::array())
Normal probability density function.
static af::array SquareDistance(const af::array &inX1, const af::array &inX2)
Gets standardized Square Euclidean distance.
static Scalar Euclidean(const af::array &a)
Gets the Euclidean norm for a vector.
static af::array Covariance(const af::array &M)
Covariance.
static af::array UnscaledDistance(const af::array &inX1, const af::array &inX2)
Unscaled distance.
static af::array PDInverse(const af::array &inA)
Computes the pseudo inverse of a matrix.
static af::array JitChol(const af::array &inA)
Cholesky decomposition.