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

FgGPBaseModel.h
1
11#pragma once
12
13#include <MachineLearning/FgIModel.h>
14#include <MachineLearning/FgGaussLikelihoodLayer.h>
15#include <MachineLearning/FgProbitLikelihoodLayer.h>
16
17
18 namespace NeuralEngine
19{
20 namespace MachineLearning
21 {
22 namespace GPModels
23 {
24 template<typename Scalar>
25 class GaussLikLayer;
26
27 template<typename Scalar>
28 class ProbitLikLayer;
29
38 template<typename Scalar>
39 class NE_IMPEXP GPBaseModel : public IModel<Scalar>
40 {
41 public:
42
50 GPBaseModel(const af::array& Y, LogLikType lType = LogLikType::Gaussian, ModelType mtype = ModelType::GPR);
51
58 GPBaseModel();
59
65 virtual ~GPBaseModel();
66
80 virtual void Optimise(
81 OptimizerType method = L_BFGS,
82 Scalar tol = 0.0,
83 bool reinit_hypers = true,
84 int maxiter = 1000,
85 int mb_size = 0,
86 LineSearchType lsType = MoreThuente,
87 bool disp = true,
88 int* cycle = nullptr
89 );
90
98 virtual bool Init();
99
109 virtual void PredictF(const af::array& testInputs, af::array& mf, af::array& vf);
110
120 virtual void PredictY(const af::array& testInputs, af::array& my, af::array& vy);
121
131 virtual void SampleY(const af::array inputs, int numSamples, af::array& outFunctions);
132
140 virtual void AddData(const af::array Ytrain);
141
142
150 af::array GetTrainingData();
151
159 void SetTrainingData(af::array& data);
160
168 virtual int GetNumParameters();
169
177 virtual void SetParameters(const af::array& param);
178
186 virtual af::array GetParameters();
187
193 virtual void UpdateParameters();
194
202 virtual void FixLikelihoodParameters(bool isfixed);
203
211 //virtual void FixKernelParameters(bool isfixed) = 0;
212
220 void SetSegments(af::array segments);
221
229 af::array GetSegments();
230
231 protected:
232
233 bool bInit;
234 af::array afY;
235 af::array afBias;
236 af::array afSegments;
237
238
239 LikelihoodBaseLayer<Scalar>* likLayer;
240
241
242 /*std::vector fixed_params
243 bool updated = false*/
244
245 private:
246 friend class boost::serialization::access;
247
248 friend class GaussLikLayer<Scalar>;
249 friend class ProbitLikLayer<Scalar>;
250
251 template<class Archive>
252 void serialize(Archive& ar, unsigned int version)
253 {
254 ar& boost::serialization::base_object<IModel<Scalar>>(*this);
255 //ar& boost::serialization::make_nvp("IModel", boost::serialization::base_object<IModel<Scalar>>(*this));
256
257 ar.register_type<GaussLikLayer<Scalar>>();
258 ar.register_type<ProbitLikLayer<Scalar>>();
259
260 ar& BOOST_SERIALIZATION_NVP(afY);
261 ar& BOOST_SERIALIZATION_NVP(afBias);
262 ar& BOOST_SERIALIZATION_NVP(afSegments);
263 ar& BOOST_SERIALIZATION_NVP(bInit);
264 ar& BOOST_SERIALIZATION_NVP(likLayer);
265 }
266 };
267 }
268 }
269}
NeuralEngine::MachineLearning::GPModels::GPBaseModel
Base class with abstract and basic function definitions. All GP models will be derived from this clas...
Definition: FgGPBaseModel.h:40
NeuralEngine::MachineLearning::GPModels::GPBaseModel::afBias
af::array afBias
the bias
Definition: FgGPBaseModel.h:235
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GPBaseModel
GPBaseModel()
Default Constructor.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::PredictF
virtual void PredictF(const af::array &testInputs, af::array &mf, af::array &vf)
Predict noise free functions values .
NeuralEngine::MachineLearning::GPModels::GPBaseModel::Init
virtual bool Init()
Initializes the model.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::PredictY
virtual void PredictY(const af::array &testInputs, af::array &my, af::array &vy)
Prediction of test outputs .
NeuralEngine::MachineLearning::GPModels::GPBaseModel::AddData
virtual void AddData(const af::array Ytrain)
Adds training data to the model.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::bInit
bool bInit
check if model is initialized
Definition: FgGPBaseModel.h:233
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GetParameters
virtual af::array GetParameters()
Gets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::likLayer
LikelihoodBaseLayer< Scalar > * likLayer
liklihood layer
Definition: FgGPBaseModel.h:239
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GetNumParameters
virtual int GetNumParameters()
Gets number of parameters.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::Optimise
virtual void Optimise(OptimizerType method=L_BFGS, Scalar tol=0.0, bool reinit_hypers=true, int maxiter=1000, int mb_size=0, LineSearchType lsType=MoreThuente, bool disp=true, int *cycle=nullptr)
Optimizes the model parameters for best fit.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GetTrainingData
af::array GetTrainingData()
Gets the training data set Y.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::UpdateParameters
virtual void UpdateParameters()
Updates the parameters.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::~GPBaseModel
virtual ~GPBaseModel()
Destructor.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GetSegments
af::array GetSegments()
Gets the start index array for the sequences.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::GPBaseModel
GPBaseModel(const af::array &Y, LogLikType lType=LogLikType::Gaussian, ModelType mtype=ModelType::GPR)
Constructor.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::SetSegments
void SetSegments(af::array segments)
Sets fixation for hyperparameters.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::afY
af::array afY
training dataset, mean substracted
Definition: FgGPBaseModel.h:234
NeuralEngine::MachineLearning::GPModels::GPBaseModel::SetTrainingData
void SetTrainingData(af::array &data)
Sets training data Y.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::SampleY
virtual void SampleY(const af::array inputs, int numSamples, af::array &outFunctions)
Generate function samples from posterior.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::SetParameters
virtual void SetParameters(const af::array &param)
Sets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::FixLikelihoodParameters
virtual void FixLikelihoodParameters(bool isfixed)
Sets the likelihood parameters to be fixed or not for optimization.
NeuralEngine::MachineLearning::GPModels::GPBaseModel::afSegments
af::array afSegments
Index of starting positions for all trials.
Definition: FgGPBaseModel.h:236
NeuralEngine::MachineLearning::GPModels::GaussLikLayer
Likelihood estimation based on Gaussian distribution.
Definition: FgGaussLikelihoodLayer.h:51
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgLikelihoodBaseLayer.h:35
NeuralEngine::MachineLearning::GPModels::ProbitLikLayer
Likelihood estimation based on Probit distribution.
Definition: FgProbitLikelihoodLayer.h:51
NeuralEngine::MachineLearning::IModel
Base class with abstract and basic function definitions. All models will be derived from this class.
Definition: FgIModel.h:103
Scalar
NeuralEngine
Definition: NeArray2.h:18