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

FgLikelihoodBaseLayer.h
1
11#pragma once
12
13#include <MachineLearning/FgILayer.h>
14
15 namespace NeuralEngine
16{
17 namespace MachineLearning
18 {
19 namespace GPModels
20 {
21
22 enum class LogLikType
23 {
24 Gaussian,
25 Probit
26 };
27
33 template<typename Scalar>
34 class NE_IMPEXP LikelihoodBaseLayer : public ILayer<Scalar>
35 {
36 public:
37
47 LikelihoodBaseLayer(LogLikType type, int numPoints, int outputDim);
48
49 virtual ~LikelihoodBaseLayer();
50
63 virtual Scalar ComputeLogZ(const af::array& mout, const af::array& vout, const af::array& y, Scalar alpha = 1.0, af::array* dlogZ_dm = nullptr,
64 af::array* dlogZ_dv = nullptr, af::array* dlogZ_dm2 = nullptr) = 0;
65
78 virtual void ComputeLogZGradients(const af::array& mout, const af::array& vout, const af::array& y, af::array* dlogZ_dm = nullptr,
79 af::array* dlogZ_dv = nullptr, af::array* dlogZ_dm2 = nullptr, Scalar alpha = 1.0) = 0;
80
81 virtual Scalar BackpropagationGradients(const af::array& mout, const af::array& vout, af::array& dmout, af::array& dvout, Scalar alpha = 1.0, Scalar scale = 1.0) = 0;
82
83 virtual Scalar ComputeLogLikExp(const af::array& mout, const af::array& vout, const af::array& y) = 0;
84
85 virtual void ComputeLogLikExpGradients(const af::array& mout, const af::array& vout, const af::array& y, af::array* de_dm = nullptr, af::array* de_dv = nullptr) = 0;
86
87 virtual Scalar BackpropagationGradientsLogLikExp(const af::array& mout, const af::array& vout, af::array& dmout, af::array& dvout, af::array& y, Scalar scale = 1.0) = 0;
88
89 virtual void ProbabilisticOutput(const af::array& mf, const af::array& vf, af::array& myOut, af::array& vyOut, Scalar alpha = 1.0f) = 0;
90
91 virtual Scalar InitParameters() { return 0.0f; }
92
100 LogLikType GetLogLikType();
101
109 virtual int GetNumParameters();
110
118 virtual void SetParameters(const af::array& param);
119
127 virtual af::array GetParameters();
128
136 virtual void FixParameters(bool isfixed);
137
143 virtual void UpdateParameters() { }
144
145 protected:
151 LikelihoodBaseLayer() { }
152
153 bool isFixedParam;
154 bool bDimMod;
155
156 private:
157 LogLikType lltype;
158
159 friend class boost::serialization::access;
160
161 template<class Archive>
162 void serialize(Archive& ar, unsigned int version)
163 {
164 ar& boost::serialization::base_object<ILayer<Scalar>>(*this);
165 ar& BOOST_SERIALIZATION_NVP(lltype);
166 ar& BOOST_SERIALIZATION_NVP(isFixedParam);
167 ar& BOOST_SERIALIZATION_NVP(bDimMod);
168 }
169 };
170 }
171 }
172}
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer
Abstract class for different GP likelihood layers.
Definition: FgLikelihoodBaseLayer.h:35
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::ComputeLogZ
virtual Scalar ComputeLogZ(const af::array &mout, const af::array &vout, const af::array &y, Scalar alpha=1.0, af::array *dlogZ_dm=nullptr, af::array *dlogZ_dv=nullptr, af::array *dlogZ_dm2=nullptr)=0
Calculates the logZ.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::UpdateParameters
virtual void UpdateParameters()
Updates the parameters.
Definition: FgLikelihoodBaseLayer.h:143
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::LikelihoodBaseLayer
LikelihoodBaseLayer(LogLikType type, int numPoints, int outputDim)
Constructor.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::ComputeLogZGradients
virtual void ComputeLogZGradients(const af::array &mout, const af::array &vout, const af::array &y, af::array *dlogZ_dm=nullptr, af::array *dlogZ_dv=nullptr, af::array *dlogZ_dm2=nullptr, Scalar alpha=1.0)=0
Calculates logZ gradients.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::FixParameters
virtual void FixParameters(bool isfixed)
Set to fix the parameters or not for optimization.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::GetNumParameters
virtual int GetNumParameters()
Gets number of parameters to be optimized.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::GetLogLikType
LogLikType GetLogLikType()
Gets log likelihood type.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::GetParameters
virtual af::array GetParameters()
Gets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::LikelihoodBaseLayer
LikelihoodBaseLayer()
Default constructor.
Definition: FgLikelihoodBaseLayer.h:151
NeuralEngine::MachineLearning::GPModels::LikelihoodBaseLayer::SetParameters
virtual void SetParameters(const af::array &param)
Sets the parameters for each optimization iteration.
NeuralEngine::MachineLearning::ILayer
Abstract class for different kind of layers.
Definition: FgILayer.h:38
Scalar
NeuralEngine
Definition: NeArray2.h:18