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