NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
FgLBFGSBsolver.h
1
11#pragma once
12
13#include <MachineLearning/BaseGradientOptimizationMethod.h>
14
15namespace NeuralEngine
16{
17 namespace MachineLearning
18 {
75 template<typename Scalar, LineSearchType LSType = MoreThuente>
76 class NE_IMPEXP LBFGSBSolver : public BaseGradientOptimizationMethod<Scalar, LSType>
77 {
78 public:
88 LBFGSBSolver(int numberOfVariables);
89
101 LBFGSBSolver(int numberOfVariables,
102 std::function<Scalar(const af::array&, af::array&)> function);
103
112
113 void SetHistorySize(const int hs);
114
116
117 protected:
118
129 virtual bool Optimize(int* cycle = nullptr) override;
130
140 std::vector<int> SortIndexes(const std::vector<std::pair<int, Scalar>>& v);
141
153 void GetGeneralizedCauchyPoint(const af::array& x, const af::array& g, af::array& x_cauchy, af::array& c);
154
167 Scalar FindAlpha(af::array& x_cp, af::array& du, std::vector<int>& FreeVariables);
168
181 void SubspaceMinimization(af::array& x_cauchy, af::array& x, af::array& c, af::array& g, af::array& SubspaceMin);
182
193 Scalar GetOptimality(const af::array& x, const af::array& g);
194
195 private:
196 af::array W, M;
197 Scalar theta;
198 int m_historySize;
199 };
200 }
201}
Limited-memory BFGS (L-BFGS or LM-BFGS).
Scalar GetOptimality(const af::array &x, const af::array &g)
Gets an optimality.
LBFGSBSolver(int numberOfVariables)
Creates a new instance of the L-BFGS optimization algorithm.
virtual bool Optimize(int *cycle=nullptr) override
Implements the actual optimization algorithm. This method should try to minimize the objective functi...
void GetGeneralizedCauchyPoint(const af::array &x, const af::array &g, af::array &x_cauchy, af::array &c)
Computation of the generalized Cauchy point.
std::vector< int > SortIndexes(const std::vector< std::pair< int, Scalar > > &v)
Sorts pairs (k,v) according v ascending.
Scalar FindAlpha(af::array &x_cp, af::array &du, std::vector< int > &FreeVariables)
Finds alpha* = max{a : a <= 1 and l_i-xc_i <= a*d_i <= u_i-xc_i}.
LBFGSBSolver(int numberOfVariables, std::function< Scalar(const af::array &, af::array &)> function)
Creates a new instance of the L-BFGS optimization algorithm.
LBFGSBSolver(NonlinearObjectiveFunction< Scalar > *function)
Creates a new instance of the L-BFGS optimization algorithm.
void SubspaceMinimization(af::array &x_cauchy, af::array &x, af::array &c, af::array &g, af::array &SubspaceMin)
Solving unbounded probelm.