12#ifndef MLPACK_CORE_HPT_HPT_HPP
13#define MLPACK_CORE_HPT_HPT_HPP
17#include <ensmallen.hpp>
85template<
typename MLAlgorithm,
87 template<
typename,
typename,
typename,
typename,
typename>
class CV,
88 typename OptimizerType = ens::GridSearch,
89 typename MatType = arma::mat,
90 typename PredictionsType =
91 typename cv::MetaInfoExtractor<MLAlgorithm,
92 MatType>::PredictionsType,
93 typename WeightsType =
94 typename cv::MetaInfoExtractor<MLAlgorithm, MatType,
95 PredictionsType>::WeightsType>
106 template<
typename... CVArgs>
177 template<
typename... Args>
184 const MLAlgorithm&
BestModel()
const {
return bestModel; }
193 template<
typename OriginalMetric>
196 static double Evaluate(MLAlgorithm& model,
198 const PredictionsType& ys)
199 {
return -OriginalMetric::Evaluate(model, xs, ys); }
203 using CVType =
typename std::conditional<Metric::NeedsMinimization,
204 CV<MLAlgorithm, Metric, MatType, PredictionsType, WeightsType>,
205 CV<MLAlgorithm, Negated<Metric>, MatType, PredictionsType,
213 OptimizerType optimizer;
216 double bestObjective;
219 MLAlgorithm bestModel;
225 double relativeDelta;
237 template<
typename Tuple,
size_t I>
238 using IsPreFixed = IsPreFixedArg<typename std::tuple_element<I, Tuple>::type>;
244 template<
typename Tuple,
size_t I>
245 using IsArithmetic = std::is_arithmetic<
typename std::remove_reference<
246 typename std::tuple_element<I, Tuple>::type>::type>;
257 typename... FixedArgs,
259 inline void InitAndOptimize(
260 const ArgsTuple& args,
261 arma::mat& bestParams,
262 data::DatasetMapper<data::IncrementPolicy, double>& datasetInfo,
263 FixedArgs... fixedArgs);
275 typename... FixedArgs,
278 inline void InitAndOptimize(
279 const ArgsTuple& args,
280 arma::mat& bestParams,
281 data::DatasetMapper<data::IncrementPolicy, double>& datasetInfo,
282 FixedArgs... fixedArgs);
294 typename... FixedArgs,
297 IsArithmetic<ArgsTuple, I>::value>,
299 inline void InitAndOptimize(
300 const ArgsTuple& args,
301 arma::mat& bestParams,
302 data::DatasetMapper<data::IncrementPolicy, double>& datasetInfo,
303 FixedArgs... fixedArgs);
315 typename... FixedArgs,
318 !IsArithmetic<ArgsTuple, I>::value>,
321 inline void InitAndOptimize(
322 const ArgsTuple& args,
323 arma::mat& bestParams,
324 data::DatasetMapper<data::IncrementPolicy, double>& datasetInfo,
325 FixedArgs... fixedArgs);
331 template<
typename TupleType,
336 inline TupleType VectorToTuple(
const arma::vec& vector,
const Args&... args);
341 template<
typename TupleType,
347 inline TupleType VectorToTuple(
const arma::vec& vector,
const Args&... args);
354#include "hpt_impl.hpp"
The class HyperParameterTuner for the given MLAlgorithm utilizes the provided Optimizer to find the v...
double & RelativeDelta()
Modify relative increase of arguments for calculation of partial derivatives (by the definition) in g...
OptimizerType & Optimizer()
Access and modify the optimizer.
HyperParameterTuner(const CVArgs &...args)
Create a HyperParameterTuner object by passing constructor arguments for the given cross-validation s...
double & MinDelta()
Modify minimum increase of arguments for calculation of partial derivatives (by the definition) in gr...
MLAlgorithm & BestModel()
Modify the best model from the last run.
const MLAlgorithm & BestModel() const
Get the best model from the last run.
TupleOfHyperParameters< Args... > Optimize(const Args &... args)
Find the best hyper-parameters by using the given Optimizer.
double RelativeDelta() const
Get relative increase of arguments for calculation of partial derivatives (by the definition) in grad...
double BestObjective() const
Get the performance measurement of the best model from the last run.
double MinDelta() const
Get minimum increase of arguments for calculation of partial derivatives (by the definition) in gradi...
typename DeduceHyperParameterTypes< Args... >::TupleType TupleOfHyperParameters
A short alias for deducing types of hyper-parameters from types of arguments in the Optimize method i...
Linear algebra utility functions, generally performed on matrices or vectors.
typename enable_if< B, T >::type enable_if_t