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

FgTensorKernel.h
1
11#pragma once
12
13#include <MachineLearning/FgIKernel.h>
14
15 namespace NeuralEngine
16{
17 namespace MachineLearning
18 {
42 template<typename Scalar>
43 class NE_IMPEXP TensorKernel : public IKernel<Scalar>
44 {
45
46 public:
52 TensorKernel();
53
59 ~TensorKernel();
60
72 void AddKernel(IKernel<Scalar>* kernel, const af::array index);
73
83 void ComputeKernelMatrix(const af::array& inX1, const af::array& inX2, af::array& outMatrix);
84
93 void ComputeDiagonal(const af::array& inX, af::array& outDiagonal);
94
110 void LogLikGradientX(const af::array& inX, const af::array& indL_dK, af::array& outdL_dX);
111
124 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);
125
136 virtual void LogLikGradientX(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dX) override;
137
148 void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK, af::array& outdL_dParam);
149
160 virtual void LogLikGradientParam(const af::array& inX1, const af::array& inX2, const af::array& indL_dK,
161 af::array& outdL_dParam, const af::array* dlogZ_dv) override;
162
173 void GradX(const af::array& inX1, const af::array& inX2, int q, af::array& outdK_dX);
174
183 void DiagGradX(const af::array& inX, af::array& outDiagdK_dX);
184
194 void DiagGradParam(const af::array& inX, const af::array& inCovDiag, af::array& outDiagdK_dParam);
195
203 void SetParameters(const af::array& param);
204
212 virtual void SetLogParameters(const af::array& param) override;
213
221 virtual af::array GetLogParameters() override;
222
230 af::array GetParameters();
231
242 virtual void InitParameters(Scalar inMedian) override;
243
244 virtual void LogLikGradientCompundKfu(const af::array& indL_dKfu, const af::array& inX, const af::array& inXu,
245 af::array* outdL_dParam, af::array* outdL_dXu, const af::array* dlogZ_dv = nullptr, af::array* outdL_dX = nullptr) override;
246
247 virtual void LogGradientCompoundKuu(const af::array& inXu, const af::array& inCovDiag,
248 af::array* outdL_dParam, af::array* outdL_dXu) override;
249
253
266 void ComputePsiStatistics(const af::array& inXu, const af::array& inMu, const af::array& inS,
267 af::array& outPsi0, af::array& outPsi1, af::array& outPsi2) override;
268
286 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,
287 const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu,
288 af::array& outdL_dMu, af::array& outdL_dS, const af::array* dlogZ_dv = nullptr) override;
289
290 protected:
301 //void ComputePsi1(const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outPsi1);
302
313 //void ComputePsi2(const af::array& inXu, const af::array& inMu, const af::array& inS, af::array& outPsi2);
314
330 //void Psi1Derivative(const af::array& inPsi1, const af::array& indL_dPsi1, const af::array& inXu, const af::array& inMu,
331 // const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu, af::array& outdL_dMu, af::array& outdL_dS);
332
348 //void Psi2Derivative(const af::array& inPsi2, const af::array& indL_dPsi2, const af::array& inXu, const af::array& inMu,
349 // const af::array& inS, af::array& outdL_dParam, af::array& outdL_dXu, af::array& outdL_dMu, af::array& outdL_dS);
350
351 private:
352 void DiagGradParamTensor(const af::array& inX, af::array& indL_dK);
353
354 std::vector<IKernel<Scalar>*> KSlash(int kernelIndex);
355
356 friend class boost::serialization::access;
357
358 template<class Archive>
359 void serialize(Archive& ar, unsigned int version)
360 {
361 ar & boost::serialization::base_object<IKernel<Scalar>>(*this);
362 //ar& boost::serialization::make_nvp("IKernel", boost::serialization::base_object<IKernel<Scalar>>(*this));
363 ar& BOOST_SERIALIZATION_NVP(vKernel);
364 ar& BOOST_SERIALIZATION_NVP(vIndex);
365 }
366
367 //af::array afParameter; // []{variance, dInvScale}
368 std::vector<IKernel<Scalar>*> vKernel;
369 std::vector<af::array> vIndex;
370 };
371 }
372}
NeuralEngine::MachineLearning::IKernel
Definition: FgIKernel.h:36
NeuralEngine::MachineLearning::TensorKernel
Tensor kernel function.
Definition: FgTensorKernel.h:44
NeuralEngine::MachineLearning::TensorKernel::~TensorKernel
~TensorKernel()
Destructor.
NeuralEngine::MachineLearning::TensorKernel::AddKernel
void AddKernel(IKernel< Scalar > *kernel, const af::array index)
Adds a kernel object and the corresponding column index of X for computation.
NeuralEngine::MachineLearning::TensorKernel::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::TensorKernel::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::TensorKernel::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::TensorKernel::DiagGradX
void DiagGradX(const af::array &inX, af::array &outDiagdK_dX)
Derivative of diagonal elemts of K w.r.t X.
NeuralEngine::MachineLearning::TensorKernel::GetParameters
af::array GetParameters()
Gets the parameters.
NeuralEngine::MachineLearning::TensorKernel::SetLogParameters
virtual void SetLogParameters(const af::array &param) override
Sets log parameters.
NeuralEngine::MachineLearning::TensorKernel::SetParameters
void SetParameters(const af::array &param)
Sets the parameters.
NeuralEngine::MachineLearning::TensorKernel::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::TensorKernel::ComputeKernelMatrix
void ComputeKernelMatrix(const af::array &inX1, const af::array &inX2, af::array &outMatrix)
Computes the kernel matrix of the kernel.
NeuralEngine::MachineLearning::TensorKernel::GradX
void GradX(const af::array &inX1, const af::array &inX2, int q, af::array &outdK_dX)
Computes dK/dX.
NeuralEngine::MachineLearning::TensorKernel::GetLogParameters
virtual af::array GetLogParameters() override
Gets log parameters.
NeuralEngine::MachineLearning::TensorKernel::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::TensorKernel::InitParameters
virtual void InitParameters(Scalar inMedian) override
Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$.
NeuralEngine::MachineLearning::TensorKernel::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 computation.
NeuralEngine::MachineLearning::TensorKernel::TensorKernel
TensorKernel()
Default constructor.
NeuralEngine::MachineLearning::TensorKernel::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::TensorKernel::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::TensorKernel::ComputeDiagonal
void ComputeDiagonal(const af::array &inX, af::array &outDiagonal)
Calculates only diagonal elements of K.
Scalar
NeuralEngine
Definition: NeArray2.h:18