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

BaseOptimizationMethod.h
1
11#pragma once
12
13#include <NeMachineLearningLib.h>
14#include <MachineLearning/IOptimizationMethod.h>
15#include <MachineLearning/NonlinearObjectiveFunction.h>
16#include <functional>
17#include <exception>
18
19 namespace NeuralEngine
20{
21 namespace MachineLearning
22 {
23
29 template<typename Scalar>
30 class NE_IMPEXP BaseOptimizationMethod : public IOptimizationMethod<Scalar>
31 {
32 public:
33
42 virtual int GetNumberOfVariables();
43
54 virtual af::array GetSolution();
55
66 virtual void SetSolution(af::array& x);
67
75 virtual Scalar GetValue();
76
93 virtual bool Maximize(af::array& values, int* cycle = nullptr);
94
111 virtual bool Minimize(af::array& values, int* cycle = nullptr);
112
127 virtual bool Maximize(int* cycle = nullptr);
128
143 virtual bool Minimize(int* cycle = nullptr);
144
152 void Display(bool display);
153
154 ~BaseOptimizationMethod();
155
156 protected:
157
165 void SetValue(Scalar v);
166
175 void SetNumberOfVariables(int n);
176
188 BaseOptimizationMethod(int numberOfVariables);
189
204 BaseOptimizationMethod(int numberOfVariables, std::function<Scalar(const af::array&, af::array&)> function);
205
215 BaseOptimizationMethod(NonlinearObjectiveFunction<Scalar>* function);
216
227 virtual bool Optimize(int* cycle = nullptr) = 0;
228
229 //std::function<Scalar(af::array&)> _function;
230
231 NonlinearObjectiveFunction<Scalar>* _function;
232
233 af::array _x;
234
235 bool _display;
236
237 af::dtype m_dtype;
238
239 private:
240
241 void init(int numberOfVariables);
242
243 Scalar _value;
244 int _numVariables;
245 };
246 }
247}
NeuralEngine::MachineLearning::BaseOptimizationMethod
Base class for optimization methods.
Definition: BaseOptimizationMethod.h:31
NeuralEngine::MachineLearning::BaseOptimizationMethod::Minimize
virtual bool Minimize(af::array &values, int *cycle=nullptr)
Finds the minimum value of a function. The solution vector will be made available at the Solution pro...
NeuralEngine::MachineLearning::BaseOptimizationMethod::Optimize
virtual bool Optimize(int *cycle=nullptr)=0
Implements the actual optimization algorithm. This method should try to minimize the objective functi...
NeuralEngine::MachineLearning::BaseOptimizationMethod::BaseOptimizationMethod
BaseOptimizationMethod(int numberOfVariables, std::function< Scalar(const af::array &, af::array &)> function)
Initializes a new instance of the BaseOptimizationMethod class.
NeuralEngine::MachineLearning::BaseOptimizationMethod::Maximize
virtual bool Maximize(af::array &values, int *cycle=nullptr)
Finds the maximum value of a function. The solution vector will be made available at the Solution pro...
NeuralEngine::MachineLearning::BaseOptimizationMethod::BaseOptimizationMethod
BaseOptimizationMethod(NonlinearObjectiveFunction< Scalar > *function)
Initializes a new instance of the BaseOptimizationMethod class.
NeuralEngine::MachineLearning::BaseOptimizationMethod::GetSolution
virtual af::array GetSolution()
Gets the current solution found, the values of the parameters which optimizes the function.
NeuralEngine::MachineLearning::BaseOptimizationMethod::SetNumberOfVariables
void SetNumberOfVariables(int n)
Sets the number of variables (free parameters) in the optimization problem.
NeuralEngine::MachineLearning::BaseOptimizationMethod::Maximize
virtual bool Maximize(int *cycle=nullptr)
Finds the maximum value of a function. The solution vector will be made available at the Solution pro...
NeuralEngine::MachineLearning::BaseOptimizationMethod::GetNumberOfVariables
virtual int GetNumberOfVariables()
Gets the number of variables (free parameters) in the optimization problem.
NeuralEngine::MachineLearning::BaseOptimizationMethod::Minimize
virtual bool Minimize(int *cycle=nullptr)
Finds the minimum value of a function. The solution vector will be made available at the Solution pro...
NeuralEngine::MachineLearning::BaseOptimizationMethod::SetValue
void SetValue(Scalar v)
Sets the output of the function at the current Solution.
NeuralEngine::MachineLearning::BaseOptimizationMethod::SetSolution
virtual void SetSolution(af::array &x)
Sets the current solution found, the values of the parameters which optimizes the function.
NeuralEngine::MachineLearning::BaseOptimizationMethod::Display
void Display(bool display)
Set to display optimization information.
NeuralEngine::MachineLearning::BaseOptimizationMethod::BaseOptimizationMethod
BaseOptimizationMethod(int numberOfVariables)
Initializes a new instance of the BaseOptimizationMethod class.
NeuralEngine::MachineLearning::BaseOptimizationMethod::GetValue
virtual Scalar GetValue()
Gets the output of the function at the current Solution.
NeuralEngine::MachineLearning::IOptimizationMethod
Common interface for function optimization methods.
Definition: IOptimizationMethod.h:43
NeuralEngine::MachineLearning::NonlinearObjectiveFunction
Definition: NonlinearObjectiveFunction.h:21
Scalar
NeuralEngine
Definition: NeArray2.h:18