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

FgGPBaseLayer.h
1
11#pragma once
12
13#include <MachineLearning/FgILayer.h>
14#include <MachineLearning/FgKernels.h>
15#include <MachineLearning/FgGPLVMBaseModel.h>
16
17 namespace NeuralEngine
18{
19 namespace MachineLearning
20 {
21 namespace GPModels
22 {
28 template<typename Scalar>
29 class NE_IMPEXP GPBaseLayer : public ILayer<Scalar>
30 {
31 public:
41 GPBaseLayer(int numPoints, int outputDim, int inputDim);
42
48 virtual ~GPBaseLayer();
49
57 IKernel<Scalar>* GetKernel();
58
66 void SetKernel(IKernel<Scalar>* kern);
67
68 virtual void InitParameters(af::array* X = nullptr);
69
77 virtual int GetNumParameters();
78
86 virtual void SetParameters(const af::array& param);
87
95 virtual af::array GetParameters();
96
107 virtual void ForwardPredictionPost(const af::array* mx, const af::array* vx, af::array& mout, af::array& vout);
108
121 virtual void SampleFromPost(const af::array& inX, af::array& outfsample);
122
130 virtual void FixKernelParameters(bool isfixed);
131
137 virtual void UpdateParameters();
138
147 virtual void SetDataSize(int length, int dimension) override;
148
156 void SetStyles(std::map<std::string, Style<Scalar>>* styles);
157
165 void SetLatentDimension(int q);
166
167
168 protected:
174 GPBaseLayer() { }
175
181 virtual void ReinitParameters();
182
183 int iq;
184
185 bool isFixedHypers;
186
187 IKernel<Scalar>* kernel;
188 std::map<std::string, Style<Scalar>>* mStyles;
189
190 Scalar JITTER;
191
192 private:
193 friend class boost::serialization::access;
194
195 template<class Archive>
196 void serialize(Archive& ar, unsigned int version)
197 {
198 ar& boost::serialization::base_object<ILayer<Scalar>>(*this);
199 //ar& boost::serialization::make_nvp("ILayer", boost::serialization::base_object<ILayer<Scalar>>(*this));
200
201 ar.register_type<LinearKernel<Scalar>>();
202 //ar.register_type<RBFKernel<Scalar>>();
203 ar.register_type<ARDKernel<Scalar>>();
204 //ar.register_type<WhiteKernel<Scalar>>();
205 ar.register_type<CompoundKernel<Scalar>>();
206 //ar.register_type<RBFAccelerationKernel<Scalar>>();
207 //ar.register_type<LinearAccelerationKernel<Scalar>>();
208
209 ar& BOOST_SERIALIZATION_NVP(iq);
210 ar& BOOST_SERIALIZATION_NVP(kernel);
211 ar& BOOST_SERIALIZATION_NVP(isFixedHypers);
212 ar& BOOST_SERIALIZATION_NVP(JITTER);
213 ar& BOOST_SERIALIZATION_NVP(mStyles);
214 }
215 };
216 }
217 }
218}
NeuralEngine::MachineLearning::ARDKernel
Automatic Relevance Determination kernel.
Definition: FgARDKernel.h:39
NeuralEngine::MachineLearning::CompoundKernel
Compound kernel function.
Definition: FgCompoundKernel.h:44
NeuralEngine::MachineLearning::GPModels::GPBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgGPBaseLayer.h:30
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::GetNumParameters
virtual int GetNumParameters()
Gets number of parameters to be optimized.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::ReinitParameters
virtual void ReinitParameters()
Reinitializes the parameters.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::GetKernel
IKernel< Scalar > * GetKernel()
Gets the kernel function.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::GPBaseLayer
GPBaseLayer()
Default constructor.
Definition: FgGPBaseLayer.h:174
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::GetParameters
virtual af::array GetParameters()
Gets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SetLatentDimension
void SetLatentDimension(int q)
Sets latent dimension.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::FixKernelParameters
virtual void FixKernelParameters(bool isfixed)
Sets fixation for hyperparameters.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::~GPBaseLayer
virtual ~GPBaseLayer()
Destructor.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SetStyles
void SetStyles(std::map< std::string, Style< Scalar > > *styles)
Sets the syles.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::ForwardPredictionPost
virtual void ForwardPredictionPost(const af::array *mx, const af::array *vx, af::array &mout, af::array &vout)
Forward prediction of posterior function values.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SetDataSize
virtual void SetDataSize(int length, int dimension) override
Sets data size.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::JITTER
Scalar JITTER
for kernel matrix stability (positive definiteness)
Definition: FgGPBaseLayer.h:190
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::mStyles
std::map< std::string, Style< Scalar > > * mStyles
style variable
Definition: FgGPBaseLayer.h:188
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::GPBaseLayer
GPBaseLayer(int numPoints, int outputDim, int inputDim)
Constructor.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SetKernel
void SetKernel(IKernel< Scalar > *kern)
Sets a kernel function.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SetParameters
virtual void SetParameters(const af::array &param)
Sets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::SampleFromPost
virtual void SampleFromPost(const af::array &inX, af::array &outfsample)
Samples from posterior.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::kernel
IKernel< Scalar > * kernel
kernel function
Definition: FgGPBaseLayer.h:187
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::UpdateParameters
virtual void UpdateParameters()
Updates the parameters.
NeuralEngine::MachineLearning::GPModels::GPBaseLayer::iq
int iq
Latent dimension.
Definition: FgGPBaseLayer.h:183
NeuralEngine::MachineLearning::GPModels::Style
Style variable.
Definition: FgGPLVMBaseModel.h:33
NeuralEngine::MachineLearning::IKernel
Definition: FgIKernel.h:36
NeuralEngine::MachineLearning::ILayer
Abstract class for different kind of layers.
Definition: FgILayer.h:38
NeuralEngine::MachineLearning::LinearKernel
Linear kernel function.
Definition: FgLinearKernel.h:35
Scalar
NeuralEngine
Definition: NeArray2.h:18