MLPACK  1.0.10
test_functions.hpp
Go to the documentation of this file.
1 
28 #ifndef __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
29 #define __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
30 
31 #include <mlpack/core.hpp>
32 
33 // To fulfill the template policy class 'FunctionType', we must implement
34 // the following:
35 //
36 // FunctionType(); // constructor
37 // void Gradient(const arma::mat& coordinates, arma::mat& gradient);
38 // double Evaluate(const arma::mat& coordinates);
39 // const arma::mat& GetInitialPoint();
40 //
41 // Note that we are using an arma::mat instead of the more intuitive and
42 // expected arma::vec. This is because L-BFGS will also optimize matrices.
43 // However, remember that an arma::vec is simply an (n x 1) arma::mat. You can
44 // use either internally but the L-BFGS method requires arma::mat& to be passed
45 // (C++ does not allow implicit reference casting to subclasses).
46 
47 namespace mlpack {
48 namespace optimization {
49 namespace test {
50 
64 {
65  public:
66  RosenbrockFunction(); // initialize initial point
67 
68  double Evaluate(const arma::mat& coordinates);
69  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
70 
71  const arma::mat& GetInitialPoint() const;
72 
73  private:
74  arma::mat initialPoint;
75 };
76 
94 {
95  public:
96  WoodFunction(); // initialize initial point
97 
98  double Evaluate(const arma::mat& coordinates);
99  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
100 
101  const arma::mat& GetInitialPoint() const;
102 
103  private:
104  arma::mat initialPoint;
105 };
106 
124 {
125  public:
126  /***
127  * Set the dimensionality of the extended Rosenbrock function.
128  *
129  * @param n Number of dimensions for the function.
130  */
132 
133  double Evaluate(const arma::mat& coordinates) const;
134  void Gradient(const arma::mat& coordinates, arma::mat& gradient) const;
135 
136  size_t NumFunctions() const { return n - 1; }
137  double Evaluate(const arma::mat& coordinates, const size_t i) const;
138  void Gradient(const arma::mat& coordinates,
139  const size_t i,
140  arma::mat& gradient) const;
141 
142  const arma::mat& GetInitialPoint() const;
143 
144  private:
145  arma::mat initialPoint;
146  int n; // Dimensionality
147 };
148 
155 {
156  public:
157  RosenbrockWoodFunction(); // initialize initial point
158 
159  double Evaluate(const arma::mat& coordinates);
160  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
161 
162  const arma::mat& GetInitialPoint() const;
163 
164  private:
165  arma::mat initialPoint;
168 };
169 
170 }; // namespace test
171 }; // namespace optimization
172 }; // namespace mlpack
173 
174 #endif // __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP