add_decomposable_evaluate.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_OPTIMIZERS_FUNCTION_ADD_DECOMPOSABLE_EVALUATE_HPP
14 #define MLPACK_CORE_OPTIMIZERS_FUNCTION_ADD_DECOMPOSABLE_EVALUATE_HPP
15 
16 #include "traits.hpp"
17 
18 namespace mlpack {
19 namespace optimization {
20 
26 template<typename FunctionType,
27  bool HasDecomposableEvaluateWithGradient =
28  traits::HasEvaluateWithGradient<FunctionType,
30  bool HasDecomposableEvaluate =
31  traits::HasEvaluate<FunctionType,
34 {
35  public:
36  // Provide a dummy overload so the name 'Evaluate' exists for this object.
37  double Evaluate(traits::UnconstructableType&, const size_t, const size_t);
38 };
39 
43 template<typename FunctionType, bool HasDecomposableEvaluateWithGradient>
44 class AddDecomposableEvaluate<FunctionType, HasDecomposableEvaluateWithGradient,
45  true>
46 {
47  public:
48  // Reflect the existing Evaluate().
49  double Evaluate(const arma::mat& coordinates,
50  const size_t begin,
51  const size_t batchSize)
52  {
53  return static_cast<FunctionType*>(
54  static_cast<Function<FunctionType>*>(this))->Evaluate(coordinates,
55  begin, batchSize);
56  }
57 };
58 
63 template<typename FunctionType>
64 class AddDecomposableEvaluate<FunctionType, true, false>
65 {
66  public:
75  double Evaluate(const arma::mat& coordinates,
76  const size_t begin,
77  const size_t batchSize)
78  {
79  arma::mat gradient; // This will be ignored.
80  return static_cast<Function<FunctionType>*>(this)->EvaluateWithGradient(
81  coordinates, begin, gradient, batchSize);
82  }
83 };
84 
90 template<typename FunctionType,
91  bool HasDecomposableEvaluateWithGradient =
92  traits::HasEvaluateWithGradient<FunctionType,
94  bool HasDecomposableEvaluate =
95  traits::HasEvaluate<FunctionType,
98 {
99  public:
100  // Provide a dummy overload so the name 'Evaluate' exists for this object.
101  double Evaluate(traits::UnconstructableType&, const size_t, const size_t)
102  const;
103 };
104 
108 template<typename FunctionType, bool HasDecomposableEvaluateWithGradient>
109 class AddDecomposableEvaluateConst<FunctionType,
110  HasDecomposableEvaluateWithGradient, true>
111 {
112  public:
113  // Reflect the existing Evaluate().
114  double Evaluate(const arma::mat& coordinates,
115  const size_t begin,
116  const size_t batchSize) const
117  {
118  return static_cast<const FunctionType*>(
119  static_cast<const Function<FunctionType>*>(this))->Evaluate(coordinates,
120  begin, batchSize);
121  }
122 };
123 
128 template<typename FunctionType>
129 class AddDecomposableEvaluateConst<FunctionType, true, false>
130 {
131  public:
140  double Evaluate(const arma::mat& coordinates,
141  const size_t begin,
142  const size_t batchSize) const
143  {
144  arma::mat gradient; // This will be ignored.
145  return
146  static_cast<const Function<FunctionType>*>(this)->EvaluateWithGradient(
147  coordinates, begin, gradient, batchSize);
148  }
149 };
150 
156 template<typename FunctionType,
157  bool HasDecomposableEvaluateWithGradient =
158  traits::HasEvaluateWithGradient<FunctionType,
160  bool HasDecomposableEvaluate =
161  traits::HasEvaluate<FunctionType,
164 {
165  public:
166  // Provide a dummy overload so the name 'Evaluate' exists for this object.
167  double Evaluate(traits::UnconstructableType&, const size_t) const;
168 };
169 
173 template<typename FunctionType, bool HasDecomposableEvaluateWithGradient>
174 class AddDecomposableEvaluateStatic<FunctionType,
175  HasDecomposableEvaluateWithGradient, true>
176 {
177  public:
178  // Reflect the existing Evaluate().
179  static double Evaluate(const arma::mat& coordinates,
180  const size_t begin,
181  const size_t batchSize)
182  {
183  return FunctionType::Evaluate(coordinates, begin, batchSize);
184  }
185 };
186 
191 template<typename FunctionType>
192 class AddDecomposableEvaluateStatic<FunctionType, true, false>
193 {
194  public:
203  static double Evaluate(const arma::mat& coordinates,
204  const size_t begin,
205  const size_t batchSize)
206  {
207  arma::mat gradient; // This will be ignored.
208  return FunctionType::EvaluateWithGradient(coordinates, begin, gradient,
209  batchSize);
210  }
211 };
212 
213 } // namespace optimization
214 } // namespace mlpack
215 
216 #endif
.hpp
Definition: add_to_po.hpp:21
The AddDecomposableEvaluate mixin class will add a decomposable Evaluate() method if a decomposable E...
The AddDecomposableEvaluateStatic mixin class will add a decomposable static Evaluate() method if a d...
double(FunctionType::*)(const arma::mat &, const size_t, const size_t) const DecomposableEvaluateConstForm
This is the form of a decomposable const Evaluate() method.
Definition: traits.hpp:117
double(*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientStaticForm
This is the form of a decomposable static EvaluateWithGradient() method.
Definition: traits.hpp:152
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) const DecomposableEvaluateWithGradientConstForm
This is the form of a decomposable const EvaluateWithGradient() method.
Definition: traits.hpp:147
static double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize)
double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize)
This is a utility type used to provide unusable overloads from each of the mixin classes.
Definition: traits.hpp:255
double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize)
Return the objective function for the given coordinates, starting at the given decomposable function ...
double Evaluate(traits::UnconstructableType &, const size_t, const size_t)
static double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize)
Return the objective function for the given coordinates, starting at the given decomposable function ...
double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize) const
Return the objective function for the given coordinates, starting at the given decomposable function ...
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientForm
This is the form of a decomposable non-const EvaluateWithGradient() method.
Definition: traits.hpp:142
The Function class is a wrapper class for any FunctionType that will add any possible derived methods...
Definition: function.hpp:22
double(*)(const arma::mat &, const size_t, const size_t) DecomposableEvaluateStaticForm
This is the form of a decomposable static Evaluate() method.
Definition: traits.hpp:122
double(FunctionType::*)(const arma::mat &, const size_t, const size_t) DecomposableEvaluateForm
This is the form of a decomposable Evaluate() method.
Definition: traits.hpp:112
The AddDecomposableEvaluateConst mixin class will add a decomposable const Evaluate() method if a dec...
double Evaluate(const arma::mat &coordinates, const size_t begin, const size_t batchSize) const