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

Sparse GP layer. More...

#include <FgPEPSparseGPLayer.h>

Inheritance diagram for NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >:
Collaboration diagram for NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >:

Public Member Functions

 SGPLayer (int numPoints, int numPseudos, int outputDim, int inputDim)
 Constructor. More...
 
virtual ~SGPLayer ()
 Destructor. More...
 
void ForwardPredictionCavity (af::array &mout, af::array &vout, af::array &n, af::array &mx, af::array *vx=nullptr, Scalar alpha=1.0)
 Forward prediction through cavity. More...
 
void BackpropGradientsReg (af::array &m, af::array &v, af::array &dlogZ_dm, af::array &dlogZ_dv, af::array &x, std::map< std::string, af::array > &grad_hyper, std::map< std::string, af::array > &grad_cav, Scalar alpha=1.0)
 Prediction of posterior function values. More...
 
void UpdateFactor (af::array &n, std::map< std::string, af::array > grad_cav, Scalar alpha, Scalar decay=0)
 Update step of PowerEP. More...
 
virtual void UpdateParameters () override
 Updates the parameters. More...
 
virtual void InitParameters (af::array *X=nullptr) override
 Initializes the parameters. More...
 
- Public Member Functions inherited from NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer< Scalar >
 SparseGPBaseLayer (int numPoints, int numPseudos, int outputDim, int inputDim)
 Constructor. More...
 
virtual ~SparseGPBaseLayer ()
 Destructor. More...
 
virtual void ForwardPredictionPost (const af::array *mx, const af::array *vx, af::array &mout, af::array &vout) override
 Forward prediction of posterior function values. More...
 
virtual void SampleFromPost (const af::array &inX, af::array &outfsample) override
 Samples from posterior. More...
 
void ComputeKuu ()
 Calculates the kernel matrix of pseudo inputs. More...
 
void ComputeKfu (const af::array &inX)
 Calculates the kernel matrix of inputes and pseudo inputs. More...
 
af::array GetPseudoInputs ()
 Gets pseudo inputs. More...
 
virtual int GetNumParameters () override
 Gets number of parameters to be optimized. More...
 
virtual void SetParameters (const af::array &param) override
 Sets the parameters for each optimization iteration. More...
 
virtual af::array GetParameters () override
 Gets the parameters for each optimization iteration. More...
 
virtual void FixInducing (bool isfixed)
 Set fixation for inducing inputs. More...
 
virtual void UpdateParameters () override
 Updates the parameters. More...
 
virtual void InitParameters (af::array *X=nullptr) override
 Initializes the parameters. More...
 
- Public Member Functions inherited from NeuralEngine::MachineLearning::GPModels::GPBaseLayer< Scalar >
 GPBaseLayer (int numPoints, int outputDim, int inputDim)
 Constructor. More...
 
virtual ~GPBaseLayer ()
 Destructor. More...
 
IKernel< Scalar > * GetKernel ()
 Gets the kernel function. More...
 
void SetKernel (IKernel< Scalar > *kern)
 Sets a kernel function. More...
 
virtual void InitParameters (af::array *X=nullptr)
 
virtual int GetNumParameters ()
 Gets number of parameters to be optimized. More...
 
virtual void SetParameters (const af::array &param)
 Sets the parameters for each optimization iteration. More...
 
virtual af::array GetParameters ()
 Gets the parameters for each optimization iteration. More...
 
virtual void ForwardPredictionPost (const af::array *mx, const af::array *vx, af::array &mout, af::array &vout)
 Forward prediction of posterior function values. More...
 
virtual void SampleFromPost (const af::array &inX, af::array &outfsample)
 Samples from posterior. More...
 
virtual void FixKernelParameters (bool isfixed)
 Sets fixation for hyperparameters. More...
 
virtual void UpdateParameters ()
 Updates the parameters. More...
 
virtual void SetDataSize (int length, int dimension) override
 Sets data size. More...
 
void SetStyles (std::map< std::string, Style< Scalar > > *styles)
 Sets the syles. More...
 
void SetLatentDimension (int q)
 Sets latent dimension. More...
 
- Public Member Functions inherited from NeuralEngine::MachineLearning::ILayer< Scalar >
 ILayer (LayerType type, int numPoints, int outputDim)
 Constructor. More...
 
virtual ~ILayer ()=default
 Destructor. More...
 
LayerType GetType ()
 Gets the layer type. More...
 
virtual int GetNumParameters ()=0
 Gets number of parameters to be optimized. More...
 
virtual void SetParameters (const af::array &param)=0
 Sets the parameters for each optimization iteration. More...
 
virtual af::array GetParameters ()=0
 Gets the parameters for each optimization iteration. More...
 
virtual void UpdateParameters ()=0
 Updates the parameters. More...
 
virtual void SetDataSize (int length, int dimension)
 Sets data size. More...
 

Protected Member Functions

 SGPLayer ()
 Default constructor. More...
 
void ForwardPredictionDeterministicPost (af::array &mx, af::array *mout, af::array *vout)
 
