NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
NeuralEngine::MachineLearning::TensorKernel< Scalar > Class Template Reference

Tensor kernel function. More...

#include <FgTensorKernel.h>

Inheritance diagram for NeuralEngine::MachineLearning::TensorKernel< Scalar >:
Collaboration diagram for NeuralEngine::MachineLearning::TensorKernel< Scalar >:

Public Member Functions

 TensorKernel ()
 Default constructor. More...
 
 ~TensorKernel ()
 Destructor. More...
 
void AddKernel (IKernel< Scalar > *kernel, const af::array index)
 
Adds a kernel object and the corresponding column index of X for computation. More...
 
void ComputeKernelMatrix (const af::array &inX1, const af::array &inX2, af::array &outMatrix)
 Computes the kernel matrix of the kernel. More...
 
void ComputeDiagonal (const af::array &inX, af::array &outDiagonal)
 Calculates only diagonal elements of K. More...
 
void LogLikGradientX (const af::array &inX, const af::array &indL_dK, af::array &outdL_dX)
 Computes dL/dX for full fit GP. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void GradX (const af::array &inX1, const af::array &inX2, int q, af::array &outdK_dX)
 Computes dK/dX. More...
 
void DiagGradX (const af::array &inX, af::array &outDiagdK_dX)
 Derivative of diagonal elemts of K w.r.t X. More...
 
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. More...
 
void SetParameters (const af::array &param)
 Sets the parameters. More...
 
virtual void SetLogParameters (const af::array &param) override
 Sets log parameters. More...
 
virtual af::array GetLogParameters () override
 Gets log parameters. More...
 
af::array GetParameters ()
 Gets the parameters. More...
 
virtual void InitParameters (Scalar inMedian) override
 
Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$. More...
 
virtual void LogLikGradientCompundKfu (const af::array &indL_dKfu, const af::array &inX, const af::array &inXu, af::array *outdL_dParam, af::array *outdL_dXu, const af::array *dlogZ_dv=nullptr, af::array *outdL_dX=nullptr) override
 
virtual void LogGradientCompoundKuu (const af::array &inXu, const af::array &inCovDiag, af::array *outdL_dParam, af::array *outdL_dXu) override
 
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. More...
 
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. More...
 
- Public Member Functions inherited from NeuralEngine::MachineLearning::IKernel< Scalar >
 IKernel (KernelType type, int numParameters)
 Constructor. More...
 
virtual ~IKernel ()
 Destructor. More...
 
virtual int GetNumParameter ()
 Gets number of parametes of the kernel. More...
 
virtual KernelType GetKernelType ()
 Gets kernel type. More...
 
virtual void ComputeKernelMatrix (const af::array &inX1, const af::array &inX2, af::array &outMatrix)=0
 Computes the kernel matrix of the kernel. More...
 
virtual void ComputeDiagonal (const af::array &inX, af::array &outDiagonal)=0
 Calculates only diagonal elements of K. More...
 
virtual void LogLikGradientX (const af::array &inX, const af::array &indL_dK, af::array &outdL_dX)=0
 Computes dL/dX for full fit GP. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual void LogLikGradientCompundKfu (const af::array &indL_dKfu, const af::array &inX, const af::array &inXu, af::array *outdL_dParam, af::array *outdL_dXu, const af::array *dlogZ_dv=nullptr, af::array *outdL_dX=nullptr)
 
virtual void LogGradientCompoundKuu (const af::array &inXu, const af::array &inCovDiag, af::array *outdL_dParam, af::array *outdL_dXu)
 
virtual void GradX (const af::array &inX1, const af::array &inX2, int q, af::array &outdK_dX)=0
 Computes dK/dX. More...
 
virtual void DiagGradX (const af::array &inX, af::array &outDiagdK_dX)=0
 Derivative of diagonal elemts of K w.r.t X. More...
 
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. More...
 
virtual void SetParameters (const af::array &param)=0
 Sets the parameters. More...
 
