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

FgIKernel.h
1
11#pragma once
12
13#include <NeMachineLearningLib.h>
14#include <MachineLearning/CommonUtil.h>
15
16 namespace NeuralEngine
17{
18 namespace MachineLearning
19 {
20 enum KernelType
21 {
22 eLinearKernel = 0,
23 eRBFKernel = 1,
24 eCompoundKernel = 2,
25 eTensorKernel = 3,
26 eWhiteKernel = 4,
27 eRBFAccelerationKernel = 5,
28 eLinearAccelerationKernel = 6,
29 eARDKernel = 7,
30 eStyleKernel = 8,
31 eInterKernel = 9
32 };
33
34 template<typename Scalar>
35 class NE_IMPEXP IKernel
36 {
37 public:
38
47 IKernel(KernelType type, int numParameters);
48
54 virtual ~IKernel();
55
63 virtual int GetNumParameter();
64
72 virtual KernelType GetKernelType();
73
83 virtual void ComputeKernelMatrix(const af::array& inX1, const af::array& inX2, af::array& outMatrix) = 0;
84
93 virtual void ComputeDiagonal(const af::array& inX, af::array& outDiagonal) = 0;
94
110 virtual void LogLikGradientX(const af::array& inX, const af::array& indL_dK, af::array& outdL_dX) = 0;
111
124 virtual void LogLikGradientX(const af::array& inXu, const af::array& indL_dKuu, const af::array& inX,
125 const af::array& indL_dKuf, af::array& outdL_dXu, af::array& outdL_dX) = 0;
126
137 virtual void LogLikGradientX(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dX) { };
138
149 virtual void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dParam) = 0;
150
161 virtual void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dParam, const af::array* dlogZ_dv) { };
162
163 virtual void LogLikGradientCompundKfu(const af::array& indL_dKfu, const af::array& inX, const af::array& inXu,
164 af::array* outdL_dParam, af::array* outdL_dXu, const af::array* dlogZ_dv = nullptr, af::array* outdL_dX = nullptr) { };
165
166 virtual void LogGradientCompoundKuu(const af::array& inXu, const af::array& inCovDiag,
167 af::array* outdL_dParam, af::array* outdL_dXu) { };
168
179 virtual void GradX(const af::array& inX1, const af::array& inX2, int q, af::array& outdK_dX) = 0;
180
189 virtual void DiagGradX(const af::array& inX, af::array& outDiagdK_dX) = 0;
190
200 virtual void DiagGradParam(const af::array& inX, const af::array& inCovDiag, af::array& outDiagdK_dParam) = 0;
201
209 virtual void SetParameters(const af::array& param) = 0;
210
218 virtual void SetLogParameters(const af::array& param) { };
219
227 virtual af::array GetParameters() = 0;
228
236 virtual af::array GetLogParameters() { return 0; };
237
248 virtual void InitParameters(Scalar inMedian) { };
249
253
270 virtual void ComputePsiStatistics(const af::array& inXu, const af::array& inMu, const af::array& inS,
271 af::array& outPsi0, af::array& outPsi1, af::array& outPsi2);
272
291 virtual void PsiDerivatives(const af::array& indL_dPsi0, const af::array& inPsi1, const af::array& indL_dPsi1, const af::array& inPsi2, const af::array& indL_dPsi2,
292 const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu,
293 af::array& outdL_dMu, af::array& outdL_dS, const af::array* dlogZ_dv = nullptr);
294
295 /*virtual void Psi1Derivative(const af::array& inPsi1, const af::array& indL_dPsi1, const af::array& inXu, const af::array& inMu,
296 const af::array& inS, af::array& outdL_dParam, af::array& outdL_dZ, af::array& outdL_dMu, af::array& outdL_dS) = 0;*/
297
298 protected:
304 IKernel() { }
305
306 KernelType eType;
307 int iNumParam;
308
309 af::dtype m_dType;
310
311 // Gauss-Hermite parameters
312 Scalar sDegree;
313 af::array afGHx;
314 af::array afGHw;
315 af::array afXs;
316 bool bCacheK;
317
318 private:
319 friend class boost::serialization::access;
320
321 template<class Archive>
322 void serialize(Archive& ar, unsigned int version)
323 {
324 ar& BOOST_SERIALIZATION_NVP(eType);
325 ar& BOOST_SERIALIZATION_NVP(iNumParam);
326 ar& BOOST_SERIALIZATION_NVP(m_dType);
327 }
328 };
329 }
330}
NeuralEngine::MachineLearning::IKernel
Definition: FgIKernel.h:36
NeuralEngine::MachineLearning::IKernel::SetParameters
virtual void SetParameters(const af::array &param)=0
Sets the parameters.
NeuralEngine::MachineLearning::IKernel::ComputeKernelMatrix
virtual void ComputeKernelMatrix(const af::array &inX1, const af::array &inX2, af::array &outMatrix)=0
Computes the kernel matrix of the kernel.
NeuralEngine::MachineLearning::IKernel::LogLikGradientX
virtual void LogLikGradientX(const af::array &inX, const af::array &indL_dK, af::array &outdL_dX)=0
Computes dL/dX for full fit GP.
NeuralEngine::MachineLearning::IKernel::IKernel
IKernel(KernelType type, int numParameters)
Constructor.
NeuralEngine::MachineLearning::IKernel::LogLikGradientParam
virtual void LogLikGradientParam(const af::array &inX1, const af::array &inX2, const af::array &indL_dK, af::array &outdL_dParam, const af::array *dlogZ_dv)
Computes the gradient of LL w.r.t. the kernel parameters.
Definition: FgIKernel.h:161
NeuralEngine::MachineLearning::IKernel::DiagGradX
virtual void DiagGradX(const af::array &inX, af::array &outDiagdK_dX)=0
Derivative of diagonal elemts of K w.r.t X.
NeuralEngine::MachineLearning::IKernel::LogLikGradientX
virtual void LogLikGradientX(const af::array &inX1, const af::array &inX2, const af::array &indL_dK, af::array &outdL_dX)
Computes dL / dX for sparse approximation GP.
Definition: FgIKernel.h:137
NeuralEngine::MachineLearning::IKernel::InitParameters
virtual void InitParameters(Scalar inMedian)
Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$.
Definition: FgIKernel.h:248
NeuralEngine::MachineLearning::IKernel::SetLogParameters
virtual void SetLogParameters(const af::array &param)
Sets log parameters.
Definition: FgIKernel.h:218
NeuralEngine::MachineLearning::IKernel::ComputePsiStatistics
virtual void ComputePsiStatistics(const af::array &inXu, const af::array &inMu, const af::array &inS, af::array &outPsi0, af::array &outPsi1, af::array &outPsi2)
PSI statistics.
NeuralEngine::MachineLearning::IKernel::GetLogParameters
virtual af::array GetLogParameters()
Gets log parameters.
Definition: FgIKernel.h:236
NeuralEngine::MachineLearning::IKernel::IKernel
IKernel()
Default constructor.
Definition: FgIKernel.h:304
NeuralEngine::MachineLearning::IKernel::LogLikGradientParam
virtual void LogLikGradientParam(const af::array &inX1, const af::array &inX2, const af::array &indL_dK, af::array &outdL_dParam)=0
Computes the gradient of LL w.r.t. the kernel parameters.
NeuralEngine::MachineLearning::IKernel::LogLikGradientX
virtual void LogLikGradientX(const af::array &inXu, const af::array &indL_dKuu, const af::array &inX, const af::array &indL_dKuf, af::array &outdL_dXu, af::array &outdL_dX)=0
Computes dL / dX and dL / dXu for sparse approximation GP.
NeuralEngine::MachineLearning::IKernel::GetNumParameter
virtual int GetNumParameter()
Gets number of parametes of the kernel.
NeuralEngine::MachineLearning::IKernel::GetParameters
virtual af::array GetParameters()=0
Gets the parameters.
NeuralEngine::MachineLearning::IKernel::GetKernelType
virtual KernelType GetKernelType()
Gets kernel type.
NeuralEngine::MachineLearning::IKernel::PsiDerivatives
virtual void PsiDerivatives(const af::array &indL_dPsi0, const af::array &inPsi1, const af::array &indL_dPsi1, const af::array &inPsi2, const af::array &indL_dPsi2, const af::array &inXu, const af::array &inMu, const af::array &inS, af::array &outdL_dParam, af::array &outdL_dXu, af::array &outdL_dMu, af::array &outdL_dS, const af::array *dlogZ_dv=nullptr)
Psi derivatives.
NeuralEngine::MachineLearning::IKernel::GradX
virtual void GradX(const af::array &inX1, const af::array &inX2, int q, af::array &outdK_dX)=0
Computes dK/dX.
NeuralEngine::MachineLearning::IKernel::~IKernel
virtual ~IKernel()
Destructor.
NeuralEngine::MachineLearning::IKernel::DiagGradParam
virtual void DiagGradParam(const af::array &inX, const af::array &inCovDiag, af::array &outDiagdK_dParam)=0
Derivative of diagonal elemts of K w.r.t kernel parameters.
NeuralEngine::MachineLearning::IKernel::ComputeDiagonal
virtual void ComputeDiagonal(const af::array &inX, af::array &outDiagonal)=0
Calculates only diagonal elements of K.
Scalar
NeuralEngine
Definition: NeArray2.h:18