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

FgPEPSparseGPLayer2nd.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 SGPLayer2nd : public SparseGPBaseLayer<Scalar>
38 {
39 public:
50 SGPLayer2nd(int numPoints, int numPseudos, int outputDim, int inputDim);
51
57 virtual ~SGPLayer2nd();
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(const af::array* mx, const af::array* vx, af::array& mout, af::array& vout) 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:
112 void ForwardPredictionDeterministicPost(af::array& mx, af::array* mout, af::array* vout);
113
133 void ForwardPredictionDeterministicCavity(af::array& mout, af::array& vout, af::array& idx, af::array& mx, Scalar alpha = 1.0);
134
147 void ForwardPredictionRandomCavity(af::array& mout, af::array& vout, af::array& idx, af::array& mx, af::array& vx, Scalar alpha = 1.0);
148
174 void ComputeCavity(af::array& idx, af::array& muhat, af::array& Suhat, af::array& T1uHat, af::array& T2uHat, Scalar alpha = 1.0f);
175
176 // PEP variables
177 af::array gamma;
178 af::array beta;
179
181 //af::array T1;
182 //af::array T2;
183
184 // Cavity temp variables
185 af::array afMuHat; // mean^{\n} of q(u)
186 af::array afSuHat; // covariance^{\n} of q(u)
187 af::array afInvSuHat; // T_{2,u}^{\n}
188 af::array afInvSuMuHat; // T_{1,u}^{\n}
189
190 private:
191 friend class boost::serialization::access;
192
193 template<class Archive>
194 void serialize(Archive& ar, unsigned int version)
195 {
196 ar& boost::serialization::base_object<SparseGPBaseLayer<Scalar>>(*this);
197 //ar& boost::serialization::make_nvp("SparseGPBaseLayer", boost::serialization::base_object<SparseGPBaseLayer<Scalar>>(*this));
198 ar& BOOST_SERIALIZATION_NVP(gamma);
199 ar& BOOST_SERIALIZATION_NVP(beta);
200 ar& BOOST_SERIALIZATION_NVP(afMuHat);
201 ar& BOOST_SERIALIZATION_NVP(afSuHat);
202 ar& BOOST_SERIALIZATION_NVP(afInvSuHat);
203 ar& BOOST_SERIALIZATION_NVP(afInvSuMuHat);
204 }
205 };
206 }
207 }
208 }
209}
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd
Sparse GP layer.
Definition: FgPEPSparseGPLayer2nd.h:38
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd::~SGPLayer2nd
virtual ~SGPLayer2nd()
Destructor.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd::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::SGPLayer2nd::SGPLayer2nd
SGPLayer2nd(int numPoints, int numPseudos, int outputDim, int inputDim)
Constructor.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd::ForwardPredictionPost
virtual void ForwardPredictionPost(const af::array *mx, const af::array *vx, af::array &mout, af::array &vout) override
Prediction of posterior function values.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd::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::SGPLayer2nd::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::SGPLayer2nd::InitParameters
virtual void InitParameters(af::array *X=nullptr) override
Initializes the parameters.
NeuralEngine::MachineLearning::GPModels::PowerEP::SGPLayer2nd::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::SGPLayer2nd::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::PowerEP::SGPLayer2nd::UpdateParameters
virtual void UpdateParameters() override
Updates the parameters.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgSparseGPBaseLayer.h:35
Scalar
NeuralEngine
Definition: NeArray2.h:18