virtual void SetLogParameters (const af::array &param)
 Sets log parameters. More...
 
virtual af::array GetParameters ()=0
 Gets the parameters. More...
 
virtual af::array GetLogParameters ()
 Gets log parameters. More...
 
virtual void InitParameters (Scalar inMedian)
 
Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$. More...
 
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. More...
 
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. More...
 

Private Member Functions

void DiagGradParamTensor (const af::array &inX, af::array &indL_dK)
 
std::vector< IKernel< Scalar > * > KSlash (int kernelIndex)
 
template<class Archive >
void serialize (Archive &ar, unsigned int version)
 

Private Attributes

std::vector< IKernel< Scalar > * > vKernel
 
std::vector< af::array > vIndex
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Protected Member Functions inherited from NeuralEngine::MachineLearning::IKernel< Scalar >
 IKernel ()
 Default constructor. More...
 
- Protected Attributes inherited from NeuralEngine::MachineLearning::IKernel< Scalar >
KernelType eType
 
int iNumParam
 
af::dtype m_dType
 
Scalar sDegree
 
af::array afGHx
 
af::array afGHw
 
af::array afXs
 
bool bCacheK
 

Detailed Description

template<typename Scalar>
class NeuralEngine::MachineLearning::TensorKernel< Scalar >

Tensor kernel function.

Kernel function constructed as follows:

\[k(\mathbf{x}, \mathbf{x}') = \prod_m k_m(\mathbf{x}, \mathbf{x}').\]

Elementwise multiplication of kernel matrices constructed from different kernel functions.

Example, multiplicate noise term to a rbf kernel function,

