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
void Gradient(const arma::mat &coordinates, arma::mat &gradient) const
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: load.hpp:31
void Gradient(const arma::mat &coordinates, arma::mat &gradient)
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...
double Evaluate(const arma::mat &coordinates) const
const arma::mat & GetInitialPoint() const
const arma::mat & GetInitialPoint() const
void Gradient(const arma::mat &coordinates, arma::mat &gradient)
double Evaluate(const arma::mat &coordinates)
double Evaluate(const arma::mat &coordinates)