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

FgSparseGPBaseLayer.h
1
11#pragma once
12
13#include <MachineLearning/FgGPBaseLayer.h>
14
15 namespace NeuralEngine
16{
17 namespace MachineLearning
18 {
19 namespace GPModels
20 {
21 enum PropagationMode
22 {
23 MomentMatching,
24 Linear,
25 MonteCarlo
26 };
27
33 template<typename Scalar>
34 class NE_IMPEXP SparseGPBaseLayer : public GPBaseLayer<Scalar>
35 {
36 public:
37
48 SparseGPBaseLayer(int numPoints, int numPseudos, int outputDim, int inputDim);
49
55 virtual ~SparseGPBaseLayer();
56
67 virtual void ForwardPredictionPost(const af::array* mx, const af::array* vx, af::array& mout, af::array& vout) override;
68
81 virtual void SampleFromPost(const af::array& inX, af::array& outfsample) override;
82
88 void ComputeKuu();
89
95 void ComputeKfu(const af::array& inX);
96
104 af::array GetPseudoInputs();
105
113 virtual int GetNumParameters() override;
114
122 virtual void SetParameters(const af::array& param) override;
123
131 virtual af::array GetParameters() override;
132
140 virtual void FixInducing(bool isfixed);
141
147 virtual void UpdateParameters() override;
148
156 virtual void InitParameters(af::array* X = nullptr) override;
157
158 protected:
159
165 SparseGPBaseLayer() { }
166
172 virtual void ReinitParameters() override;
173
183 virtual void ForwardPredictionDeterministicPost(const af::array& mx, af::array* mout, af::array* vout);
184
196 virtual void ForwardPredictionRandomPost(const af::array& mx, const af::array& vx, af::array& mout, af::array& vout, PropagationMode mode = PropagationMode::MomentMatching);
197
198 int ik; //< number pseudo inputs
199
200 af::array afMu; //< mean of /f$q(\mathbf{u})/f$
201 af::array afSu; //< covariance of /f$q(\mathbf{u})/f$
202 af::array afInvSu; //< natural parameter /f$\mathbf{K_{uu}} + T_{2,\mathbf{u}}/f$
203 af::array afInvSuMu; //< natural parameter /f$T_{1,\mathbf{u}}/f$
204
205 // natural parameters
206 af::array T1; //< natural parameter /f$T_{1,\mathbf{u}}/f$
207 af::array T2; //< natural parameter /f$T_{2,\mathbf{u}}/f$
208 af::array T2_R; //< triangular /f$T_{2,\mathbf{u}}/f$ for parameter optimization
209
210 af::array afXu; //< inducing/pseudo inputs
211 af::array afKuu; //< kernel matrix inducing inputs
212 af::array afInvKuu; //< inverse kernel matrix inducing inputs
213 af::array afKfu; //< kernel matrix inputs and inducing inputs
214
215 bool isFixedInducing;
216
217 private:
218 friend class boost::serialization::access;
219
220 template<class Archive>
221 void serialize(Archive& ar, unsigned int version)
222 {
223 ar& boost::serialization::base_object<GPBaseLayer<Scalar>>(*this);
224 //ar& boost::serialization::make_nvp("GPBaseLayer", boost::serialization::base_object<GPBaseLayer<Scalar>>(*this));
225
226 ar& BOOST_SERIALIZATION_NVP(ik);
227 ar& BOOST_SERIALIZATION_NVP(afXu);
228 /*ar& BOOST_SERIALIZATION_NVP(afKuu);
229 ar& BOOST_SERIALIZATION_NVP(afInvKuu);
230 ar& BOOST_SERIALIZATION_NVP(afMu);
231 ar& BOOST_SERIALIZATION_NVP(afSu);
232 ar& BOOST_SERIALIZATION_NVP(afInvSu);
233 ar& BOOST_SERIALIZATION_NVP(afInvSuMu);
234 ar& BOOST_SERIALIZATION_NVP(afKfu);*/
235 ar& BOOST_SERIALIZATION_NVP(T1);
236 ar& BOOST_SERIALIZATION_NVP(T2);
237 ar& BOOST_SERIALIZATION_NVP(T2_R);
238 ar& BOOST_SERIALIZATION_NVP(isFixedInducing);
239 }
240 };
241 }
242 }
243}
NeuralEngine::MachineLearning::GPModels::GPBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgGPBaseLayer.h:30
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgSparseGPBaseLayer.h:35
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ForwardPredictionPost
virtual void ForwardPredictionPost(const af::array *mx, const af::array *vx, af::array &mout, af::array &vout) override
Forward prediction of posterior function values.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ComputeKfu
void ComputeKfu(const af::array &inX)
Calculates the kernel matrix of inputes and pseudo inputs.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ForwardPredictionRandomPost
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.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ComputeKuu
void ComputeKuu()
Calculates the kernel matrix of pseudo inputs.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::SetParameters
virtual void SetParameters(const af::array &param) override
Sets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::SparseGPBaseLayer
SparseGPBaseLayer()
Default constructor.
Definition: FgSparseGPBaseLayer.h:165
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::FixInducing
virtual void FixInducing(bool isfixed)
Set fixation for inducing inputs.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::~SparseGPBaseLayer
virtual ~SparseGPBaseLayer()
Destructor.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::GetPseudoInputs
af::array GetPseudoInputs()
Gets pseudo inputs.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::GetNumParameters
virtual int GetNumParameters() override
Gets number of parameters to be optimized.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::SparseGPBaseLayer
SparseGPBaseLayer(int numPoints, int numPseudos, int outputDim, int inputDim)
Constructor.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::SampleFromPost
virtual void SampleFromPost(const af::array &inX, af::array &outfsample) override
Samples from posterior.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ReinitParameters
virtual void ReinitParameters() override
Reinitializes the parameters.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::InitParameters
virtual void InitParameters(af::array *X=nullptr) override
Initializes the parameters.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::ForwardPredictionDeterministicPost
virtual void ForwardPredictionDeterministicPost(const af::array &mx, af::array *mout, af::array *vout)
Deterministic forward propagation through posterior.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::GetParameters
virtual af::array GetParameters() override
Gets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::SparseGPBaseLayer::UpdateParameters
virtual void UpdateParameters() override
Updates the parameters.
NeuralEngine
Definition: NeArray2.h:18