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

FgARDKernel.h
1
11#pragma once
12
13
14#include <MachineLearning/FgIKernel.h>
15
16 namespace NeuralEngine
17{
18 namespace MachineLearning
19 {
37 template<typename Scalar>
38 class NE_IMPEXP ARDKernel : public IKernel<Scalar>
39 {
40 public:
41
49 ARDKernel(int numDim);
50
56 ~ARDKernel();
57
67 void ComputeKernelMatrix(const af::array& inX1, const af::array& inX2, af::array& outMatrix);
68
77 void ComputeDiagonal(const af::array& inX, af::array& outDiagonal);
78
94 void LogLikGradientX(const af::array& inX, const af::array& indL_dK, af::array& outdL_dX);
95
108 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);
109
120 virtual void LogLikGradientX(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dX) override;
121
132 void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dParam);
133
144 virtual void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK,
145 af::array& outdL_dParam, const af::array* dlogZ_dv) override;
146
157 void GradX(const af::array& inX1, const af::array& inX2, int q, af::array& outdK_dX);
158
167 void DiagGradX(const af::array& inX, af::array& outDiagdK_dX);
168
178 void DiagGradParam(const af::array& inX, const af::array& inCovDiag, af::array& outDiagdK_dParam);
179
180 virtual void LogLikGradientCompundKfu(const af::array& indL_dKfu, const af::array& inX, const af::array& inXu,
181 af::array* outdL_dParam, af::array* outdL_dXu, const af::array* dlogZ_dv = nullptr, af::array* outdL_dX = nullptr) override;
182
183 virtual void LogGradientCompoundKuu(const af::array& inXu, const af::array& inCovDiag,
184 af::array* outdL_dParam, af::array* outdL_dXu) override;
185
193 void SetParameters(const af::array& param);
194
202 af::array GetParameters();
203
211 virtual void SetLogParameters(const af::array& param) override;
212
220 virtual af::array GetLogParameters() override;
221
232 virtual void InitParameters(Scalar inMedian) override;
233
237
250 void ComputePsiStatistics(const af::array& inXu, const af::array& inMu, const af::array& inS,
251 af::array& outPsi0, af::array& outPsi1, af::array& outPsi2) override;
252
253 /*void ComputePsiStatisticsWeave(const af::array& inXu, const af::array& inXmean, const af::array& inXvar,
254 af::array& outPsi0, af::array& outPsi1, af::array& outPsi2) override;*/
255
273 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,
274 const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu,
275 af::array& outdL_dMu, af::array& outdL_dS, const af::array* dlogZ_dv = nullptr) override;
276
277 protected:
283 ARDKernel() { }
284
295 void ComputePsi1(const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outPsi1);
296
307 void ComputePsi2(const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outPsi2);
308
324 void Psi1Derivative(const af::array& inPsi1, const af::array& indL_dPsi1, const af::array& inXu, const af::array& inMu,
325 const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu, af::array& outdL_dMu, af::array& outdL_dS);
326
342 void Psi2Derivative(const af::array& inPsi2, const af::array& indL_dPsi2, const af::array& inXu, const af::array& inMu,
343 const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu, af::array& outdL_dMu, af::array& outdL_dS);
344 private:
345 Scalar dVariance;
346 af::array dInvScale;
347
348 friend class boost::serialization::access;
349
350 template<class Archive>
351 void serialize(Archive& ar, unsigned int version)
352 {
353 ar & boost::serialization::base_object<IKernel<Scalar>>(*this);
354 //ar& boost::serialization::make_nvp("IKernel", boost::serialization::base_object<IKernel<Scalar>>(*this));
355 ar& BOOST_SERIALIZATION_NVP(dVariance);
356 ar& BOOST_SERIALIZATION_NVP(dInvScale);
357 }
358 };
359 }
360}
NeuralEngine::MachineLearning::ARDKernel
Automatic Relevance Determination kernel.
Definition: FgARDKernel.h:39
NeuralEngine::MachineLearning::ARDKernel::GradX
void GradX(const af::array &inX1, const af::array &inX2, int q, af::array &outdK_dX)
Computes dK/dX.
NeuralEngine::MachineLearning::ARDKernel::ComputePsi1
void ComputePsi1(const af::array &inXu, const af::array &inMu, const af::array &inS, af::array &outPsi1)
Calculates the psi1.
NeuralEngine::MachineLearning::ARDKernel::PsiDerivatives
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) override
Parameter and variable derivatives w.r.t. all Psi statistics.
NeuralEngine::MachineLearning::ARDKernel::LogLikGradientX
virtual void LogLikGradientX(const af::array &inX1, const af::array &inX2, const af::array &indL_dK, af::array &outdL_dX) override
Computes dL / dX for sparse approximation GP.
NeuralEngine::MachineLearning::ARDKernel::~ARDKernel
~ARDKernel()
Destructor.
NeuralEngine::MachineLearning::ARDKernel::ComputePsiStatistics
void ComputePsiStatistics(const af::array &inXu, const af::array &inMu, const af::array &inS, af::array &outPsi0, af::array &outPsi1, af::array &outPsi2) override
PSI statistics.
NeuralEngine::MachineLearning::ARDKernel::LogLikGradientX
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)
Computes dL / dX and dL / dXu for sparse approximation GP.
NeuralEngine::MachineLearning::ARDKernel::GetLogParameters
virtual af::array GetLogParameters() override
Gets log parameters.
NeuralEngine::MachineLearning::ARDKernel::SetParameters
void SetParameters(const af::array &param)
Sets the parameters.
NeuralEngine::MachineLearning::ARDKernel::GetParameters
af::array GetParameters()
Gets the parameters.
NeuralEngine::MachineLearning::ARDKernel::SetLogParameters
virtual void SetLogParameters(const af::array &param) override
Sets log parameters.
NeuralEngine::MachineLearning::ARDKernel::ComputeDiagonal
void ComputeDiagonal(const af::array &inX, af::array &outDiagonal)
Calculates only diagonal elements of K.
NeuralEngine::MachineLearning::ARDKernel::ComputePsi2
void ComputePsi2(const af::array &inXu, const af::array &inMu, const af::array &inS, af::array &outPsi2)
Calculates the psi2.
NeuralEngine::MachineLearning::ARDKernel::ARDKernel
ARDKernel()
Default constructor.
Definition: FgARDKernel.h:283
NeuralEngine::MachineLearning::ARDKernel::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) override
Computes the gradient of LL w.r.t. the kernel parameters.
NeuralEngine::MachineLearning::ARDKernel::Psi1Derivative
void Psi1Derivative(const af::array &inPsi1, const af::array &indL_dPsi1, 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)
Parameter and variable derivatives w.r.t. Psi1.
NeuralEngine::MachineLearning::ARDKernel::ComputeKernelMatrix
void ComputeKernelMatrix(const af::array &inX1, const af::array &inX2, af::array &outMatrix)
Computes the kernel matrix of the kernel.
NeuralEngine::MachineLearning::ARDKernel::ARDKernel
ARDKernel(int numDim)
Constructor.
NeuralEngine::MachineLearning::ARDKernel::DiagGradParam
void DiagGradParam(const af::array &inX, const af::array &inCovDiag, af::array &outDiagdK_dParam)
Derivative of diagonal elemts of K w.r.t kernel parameters.
NeuralEngine::MachineLearning::ARDKernel::Psi2Derivative
void Psi2Derivative(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)
Parameter and variable derivatives w.r.t. Psi2.
NeuralEngine::MachineLearning::ARDKernel::LogLikGradientX
void LogLikGradientX(const af::array &inX, const af::array &indL_dK, af::array &outdL_dX)
Computes dL/dX for full fit GP.
NeuralEngine::MachineLearning::ARDKernel::DiagGradX
void DiagGradX(const af::array &inX, af::array &outDiagdK_dX)
Derivative of diagonal elemts of K w.r.t X.
NeuralEngine::MachineLearning::ARDKernel::LogLikGradientParam
void LogLikGradientParam(const af::array &inX1, const af::array &inX2, const af::array &indL_dK, af::array &outdL_dParam)
Computes the gradient of the kernel parameters.
NeuralEngine::MachineLearning::ARDKernel::InitParameters
virtual void InitParameters(Scalar inMedian) override
Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$.
NeuralEngine::MachineLearning::IKernel
Definition: FgIKernel.h:36
Scalar
NeuralEngine
Definition: NeArray2.h:18