mlpack  3.4.2
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:
62  CVFunction(CVType& cv,
64  const double relativeDelta,
65  const double minDelta,
66  const BoundArgs&... args);
67 
74  double Evaluate(const arma::mat& parameters);
75 
84  void Gradient(const arma::mat& parameters, arma::mat& gradient);
85 
87  MLAlgorithm& BestModel() { return bestModel; }
88 
89  private:
91  using BoundArgsTupleType = std::tuple<BoundArgs...>;
92 
94  static const size_t BoundArgsAmount =
95  std::tuple_size<BoundArgsTupleType>::value;
96 
102  template<size_t BoundArgIndex,
103  size_t ParamIndex,
104  bool BoundArgsIndexInRange = (BoundArgIndex < BoundArgsAmount)>
105  struct UseBoundArg;
106 
108  CVType& cv;
109 
112 
114  BoundArgsTupleType boundArgs;
115 
117  double bestObjective;
118 
120  MLAlgorithm bestModel;
121 
123  double relativeDelta;
124 
126  double minDelta;
127 
131  template<size_t BoundArgIndex,
132  size_t ParamIndex,
133  typename... Args,
134  typename = typename
135  std::enable_if<(BoundArgIndex + ParamIndex < TotalArgs)>::type>
136  inline double Evaluate(const arma::mat& parameters, const Args&... args);
137 
141  template<size_t BoundArgIndex,
142  size_t ParamIndex,
143  typename... Args,
144  typename = typename
145  std::enable_if<BoundArgIndex + ParamIndex == TotalArgs>::type,
146  typename = void>
147  inline double Evaluate(const arma::mat& parameters, const Args&... args);
148 
152  template<size_t BoundArgIndex,
153  size_t ParamIndex,
154  typename... Args,
155  typename = typename std::enable_if<
156  UseBoundArg<BoundArgIndex, ParamIndex>::value>::type>
157  inline double PutNextArg(const arma::mat& parameters, const Args&... args);
158 
163  template<size_t BoundArgIndex,
164  size_t ParamIndex,
165  typename... Args,
166  typename = typename std::enable_if<
167  !UseBoundArg<BoundArgIndex, ParamIndex>::value>::type,
168  typename = void>
169  inline double PutNextArg(const arma::mat& parameters, const Args&... args);
170 };
171 
172 
173 } // namespace hpt
174 } // namespace mlpack
175 
176 // Include implementation
177 #include "cv_function_impl.hpp"
178 
179 #endif
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
This wrapper serves for adapting the interface of the cross-validation classes to the one that can be...
Definition: cv_function.hpp:40
MLAlgorithm & BestModel()
Access and modify the best model so far.
Definition: cv_function.hpp:87
double Evaluate(const arma::mat &parameters)
Run cross-validation with the bound and passed parameters.
CVFunction(CVType &cv, data::DatasetMapper< data::IncrementPolicy, double > &datasetInfo, const double relativeDelta, const double minDelta, const BoundArgs &... args)
Initialize a CVFunction object.
void Gradient(const arma::mat &parameters, arma::mat &gradient)
Evaluate numerically the gradient of the CVFunction with the given parameters.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
Linear algebra utility functions, generally performed on matrices or vectors.