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

FgPEPSparseGPLayer.h
1
11#pragma once
12
13#include <MachineLearning/FgSparseGPBaseLayer.h>
14
15 namespace NeuralEngine
16{
17 namespace MachineLearning
18 {
19 namespace GPModels
20 {
21 namespace PowerEP
22 {
36 template<typename Scalar>
37 class NE_IMPEXP SGPLayer : public SparseGPBaseLayer<Scalar>
38 {
39 public:
50 SGPLayer(int numPoints, int numPseudos, int outputDim, int inputDim);
51
57 virtual ~SGPLayer();
58
76 void ForwardPredictionCavity(af::array& mout, af::array& vout, af::array& n, af::array& mx, af::array* vx = nullptr, Scalar alpha = 1.0);
77
87 //virtual void ForwardPredictionPost(af::array& mout, af::array& vout, af::array* mx, af::array* vx = nullptr) override;
88
89 void BackpropGradientsReg(af::array& m, af::array& v, af::array& dlogZ_dm, af::array& dlogZ_dv, af::array& x, std::map<std::string,
90 af::array>& grad_hyper, std::map<std::string, af::array>& grad_cav, Scalar alpha = 1.0);
91
105 void UpdateFactor(af::array& n, std::map<std::string, af::array> grad_cav, Scalar alpha, Scalar decay = 0);
106
107 virtual void UpdateParameters() override;
108
109 virtual void InitParameters(af::array* X = nullptr) override;
110
111 protected:
117 SGPLayer() { }
118
119 void ForwardPredictionDeterministicPost(af::array& mx, af::array* mout, af::array* vout);
120
140 void ForwardPredictionDeterministicCavity(af::array& mout, af::array& vout, af::array& idx, af::array& mx, Scalar alpha = 1.0);
141
154 void ForwardPredictionRandomCavity(af::array& mout, af::array& vout, af::array& idx, af::array& mx, af::array& vx, Scalar alpha = 1.0);
155
181 void ComputeCavity(af::array& idx, af::array& muhat, af::array& Suhat, af::array& T1uHat, af::array& T2uHat, Scalar alpha = 1.0f);
182
183 // PEP variables
184 af::array gamma;
185 af::array beta;
186
188 //af::array T1;
189 //af::array T2;
190
191 // Cavity temp variables
192 af::array afMuHat; // mean^{\n} of q(u)
193 af::array afSuHat; // covariance^{\n} of q(u)
194 af::array afInvSuHat; // T_{2,u}^{\n}
195 af::array afInvSuMuHat; // T_{1,u}^{\n}
196
197 private:
198 friend class boost::serialization::access;
199
200 template<class Archive>
201 void serialize(Archive& ar, unsigned int version)
202 {
203 ar& boost::serialization::base_object<SparseGPBaseLayer<Scalar>>(*this);
204 //ar& boost::serialization::make_nvp("SparseGPBaseLayer", boost::serialization::base_object<SparseGPBaseLayer<Scalar>>(*this));
205 ar& BOOST_SERIALIZATION_NVP(gamma);
206 ar& BOOST_SERIALIZATION_NVP(beta);
207 }
208 };
209 }
210 }
211 }
212}
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer
Sparse GP layer.
Definition: FgPEPSparseGPLayer.h:38
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::ForwardPredictionCavity
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.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::UpdateParameters
virtual void UpdateParameters() override
Updates the parameters.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::SGPLayer
SGPLayer()
Default constructor.
Definition: FgPEPSparseGPLayer.h:117
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::ComputeCavity
void ComputeCavity(af::array &idx, af::array &muhat, af::array &Suhat, af::array &T1uHat, af::array &T2uHat, Scalar alpha=1.0f)
Calculates the cavity.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::BackpropGradientsReg
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.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::UpdateFactor
void UpdateFactor(af::array &n, std::map< std::string, af::array > grad_cav, Scalar alpha, Scalar decay=0)
Update step of PowerEP.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::~SGPLayer
virtual ~SGPLayer()
Destructor.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::ForwardPredictionRandomCavity
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.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::SGPLayer
SGPLayer(int numPoints, int numPseudos, int outputDim, int inputDim)
Constructor.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::InitParameters
virtual void InitParameters(af::array *X=nullptr) override
Initializes the parameters.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer::ForwardPredictionDeterministicCavity
void ForwardPredictionDeterministicCavity(af::array &mout, af::array &vout, af::array &idx, af::array &mx, Scalar alpha=1.0)
Forward prediction through deterministic cavity.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgSparseGPBaseLayer.h:35
Scalar
NeuralEngine
Definition: NeArray2.h:18