void ForwardPredictionDeterministicCavity (af::array &mout, af::array &vout, af::array &idx, af::array &mx, Scalar alpha=1.0)
 Forward prediction through deterministic cavity. More...
 
void ForwardPredictionRandomCavity (af::array &mout, af::array &vout, af::array &idx, af::array &mx, af::array &vx, Scalar alpha=1.0)
 Forward prediction through random cavity. More...
 
void ComputeCavity (af::array &idx, af::array &muhat, af::array &Suhat, af::array &T1uHat, af::array &T2uHat, Scalar alpha=1.0f)
 Calculates the cavity. More...
 
- Protected Member Functions inherited from NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer< Scalar >
 SparseGPBaseLayer ()
 Default constructor. More...
 
virtual void ReinitParameters () override
 Reinitializes the parameters. More...
 
virtual void ForwardPredictionDeterministicPost (const af::array &mx, af::array *mout, af::array *vout)
 Deterministic forward propagation through posterior. More...
 
virtual void ForwardPredictionRandomPost (const af::array &mx, const af::array &vx, af::array &mout, af::array &vout, PropagationMode mode=PropagationMode::MomentMatching)
 Forward prediction through random posterior. More...
 
- Protected Member Functions inherited from NeuralEngine::MachineLearning::GPModels::GPBaseLayer< Scalar >
 GPBaseLayer ()
 Default constructor. More...
 
virtual void ReinitParameters ()
 Reinitializes the parameters. More...
 
- Protected Member Functions inherited from NeuralEngine::MachineLearning::ILayer< Scalar >
 ILayer ()
 Default constructor. More...
 

Protected Attributes

af::array gamma
 
af::array beta
 
af::array afMuHat
 
af::array afSuHat
 
af::array afInvSuHat
 
af::array afInvSuMuHat
 
- Protected Attributes inherited from NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer< Scalar >
int ik
 
af::array afMu
 
af::array afSu
 
af::array afInvSu
 
af::array afInvSuMu
 
af::array T1
 
af::array T2
 
af::array T2_R
 
af::array afXu
 
af::array afKuu
 
af::array afInvKuu
 
af::array afKfu
 
bool isFixedInducing
 
- Protected Attributes inherited from NeuralEngine::MachineLearning::GPModels::GPBaseLayer< Scalar >
int iq
 Latent dimension. More...
 
bool isFixedHypers
 
IKernel< Scalar > * kernel
 kernel function More...
 
std::map< std::string, Style< Scalar > > * mStyles
 style variable More...
 
Scalar JITTER
 for kernel matrix stability (positive definiteness) More...
 
- Protected Attributes inherited from NeuralEngine::MachineLearning::ILayer< Scalar >
int iD
 data dimension More...
 
int iN
 data size More...
 
LayerType lType
 liklihood or gp layer More...
 
af::dtype m_dType
 floating point precision flag for af::array More...
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, unsigned int version)
 

Friends

class boost::serialization::access
 

Detailed Description

template<typename Scalar>
class NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >

Sparse GP layer.

Holds all variables for FITC approximation and PEP. Defines a subset of X. Selects k inducing inputs Xu, computes the subset kernel matrix Kuu and its inverse.

For more information see, https://pdfs.semanticscholar.org/99f9/3283e415ae21bd42a90031cd3972f3bfbc9d.pdf

Hmetal T, 05/05/2018.

Definition at line 37 of file FgPEPSparseGPLayer.h.

Constructor & Destructor Documentation

◆ SGPLayer() [1/2]

template<typename Scalar >
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::SGPLayer ( int  numPoints,
int  numPseudos,
int  outputDim,
int  inputDim 
)

Constructor.

, 15.05.2018.

Parameters
numPointsNumber of points.
numPseudosNumber of pseudo inputs.
outputDimThe output dimension.
inputDimThe input dimension.

◆ ~SGPLayer()

Destructor.

, 15.05.2018.

◆ SGPLayer() [2/2]

template<typename Scalar >
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::SGPLayer ( )
inlineprotected

Default constructor.

Hmetal T, 02/07/2018.

Definition at line 117 of file FgPEPSparseGPLayer.h.

Member Function Documentation

◆ ForwardPredictionCavity()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::ForwardPredictionCavity ( af::array &  mout,
af::array &  vout,
af::array &  n,
af::array &  mx,
af::array *  vx = nullptr,
Scalar  alpha = 1.0 
)

Forward prediction through cavity.


Computes new mean m^{
}_{f} and covariance V^{
}_{ff} function. From cavity distribution.

, 16.05.2018.

Parameters
mout[in,out] The m^{
}_{f}.
vout[in,out] The V^{
}_{ff}.
n[in,out] indexes of points to be removed from distribution.
mx[in,out] The inputs mx.
vx[in,out] (Optional) If non-null, the variances vx.
alpha(Optional) the alpha, weighning for alpha-divergence.