\[k(\mathbf{x}, \mathbf{x}') = \gamma_1 \exp\left(-\frac{1}{\gamma_2} | \mathbf{x} - \mathbf{x}'|^2\right)\beta^{-1} \delta_{\mathbf{x}, \mathbf{x}'},\]

can be constructed with a Tensor kernel as follows,

\[k_{comp}(\mathbf{x}, \mathbf{x}') = k_{rbf}(\mathbf{x}, \mathbf{x}') k_{white}(\mathbf{x}, \mathbf{x}').\]

Admin, 5/24/2017.

Definition at line 43 of file FgTensorKernel.h.

Constructor & Destructor Documentation

◆ TensorKernel()

template<typename Scalar >
NeuralEngine::MachineLearning::TensorKernel< Scalar >::TensorKernel ( )

Default constructor.

Admin, 5/24/2017.

◆ ~TensorKernel()

Destructor.

Admin, 5/24/2017.

Member Function Documentation

◆ AddKernel()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::AddKernel ( IKernel< Scalar > *  kernel,
const af::array  index 
)


Adds a kernel object and the corresponding column index of X for computation.

Admin, 5/31/2017.

Parameters
kernel[in,out] If non-null, the kernel.
indexZero-based index of the.

◆ ComputeKernelMatrix()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::ComputeKernelMatrix ( const af::array &  inX1,
const af::array &  inX2,
af::array &  outMatrix 
)
virtual

Computes the kernel matrix of the kernel.

Admin, 5/23/2017.

Parameters
inX1[in,out] First n times q matrix of latent points.
inX2[in,out] Second m times q matrix of latent points (X').
outMatrix[in,out] Resulting kernel matrix.< / param>

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ ComputeDiagonal()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::ComputeDiagonal ( const af::array &  inX,
af::array &  outDiagonal 
)
virtual

Calculates only diagonal elements of K.

Admin, 5/24/2017.

Parameters
inX[in,out] Nxq matrix X.
outDiagonal[in,out] The out diagonal.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientX() [1/3]

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogLikGradientX ( const af::array &  inX,
const af::array &  indL_dK,
af::array &  outdL_dX 
)
virtual

Computes dL/dX for full fit GP.

Admin, 5/23/2017.

Returns
The method returns the gradients of the latent points of type ILArray<Scalar>.
Parameters
inX[in,out] Nxq Matrix of latent points.
indL_dK[in,out] Derivative of the loglikelihood w.r.t kernel matrix K.
outdL_dX[in,out] Derivative of the loglikelihood w.r.t latent points.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientX() [2/3]

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::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 
)
virtual

Computes dL / dX and dL / dXu for sparse approximation GP.

Admin, 5/23/2017.

Parameters
inXu[in,out] kxq Matrix of latent subset points.
indL_dKuu[in,out] Derivative of the loglikelihood w.r.t subset kernel matrix Kuu.
inX[in,out] Nxq Matrix of latent points.
indL_dKuf[in,out] Derivative of the loglikelihood w.r.t the kernel matrix K.
outdL_dXu[in,out] Derivative of the loglikelihood w.r.t latent subset points Xu.
outdL_dX[in,out] Derivative of the loglikelihood w.r.t latent points X.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientX() [3/3]

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogLikGradientX ( const af::array &  inX1,
const af::array &  inX2,
const af::array &  indL_dK,
af::array &  outdL_dX 
)
overridevirtual

Computes dL / dX for sparse approximation GP.

Hmetal T, 25/11/2020.

Parameters
inX1The first latent points.
inX2The second latent points.
indL_dKThe derivative dL / dK.
outdL_dX[in,out] The derivative dL / dX.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientParam() [1/2]

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogLikGradientParam ( const af::array &  inX1,
const af::array &  inX2,
const af::array &  indL_dK,
af::array &  outdL_dParam 
)
virtual

Computes the gradient of the kernel parameters.

Admin, 5/23/2017.

Parameters
indL_dK[in,out] Derivative of the loglikelihood w.r.t the kernel matrix K.
outdL_dParam[in,out] Gradient of kernel parameters.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientParam() [2/2]

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogLikGradientParam ( const af::array &  inX1,
const af::array &  inX2,
const af::array &  indL_dK,
af::array &  outdL_dParam,
const af::array *  dlogZ_dv 
)
overridevirtual

Computes the gradient of LL w.r.t. the kernel parameters.

Admin, 5/23/2017.

Parameters
indL_dK[in,out] Derivative of the loglikelihood w.r.t the kernel matrix K.
outdL_dParam[in,out] Gradient of kernel parameters.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ GradX()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::GradX ( const af::array &  inX1,
const af::array &  inX2,
int  q,
af::array &  outdK_dX 
)
virtual

Computes dK/dX.

Admin, 5/23/2017.

Parameters
inX1[in,out] First n times q matrix of latent points.
inX2[in,out] Second n times q matrix of latent points (X').
qThe latent dimension to process.
outdK_dX[in,out] dK/dX.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ DiagGradX()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::DiagGradX ( const af::array &  inX,
af::array &  outDiagdK_dX 
)
virtual

Derivative of diagonal elemts of K w.r.t X.

Admin, 5/23/2017.

Parameters
inX[in,out] The in x coordinate.
outDiagdK_dX[in,out] Derivative of diagonal elemts of K w.r.t X.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ DiagGradParam()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::DiagGradParam ( const af::array &  inX,
const af::array &  inCovDiag,
af::array &  outDiagdK_dParam 
)
virtual

Derivative of diagonal elemts of K w.r.t kernel parameters.

Admin, 5/23/2017.

Parameters
inX[in,out] Nxq matrix of Latent points X.
inCovDiag[in,out] Diagonal of kernel matrix K.
outDiagdK_dParam[in,out] Derivative of diagonal elemts of K w.r.t kernel parameters.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ SetParameters()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::SetParameters ( const af::array &  param)
virtual

Sets the parameters.

, 26.06.2018.

Parameters
paramThe parameter.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ SetLogParameters()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::SetLogParameters ( const af::array &  param)
overridevirtual

Sets log parameters.

Hmetal T, 15/07/2019.

Parameters
paramThe parameter.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ GetLogParameters()

template<typename Scalar >
virtual af::array NeuralEngine::MachineLearning::TensorKernel< Scalar >::GetLogParameters ( )
overridevirtual

Gets log parameters.

Hmetal T, 15/07/2019.

Returns
The log parameters.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ GetParameters()

template<typename Scalar >
af::array NeuralEngine::MachineLearning::TensorKernel< Scalar >::GetParameters ( )
virtual

Gets the parameters.

, 26.06.2018.

Returns
The parameters.

Implements NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ InitParameters()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::InitParameters ( Scalar  inMedian)
overridevirtual


Initializes the parameters based on the median of the distances of /f$\mathbf{X}/f$.

Hmetal T, 06/11/2020.

Parameters
inMedianThe in median.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ LogLikGradientCompundKfu()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogLikGradientCompundKfu ( const af::array &  indL_dKfu,
const af::array &  inX,
const af::array &  inXu,
af::array *  outdL_dParam,
af::array *  outdL_dXu,
const af::array *  dlogZ_dv = nullptr,
af::array *  outdL_dX = nullptr 
)
overridevirtual

◆ LogGradientCompoundKuu()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::TensorKernel< Scalar >::LogGradientCompoundKuu ( const af::array &  inXu,
const af::array &  inCovDiag,
af::array *  outdL_dParam,
af::array *  outdL_dXu 
)
overridevirtual

◆ ComputePsiStatistics()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::ComputePsiStatistics ( const af::array &  inXu,
const af::array &  inMu,
const af::array &  inS,
af::array &  outPsi0,
af::array &  outPsi1,
af::array &  outPsi2 
)
overridevirtual

PSI statistics computation.

Hmetal T, 15/07/2019.

Parameters
inXuInducing points.
inMuPosterior mean.
inSPosterior covariance.
outPsi0[in,out] Psi0.
outPsi1[in,out] Psi1.
outPsi2[in,out] Psi2.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ PsiDerivatives()

template<typename Scalar >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::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 
)
overridevirtual

Parameter and variable derivatives w.r.t. all Psi statistics.

Hmetal T, 15/07/2019.

Parameters
inPsi1Psi1.
indL_dPsi1Psi1 derivative w.r.t. objective.
inPsi1Psi2.
indL_dPsi1Psi2 derivative w.r.t. objective.
inXuInducing points.
inMuPosterior mean.
inSPosterior covariance.
outdL_dParam[in,out] Kernel parameter derivatives w.r.t. Psi statistics.
outdL_dXu[in,out] Inducing inputs derivatives w.r.t. Psi statistics.
outdL_dMu[in,out] Posterior mean derivatives w.r.t. Psi statistics.
outdL_dS[in,out] Posterior covariance derivatives w.r.t. Psi statistics.

Reimplemented from NeuralEngine::MachineLearning::IKernel< Scalar >.

◆ serialize()

template<typename Scalar >
template<class Archive >
void NeuralEngine::MachineLearning::TensorKernel< Scalar >::serialize ( Archive &  ar,
unsigned int  version 
)
inlineprivate

Definition at line 359 of file FgTensorKernel.h.

Friends And Related Function Documentation

◆ boost::serialization::access

template<typename Scalar >
friend class boost::serialization::access
friend

Definition at line 356 of file FgTensorKernel.h.

Member Data Documentation

◆ vKernel

template<typename Scalar >
std::vector<IKernel<Scalar>*> NeuralEngine::MachineLearning::TensorKernel< Scalar >::vKernel
private

Definition at line 368 of file FgTensorKernel.h.

◆ vIndex

template<typename Scalar >
std::vector<af::array> NeuralEngine::MachineLearning::TensorKernel< Scalar >::vIndex
private

Definition at line 369 of file FgTensorKernel.h.


The documentation for this class was generated from the following file: