add_decomposable_evaluate_const.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,
33 class AddDecomposableEvaluate
34 {
35  public:
36  // Provide a dummy overload so the name 'Evaluate' exists for this object.
37  double Evaluate(traits::UnconstructableType&, 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, const size_t index)
50  {
51  return static_cast<FunctionType*>(
52  static_cast<Function<FunctionType>*>(this))->Evaluate(coordinates,
53  index);
54  }
55 };
56 
61 template<typename FunctionType>
62 class AddDecomposableEvaluate<FunctionType, true, false>
63 {
64  public:
73  double Evaluate(const arma::mat& coordinates,
74  const size_t begin,
75  const size_t batchSize)
76  {
77  arma::mat gradient; // This will be ignored.
78  return static_cast<Function<FunctionType>*>(this)->EvaluateWithGradient(
79  coordinates, begin, gradient, batchSize);
80  }
81 };
82 
88 template<typename FunctionType,
89  bool HasDecomposableEvaluateWithGradient =
90  traits::HasEvaluateWithGradient<FunctionType,
92  bool HasDecomposableEvaluate =
93  traits::HasEvaluate<FunctionType,
96 
101 template<typename FunctionType>
102 class AddDecomposableEvaluateConst<FunctionType, true, false>
103 {
104  public:
113  double Evaluate(const arma::mat& coordinates,
114  const size_t begin,
115  const size_t batchSize) const
116  {
117  arma::mat gradient; // This will be ignored.
118  return
119  static_cast<const Function<FunctionType>*>(this)->EvaluateWithGradient(
120  coordinates, begin, gradient, batchSize);
121  }
122 };
123 
129 template<typename FunctionType,
130  bool HasDecomposableEvaluateWithGradient =
131  traits::HasEvaluateWithGradient<FunctionType,
133  bool HasDecomposableEvaluate =
134  traits::HasEvaluate<FunctionType,
137 
142 template<typename FunctionType>
143 class AddDecomposableEvaluateStatic<FunctionType, true, false>
144 {
145  public:
154  static double Evaluate(const arma::mat& coordinates,
155  const size_t begin,
156  const size_t batchSize)
157  {
158  arma::mat gradient; // This will be ignored.
159  return FunctionType::EvaluateWithGradient(coordinates, begin, gradient,
160  batchSize);
161  }
162 };
163 
164 } // namespace optimization
165 } // namespace mlpack
166 
167 #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
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...