◆ BackpropGradientsReg()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::BackpropGradientsReg ( af::array &  m,
af::array &  v,
af::array &  dlogZ_dm,
af::array &  dlogZ_dv,
af::array &  x,
std::map< std::string, af::array > &  grad_hyper,
std::map< std::string, af::array > &  grad_cav,
Scalar  alpha = 1.0 
)

Prediction of posterior function values.

, 12.06.2018.

Parameters
testX[in,out] The test inputs.
mf[in,out] mean function values.
vf[in,out] covariance function values.

◆ UpdateFactor()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::UpdateFactor ( af::array &  n,
std::map< std::string, af::array >  grad_cav,
Scalar  alpha,
Scalar  decay = 0 
)

Update step of PowerEP.


Hmetal T, 08/06/2018. 
Parameters
n[in,out] The indexes to compute.
grad_cav[in,out] The gradient of the cavity functions m_f^{
} and V_{ff}^{\m}.
alphaThe alpha.
decay(Optional) the decay.

◆ UpdateParameters()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::UpdateParameters ( )
overridevirtual

Updates the parameters.

, 26.06.2018.

Reimplemented from NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer< Scalar >.

◆ InitParameters()

template<typename Scalar >
virtual void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::InitParameters ( af::array *  X = nullptr)
overridevirtual

Initializes the parameters.

Hmetal T, 09/12/2019.

Parameters
X[in,out] (Optional) If non-null, an af::array to process.

Reimplemented from NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer< Scalar >.

◆ ForwardPredictionDeterministicCavity()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::ForwardPredictionDeterministicCavity ( af::array &  mout,
af::array &  vout,
af::array &  idx,
af::array &  mx,
Scalar  alpha = 1.0 
)
protected

Forward prediction through deterministic cavity.


Projection step. Computation of cavity posterior mean and covariance function,

m^{\n}_{f} = K_{fu}K_{uu}^{−1}T^{\n, −1}_{2, u}T^{\n}_{1, u},

V{\n}_{ff} = K_{ff} − Q_{ff} + K_{fu}K^{−1}_{uu}T^{\n, −1}_{2, u}K^{−1}_{uu}K_{uf}.

, 16.05.2018.

Parameters
mout[in,out] The m^{
}_{f}.
vout[in,out] The V^{
}_{ff}.
idx[in,out] indexes of points to be removed from distribution.
mx[in,out] The inputs mx.
alpha(Optional) the alpha, weighning for alpha-divergence.

◆ ForwardPredictionRandomCavity()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::ForwardPredictionRandomCavity ( af::array &  mout,
af::array &  vout,
af::array &  idx,
af::array &  mx,
af::array &  vx,
Scalar  alpha = 1.0 
)
protected

Forward prediction through random cavity.

, 16.05.2018.

Parameters
mout[in,out] The m^{
}_{f}.
vout[in,out] The V^{
}_{ff}.
idx[in,out] indexes of points to be removed from distribution.
mx[in,out] The inputs mx.
vx[in,out] (Optional) If non-null, the variances vx.
alpha(Optional) the alpha, weighning for alpha-divergence.

◆ ComputeCavity()

template<typename Scalar >
void NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::ComputeCavity ( af::array &  idx,
af::array &  muhat,
af::array &  Suhat,
af::array &  T1uHat,
af::array &  T2uHat,
Scalar  alpha = 1.0f 
)
protected

Calculates the cavity.

Deletion step: The cavity for data point n, q^{
}(f) ∝ q^∗(f)/t^α_n(u), has a similar form to the posterior, but the natural parameters are modified by the deletion,

T^\n_{1, u} = T_{1, u} − αT_{1, n}

    and

T^\n_{2, u} = T_{2, u} − αT_{2, n},

for yielding new mean muhat and covariance function Suhat.

, 16.05.2018.

Parameters
idx[in,out] indexes of points to be removed from distribution.
muhat[in,out] The muhat.
Suhat[in,out] The Suhat.
T1uHat[in,out] The cavity natural parameter T^\n_{1, u}.
T2uHat[in,out] The cavity natural parameter T^\n_{2, u}.
alpha(Optional) the alpha, weighning for alpha-divergence.

◆ serialize()

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

Definition at line 201 of file FgPEPSparseGPLayer.h.

Friends And Related Function Documentation

◆ boost::serialization::access

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

Definition at line 198 of file FgPEPSparseGPLayer.h.

Member Data Documentation

◆ gamma

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::gamma
protected

Definition at line 184 of file FgPEPSparseGPLayer.h.

◆ beta

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::beta
protected

Definition at line 185 of file FgPEPSparseGPLayer.h.

◆ afMuHat

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::afMuHat
protected

Definition at line 192 of file FgPEPSparseGPLayer.h.

◆ afSuHat

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::afSuHat
protected

Definition at line 193 of file FgPEPSparseGPLayer.h.

◆ afInvSuHat

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::afInvSuHat
protected

Definition at line 194 of file FgPEPSparseGPLayer.h.

◆ afInvSuMuHat

template<typename Scalar >
af::array NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer< Scalar >::afInvSuMuHat
protected

Definition at line 195 of file FgPEPSparseGPLayer.h.


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