cv_function.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_HPT_CV_FUNCTION_HPP
13 #define MLPACK_CORE_HPT_CV_FUNCTION_HPP
14 
15 #include <mlpack/core.hpp>
16 
17 namespace mlpack {
18 namespace hpt {
19 
35 template<typename CVType,
36  typename MLAlgorithm,
37  size_t TotalArgs,
38  typename... BoundArgs>
40 {
41  public:
59  CVFunction(CVType& cv,
60  const double relativeDelta,
61  const double minDelta,
62  const BoundArgs&... args);
63 
70  double Evaluate(const arma::mat& parameters);
71 
80  void Gradient(const arma::mat& parameters, arma::mat& gradient);
81 
83  MLAlgorithm& BestModel() { return bestModel; }
84 
85  private:
87  using BoundArgsTupleType = std::tuple<BoundArgs...>;
88 
90  static const size_t BoundArgsAmount =
91  std::tuple_size<BoundArgsTupleType>::value;
92 
98  template<size_t BoundArgIndex,
99  size_t ParamIndex,
100  bool BoundArgsIndexInRange = (BoundArgIndex < BoundArgsAmount)>
101  struct UseBoundArg;
102 
104  CVType& cv;
105 
107  BoundArgsTupleType boundArgs;
108 
110  double bestObjective;
111 
113  MLAlgorithm bestModel;
114 
116  double relativeDelta;
117 
119  double minDelta;
120 
124  template<size_t BoundArgIndex,
125  size_t ParamIndex,
126  typename... Args,
127  typename = typename
128  std::enable_if<(BoundArgIndex + ParamIndex < TotalArgs)>::type>
129  inline double Evaluate(const arma::mat& parameters, const Args&... args);
130 
134  template<size_t BoundArgIndex,
135  size_t ParamIndex,
136  typename... Args,
137  typename = typename
138  std::enable_if<BoundArgIndex + ParamIndex == TotalArgs>::type,
139  typename = void>
140  inline double Evaluate(const arma::mat& parameters, const Args&... args);
141 
145  template<size_t BoundArgIndex,
146  size_t ParamIndex,
147  typename... Args,
148  typename = typename std::enable_if<
149  UseBoundArg<BoundArgIndex, ParamIndex>::value>::type>
150  inline double PutNextArg(const arma::mat& parameters, const Args&... args);
151 
156  template<size_t BoundArgIndex,
157  size_t ParamIndex,
158  typename... Args,
159  typename = typename std::enable_if<
160  !UseBoundArg<BoundArgIndex, ParamIndex>::value>::type,
161  typename = void>
162  inline double PutNextArg(const arma::mat& parameters, const Args&... args);
163 };
164 
165 
166 } // namespace hpt
167 } // namespace mlpack
168 
169 // Include implementation
170 #include "cv_function_impl.hpp"
171 
172 #endif
MLAlgorithm & BestModel()
Access and modify the best model so far.
Definition: cv_function.hpp:83
.hpp
Definition: add_to_po.hpp:21
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
double Evaluate(const arma::mat &parameters)
Run cross-validation with the bound and passed parameters.
This wrapper serves for adapting the interface of the cross-validation classes to the one that can be...
Definition: cv_function.hpp:39
void Gradient(const arma::mat &parameters, arma::mat &gradient)
Evaluate numerically the gradient of the CVFunction with the given parameters.
CVFunction(CVType &cv, const double relativeDelta, const double minDelta, const BoundArgs &... args)
Initialize a CVFunction object.