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