mlpack  master
test_functions.hpp
Go to the documentation of this file.
1 
18 #ifndef MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
19 #define MLPACK_CORE_OPTIMIZERS_LBFGS_TEST_FUNCTIONS_HPP
20 
21 #include <mlpack/prereqs.hpp>
22 
23 // To fulfill the template policy class 'FunctionType', we must implement
24 // the following:
25 //
26 // FunctionType(); // constructor
27 // void Gradient(const arma::mat& coordinates, arma::mat& gradient);
28 // double Evaluate(const arma::mat& coordinates);
29 // const arma::mat& GetInitialPoint();
30 //
31 // Note that we are using an arma::mat instead of the more intuitive and
32 // expected arma::vec. This is because L-BFGS will also optimize matrices.
33 // However, remember that an arma::vec is simply an (n x 1) arma::mat. You can
34 // use either internally but the L-BFGS method requires arma::mat& to be passed
35 // (C++ does not allow implicit reference casting to subclasses).
36 
37 namespace mlpack {
38 namespace optimization {
39 namespace test {
40 
54 {
55  public:
56  RosenbrockFunction(); // initialize initial point
57 
58  double Evaluate(const arma::mat& coordinates);
59  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
60 
61  const arma::mat& GetInitialPoint() const;
62 
63  private:
64  arma::mat initialPoint;
65 };
66 
84 {
85  public:
86  WoodFunction(); // initialize initial point
87 
88  double Evaluate(const arma::mat& coordinates);
89  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
90 
91  const arma::mat& GetInitialPoint() const;
92 
93  private:
94  arma::mat initialPoint;
95 };
96 
114 {
115  public:
116  /***
117  * Set the dimensionality of the extended Rosenbrock function.
118  *
119  * @param n Number of dimensions for the function.
120  */
122 
123  double Evaluate(const arma::mat& coordinates) const;
124  void Gradient(const arma::mat& coordinates, arma::mat& gradient) const;
125 
126  size_t NumFunctions() const { return n - 1; }
127  double Evaluate(const arma::mat& coordinates, const size_t i) const;
128  void Gradient(const arma::mat& coordinates,
129  const size_t i,
130  arma::mat& gradient) const;
131 
132  const arma::mat& GetInitialPoint() const;
133 
134  private:
135  arma::mat initialPoint;
136  int n; // Dimensionality
137 };
138 
145 {
146  public:
147  RosenbrockWoodFunction(); // initialize initial point
148 
149  double Evaluate(const arma::mat& coordinates);
150  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
151 
152  const arma::mat& GetInitialPoint() const;
153 
154  private:
155  arma::mat initialPoint;
158 };
159 
160 } // namespace test
161 } // namespace optimization
162 } // namespace mlpack
163 
164 #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.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
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