mlpack  2.0.1
test_functions.hpp
Go to the documentation of this file.
1 
20 #ifndef __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
21 #define __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
22 
23 #include <mlpack/core.hpp>
24 
25 // To fulfill the template policy class 'FunctionType', we must implement
26 // the following:
27 //
28 // FunctionType(); // constructor
29 // void Gradient(const arma::mat& coordinates, arma::mat& gradient);
30 // double Evaluate(const arma::mat& coordinates);
31 // const arma::mat& GetInitialPoint();
32 //
33 // Note that we are using an arma::mat instead of the more intuitive and
34 // expected arma::vec. This is because L-BFGS will also optimize matrices.
35 // However, remember that an arma::vec is simply an (n x 1) arma::mat. You can
36 // use either internally but the L-BFGS method requires arma::mat& to be passed
37 // (C++ does not allow implicit reference casting to subclasses).
38 
39 namespace mlpack {
40 namespace optimization {
41 namespace test {
42 
56 {
57  public:
58  RosenbrockFunction(); // initialize initial point
59 
60  double Evaluate(const arma::mat& coordinates);
61  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
62 
63  const arma::mat& GetInitialPoint() const;
64 
65  private:
66  arma::mat initialPoint;
67 };
68 
86 {
87  public:
88  WoodFunction(); // initialize initial point
89 
90  double Evaluate(const arma::mat& coordinates);
91  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
92 
93  const arma::mat& GetInitialPoint() const;
94 
95  private:
96  arma::mat initialPoint;
97 };
98 
116 {
117  public:
118  /***
119  * Set the dimensionality of the extended Rosenbrock function.
120  *
121  * @param n Number of dimensions for the function.
122  */
124 
125  double Evaluate(const arma::mat& coordinates) const;
126  void Gradient(const arma::mat& coordinates, arma::mat& gradient) const;
127 
128  size_t NumFunctions() const { return n - 1; }
129  double Evaluate(const arma::mat& coordinates, const size_t i) const;
130  void Gradient(const arma::mat& coordinates,
131  const size_t i,
132  arma::mat& gradient) const;
133 
134  const arma::mat& GetInitialPoint() const;
135 
136  private:
137  arma::mat initialPoint;
138  int n; // Dimensionality
139 };
140 
147 {
148  public:
149  RosenbrockWoodFunction(); // initialize initial point
150 
151  double Evaluate(const arma::mat& coordinates);
152  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
153 
154  const arma::mat& GetInitialPoint() const;
155 
156  private:
157  arma::mat initialPoint;
160 };
161 
162 } // namespace test
163 } // namespace optimization
164 } // namespace mlpack
165 
166 #endif // __MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
The Generalized Rosenbrock function in n dimensions, defined by f(x) = sum_i^{n - 1} (f(i)(x)) f_i(x)...
The Rosenbrock function, defined by f(x) = f1(x) + f2(x) f1(x) = 100 (x2 - x1^2)^2 f2(x) = (1 - x1)^2...
Linear algebra utility functions, generally performed on matrices or vectors.
void Gradient(const arma::mat &coordinates, arma::mat &gradient)
double Evaluate(const arma::mat &coordinates)
The Wood function, defined by f(x) = f1(x) + f2(x) + f3(x) + f4(x) + f5(x) + f6(x) f1(x) = 100 (x2 - ...
The Generalized Rosenbrock function in 4 dimensions with the Wood Function in four dimensions...
const arma::mat & GetInitialPoint() const
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...