Cosan  1.0
Data Analytics Library
Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename > Class Template Reference

#include <randomgridsearch.h>

Inheritance diagram for Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >:
Cosan::Search Cosan::Selection Cosan::CosanBO

Public Member Functions

 RandomGridSearch ()=delete
 
 RandomGridSearch (CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split, const std::vector< NumericType > &paramGrid, long unsigned int nsamples=100)
 
auto GetBestParams ()
 
- Public Member Functions inherited from Cosan::Selection
 Selection ()
 
- Public Member Functions inherited from Cosan::CosanBO
 CosanBO ()
 Default constructor. More...
 
virtual const std::string GetName () const
 Get the name of the objects. More...
 

Private Attributes

NumericType bestParam
 

Detailed Description

template<typename NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split, typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
class Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >

Definition at line 16 of file randomgridsearch.h.

Constructor & Destructor Documentation

◆ RandomGridSearch() [1/2]

template<typename NumericType , Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split, typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >::RandomGridSearch ( )
delete

◆ RandomGridSearch() [2/2]

template<typename NumericType , Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split, typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >::RandomGridSearch ( CosanData< NumericType > &  CRD,
Model &  estimator,
Metric &  metric,
Split &  split,
const std::vector< NumericType > &  paramGrid,
long unsigned int  nsamples = 100 
)
inline

Definition at line 19 of file randomgridsearch.h.

23  : Search() {
24  NumericType minError = std::numeric_limits<NumericType>::infinity();
25 
26  NumericType currError;
27  std::vector<NumericType> RandomChoice;
28  std::sample(paramGrid.begin(), paramGrid.end(), std::back_inserter(RandomChoice),
29  std::min({paramGrid.size(),nsamples}), std::mt19937{std::random_device{}()});
30 
31  decltype(bestParam) currParam;
32  for (gsl::index i = 0; i < RandomChoice.size(); ++i){
33  currParam = paramGrid[i];
34  estimator.SetParams(paramGrid[i]);
35  currError = crossValidation(CRD, estimator, metric, split);
36  if (currError < minError)
37  {
38  minError = currError;
39  bestParam = currParam;
40  }
41  }
42  }

Member Function Documentation

◆ GetBestParams()

template<typename NumericType , Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split, typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
auto Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >::GetBestParams ( )
inline

Definition at line 43 of file randomgridsearch.h.

43 {return bestParam;}

Member Data Documentation

◆ bestParam

template<typename NumericType , Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split, typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
NumericType Cosan::RandomGridSearch< NumericType, Model, Metric, Split, typename >::bestParam
private

Definition at line 46 of file randomgridsearch.h.


The documentation for this class was generated from the following file:
NumericType
double NumericType
Definition: onehotencodingTest.cpp:20
Cosan::crossValidation
NumericType crossValidation(CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split)
Definition: crossvalidation.h:32
Cosan::Search::Search
Search()
Definition: selection.h:29
Cosan::RandomGridSearch::bestParam
NumericType bestParam
Definition: randomgridsearch.h:46