MLPACK  1.0.10
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  const FunctionType& Function() const { return function; }
115  FunctionType& Function() { return function; }
116 
118  size_t NumBasis() const { return numBasis; }
120  size_t& NumBasis() { return numBasis; }
121 
123  size_t MaxIterations() const { return maxIterations; }
125  size_t& MaxIterations() { return maxIterations; }
126 
128  double ArmijoConstant() const { return armijoConstant; }
130  double& ArmijoConstant() { return armijoConstant; }
131 
133  double Wolfe() const { return wolfe; }
135  double& Wolfe() { return wolfe; }
136 
138  double MinGradientNorm() const { return minGradientNorm; }
140  double& MinGradientNorm() { return minGradientNorm; }
141 
143  size_t MaxLineSearchTrials() const { return maxLineSearchTrials; }
146 
148  double MinStep() const { return minStep; }
150  double& MinStep() { return minStep; }
151 
153  double MaxStep() const { return maxStep; }
155  double& MaxStep() { return maxStep; }
156 
157  // convert the obkect into a string
158  std::string ToString() const;
159 
160  private:
162  FunctionType& function;
163 
165  arma::mat newIterateTmp;
167  arma::cube s;
169  arma::cube y;
170 
172  size_t numBasis;
178  double wolfe;
184  double minStep;
186  double maxStep;
187 
189  std::pair<arma::mat, double> minPointIterate;
190 
197  double Evaluate(const arma::mat& iterate);
198 
206  double ChooseScalingFactor(const size_t iterationNum,
207  const arma::mat& gradient);
208 
215  bool GradientNormTooSmall(const arma::mat& gradient);
216 
230  bool LineSearch(double& functionValue,
231  arma::mat& iterate,
232  arma::mat& gradient,
233  const arma::mat& searchDirection);
234 
243  void SearchDirection(const arma::mat& gradient,
244  const size_t iterationNum,
245  const double scalingFactor,
246  arma::mat& searchDirection);
247 
259  void UpdateBasisSet(const size_t iterationNum,
260  const arma::mat& iterate,
261  const arma::mat& oldIterate,
262  const arma::mat& gradient,
263  const arma::mat& oldGradient);
264 };
265 
266 }; // namespace optimization
267 }; // namespace mlpack
268 
269 #include "lbfgs_impl.hpp"
270 
271 #endif // __MLPACK_CORE_OPTIMIZERS_LBFGS_LBFGS_HPP
272 
double ArmijoConstant() const
Get the Armijo condition constant.
Definition: lbfgs.hpp:128
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:125
double Wolfe() const
Get the Wolfe parameter.
Definition: lbfgs.hpp:133
size_t maxLineSearchTrials
Maximum number of trials for the line search.
Definition: lbfgs.hpp:182
arma::cube y
Stores all the y matrices in memory.
Definition: lbfgs.hpp:169
size_t & NumBasis()
Modify the memory size.
Definition: lbfgs.hpp:120
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: lbfgs.hpp:123
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:130
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:180
double maxStep
Maximum step of the line search.
Definition: lbfgs.hpp:186
double minStep
Minimum step of the line search.
Definition: lbfgs.hpp:184
double & MinGradientNorm()
Modify the minimum gradient norm.
Definition: lbfgs.hpp:140
double armijoConstant
Parameter for determining the Armijo condition.
Definition: lbfgs.hpp:176
double & MaxStep()
Modify the maximum line search step size.
Definition: lbfgs.hpp:155
size_t & MaxLineSearchTrials()
Modify the maximum number of line search trials.
Definition: lbfgs.hpp:145
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...
FunctionType & Function()
Modify the function that is being optimized.
Definition: lbfgs.hpp:115
double & Wolfe()
Modify the Wolfe parameter.
Definition: lbfgs.hpp:135
const FunctionType & Function() const
Return the function that is being optimized.
Definition: lbfgs.hpp:113
arma::mat newIterateTmp
Position of the new iterate.
Definition: lbfgs.hpp:165
arma::cube s
Stores all the s matrices in memory.
Definition: lbfgs.hpp:167
double & MinStep()
Modify the minimum line search step size.
Definition: lbfgs.hpp:150
size_t maxIterations
Maximum number of iterations.
Definition: lbfgs.hpp:174
size_t NumBasis() const
Get the memory size.
Definition: lbfgs.hpp:118
size_t MaxLineSearchTrials() const
Get the maximum number of line search trials.
Definition: lbfgs.hpp:143
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:189
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:178
double MinStep() const
Return the minimum line search step size.
Definition: lbfgs.hpp:148
double MaxStep() const
Return the maximum line search step size.
Definition: lbfgs.hpp:153
std::string ToString() const
double MinGradientNorm() const
Get the minimum gradient norm.
Definition: lbfgs.hpp:138
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:172