MLPACK  1.0.7
lbfgs.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_CORE_OPTIMIZERS_LBFGS_LBFGS_HPP
24 #define __MLPACK_CORE_OPTIMIZERS_LBFGS_LBFGS_HPP
25 
26 #include <mlpack/core.hpp>
27 
28 namespace mlpack {
29 namespace optimization {
30 
43 template<typename FunctionType>
44 class L_BFGS
45 {
46  public:
67  L_BFGS(FunctionType& function,
68  const size_t numBasis = 5, /* entirely arbitrary */
69  const size_t maxIterations = 0, /* run forever */
70  const double armijoConstant = 1e-4,
71  const double wolfe = 0.9,
72  const double minGradientNorm = 1e-10,
73  const size_t maxLineSearchTrials = 50,
74  const double minStep = 1e-20,
75  const double maxStep = 1e20);
76 
83  const std::pair<arma::mat, double>& MinPointIterate() const;
84 
96  double Optimize(arma::mat& iterate);
97 
110  double Optimize(arma::mat& iterate, const size_t maxIterations);
111 
113  size_t NumBasis() const { return numBasis; }
115  size_t& NumBasis() { return numBasis; }
116 
118  size_t MaxIterations() const { return maxIterations; }
120  size_t& MaxIterations() { return maxIterations; }
121 
123  double ArmijoConstant() const { return armijoConstant; }
125  double& ArmijoConstant() { return armijoConstant; }
126 
128  double Wolfe() const { return wolfe; }
130  double& Wolfe() { return wolfe; }
131 
133  double MinGradientNorm() const { return minGradientNorm; }
135  double& MinGradientNorm() { return minGradientNorm; }
136 
138  size_t MaxLineSearchTrials() const { return maxLineSearchTrials; }
141 
143  double MinStep() const { return minStep; }
145  double& MinStep() { return minStep; }
146 
148  double MaxStep() const { return maxStep; }
150  double& MaxStep() { return maxStep; }
151 
152  private:
154  FunctionType& function;
155 
157  arma::mat newIterateTmp;
159  arma::cube s;
161  arma::cube y;
162 
164  size_t numBasis;
170  double wolfe;
176  double minStep;
178  double maxStep;
179 
181  std::pair<arma::mat, double> minPointIterate;
182 
189  double Evaluate(const arma::mat& iterate);
190 
198  double ChooseScalingFactor(const size_t iterationNum,
199  const arma::mat& gradient);
200 
207  bool GradientNormTooSmall(const arma::mat& gradient);
208 
222  bool LineSearch(double& functionValue,
223  arma::mat& iterate,
224  arma::mat& gradient,
225  const arma::mat& searchDirection);
226 
235  void SearchDirection(const arma::mat& gradient,
236  const size_t iterationNum,
237  const double scalingFactor,
238  arma::mat& searchDirection);
239 
251  void UpdateBasisSet(const size_t iterationNum,
252  const arma::mat& iterate,
253  const arma::mat& oldIterate,
254  const arma::mat& gradient,
255  const arma::mat& oldGradient);
256 };
257 
258 }; // namespace optimization
259 }; // namespace mlpack
260 
261 #include "lbfgs_impl.hpp"
262 
263 #endif // __MLPACK_CORE_OPTIMIZERS_LBFGS_LBFGS_HPP
double ArmijoConstant() const
Get the Armijo condition constant.
Definition: lbfgs.hpp:123
L_BFGS(FunctionType &function, const size_t numBasis=5, const size_t maxIterations=0, const double armijoConstant=1e-4, const double wolfe=0.9, const double minGradientNorm=1e-10, const size_t maxLineSearchTrials=50, const double minStep=1e-20, const double maxStep=1e20)
Initialize the L-BFGS object.
void SearchDirection(const arma::mat &gradient, const size_t iterationNum, const double scalingFactor, arma::mat &searchDirection)
Find the L-BFGS search direction.
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: lbfgs.hpp:120
double Wolfe() const
Get the Wolfe parameter.
Definition: lbfgs.hpp:128
size_t maxLineSearchTrials
Maximum number of trials for the line search.
Definition: lbfgs.hpp:174
arma::cube y
Stores all the y matrices in memory.
Definition: lbfgs.hpp:161
size_t & NumBasis()
Modify the memory size.
Definition: lbfgs.hpp:115
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: lbfgs.hpp:118
bool GradientNormTooSmall(const arma::mat &gradient)
Check to make sure that the norm of the gradient is not smaller than 1e-5.
double & ArmijoConstant()
Modify the Armijo condition constant.
Definition: lbfgs.hpp:125
double ChooseScalingFactor(const size_t iterationNum, const arma::mat &gradient)
Calculate the scaling factor, gamma, which is used to scale the Hessian approximation matrix...
double minGradientNorm
Minimum gradient norm required to continue the optimization.
Definition: lbfgs.hpp:172
double maxStep
Maximum step of the line search.
Definition: lbfgs.hpp:178
double minStep
Minimum step of the line search.
Definition: lbfgs.hpp:176
double & MinGradientNorm()
Modify the minimum gradient norm.
Definition: lbfgs.hpp:135
double armijoConstant
Parameter for determining the Armijo condition.
Definition: lbfgs.hpp:168
double & MaxStep()
Modify the maximum line search step size.
Definition: lbfgs.hpp:150
size_t & MaxLineSearchTrials()
Modify the maximum number of line search trials.
Definition: lbfgs.hpp:140
bool LineSearch(double &functionValue, arma::mat &iterate, arma::mat &gradient, const arma::mat &searchDirection)
Perform a back-tracking line search along the search direction to calculate a step size satisfying th...
double & Wolfe()
Modify the Wolfe parameter.
Definition: lbfgs.hpp:130
arma::mat newIterateTmp
Position of the new iterate.
Definition: lbfgs.hpp:157
arma::cube s
Stores all the s matrices in memory.
Definition: lbfgs.hpp:159
double & MinStep()
Modify the minimum line search step size.
Definition: lbfgs.hpp:145
size_t maxIterations
Maximum number of iterations.
Definition: lbfgs.hpp:166
size_t NumBasis() const
Get the memory size.
Definition: lbfgs.hpp:113
size_t MaxLineSearchTrials() const
Get the maximum number of line search trials.
Definition: lbfgs.hpp:138
const std::pair< arma::mat, double > & MinPointIterate() const
Return the point where the lowest function value has been found.
double Evaluate(const arma::mat &iterate)
Evaluate the function at the given iterate point and store the result if it is a new minimum...
std::pair< arma::mat, double > minPointIterate
Best point found so far.
Definition: lbfgs.hpp:181
double Optimize(arma::mat &iterate)
Use L-BFGS to optimize the given function, starting at the given iterate point and finding the minimu...
The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function...
Definition: lbfgs.hpp:44
double wolfe
Parameter for detecting the Wolfe condition.
Definition: lbfgs.hpp:170
double MinStep() const
Return the minimum line search step size.
Definition: lbfgs.hpp:143
double MaxStep() const
Return the maximum line search step size.
Definition: lbfgs.hpp:148
double MinGradientNorm() const
Get the minimum gradient norm.
Definition: lbfgs.hpp:133
void UpdateBasisSet(const size_t iterationNum, const arma::mat &iterate, const arma::mat &oldIterate, const arma::mat &gradient, const arma::mat &oldGradient)
Update the y and s matrices, which store the differences between the iterate and old iterate and the ...
size_t numBasis
Size of memory for this L-BFGS optimizer.
Definition: lbfgs.hpp:164