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
19namespace 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
155
156 protected:
157
166
176
188 BaseOptimizationMethod(int numberOfVariables);
189
204 BaseOptimizationMethod(int numberOfVariables, std::function<Scalar(const af::array&, af::array&)> function);
205
216
227 virtual bool Optimize(int* cycle = nullptr) = 0;
228
229 //std::function<Scalar(af::array&)> _function;
230
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}
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...
virtual bool Optimize(int *cycle=nullptr)=0
Implements the actual optimization algorithm. This method should try to minimize the objective functi...
BaseOptimizationMethod(int numberOfVariables, std::function< Scalar(const af::array &, af::array &)> function)
Initializes a new instance of the BaseOptimizationMethod class.
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...
BaseOptimizationMethod(NonlinearObjectiveFunction< Scalar > *function)
Initializes a new instance of the BaseOptimizationMethod class.
virtual af::array GetSolution()
Gets the current solution found, the values of the parameters which optimizes the function.
void SetNumberOfVariables(int n)
Sets the number of variables (free parameters) in the optimization problem.
virtual bool Maximize(int *cycle=nullptr)
Finds the maximum value of a function. The solution vector will be made available at the Solution pro...
virtual int GetNumberOfVariables()
Gets the number of variables (free parameters) in the optimization problem.
virtual bool Minimize(int *cycle=nullptr)
Finds the minimum value of a function. The solution vector will be made available at the Solution pro...
void SetValue(Scalar v)
Sets the output of the function at the current Solution.
virtual void SetSolution(af::array &x)
Sets the current solution found, the values of the parameters which optimizes the function.
void Display(bool display)
Set to display optimization information.
BaseOptimizationMethod(int numberOfVariables)
Initializes a new instance of the BaseOptimizationMethod class.
virtual Scalar GetValue()
Gets the output of the function at the current Solution.
Common interface for function optimization methods.