rastrigin_function.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_PROBLEMS_RASTRIGIN_FUNCTION_HPP
13 #define MLPACK_CORE_OPTIMIZERS_PROBLEMS_RASTRIGIN_FUNCTION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 namespace test {
20 
43 {
44  public:
45  /*
46  * Initialize the RastriginFunction.
47  *
48  * @param n Number of dimensions for the function.
49  */
50  RastriginFunction(const size_t n);
51 
56  void Shuffle();
57 
59  size_t NumFunctions() const { return n; }
60 
62  arma::mat GetInitialPoint() const { return initialPoint; }
63 
64  /*
65  * Evaluate a function for a particular batch-size.
66  *
67  * @param coordinates The function coordinates.
68  * @param begin The first function.
69  * @param batchSize Number of points to process.
70  */
71  double Evaluate(const arma::mat& coordinates,
72  const size_t begin,
73  const size_t batchSize) const;
74 
75  /*
76  * Evaluate a function with the given coordinates.
77  *
78  * @param coordinates The function coordinates.
79  */
80  double Evaluate(const arma::mat& coordinates) const;
81 
82  /*
83  * Evaluate the gradient of a function for a particular batch-size.
84  *
85  * @param coordinates The function coordinates.
86  * @param begin The first function.
87  * @param gradient The function gradient.
88  * @param batchSize Number of points to process.
89  */
90  void Gradient(const arma::mat& coordinates,
91  const size_t begin,
92  arma::mat& gradient,
93  const size_t batchSize) const;
94 
95  /*
96  * Evaluate the gradient of a function with the given coordinates.
97  *
98  * @param coordinates The function coordinates.
99  * @param gradient The function gradient.
100  */
101  void Gradient(const arma::mat& coordinates, arma::mat& gradient);
102  private:
104  size_t n;
105 
107  arma::Row<size_t> visitationOrder;
108 
110  arma::mat initialPoint;
111 };
112 
113 } // namespace test
114 } // namespace optimization
115 } // namespace mlpack
116 
117 #endif // MLPACK_CORE_OPTIMIZERS_PROBLEMS_RASTRIGIN_FUNCTION_HPP
size_t NumFunctions() const
Return 1 (the number of functions).
void Shuffle()
Shuffle the order of function visitation.
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
The Rastrigin function, defined by.
void Gradient(const arma::mat &coordinates, const size_t begin, arma::mat &gradient, const size_t batchSize) const
arma::mat GetInitialPoint() const
Get the starting point.
double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize) const