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

#include <randomgridsearch.h>

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

Public Member Functions

 RandomGridSearchMulti ()=delete
 
 RandomGridSearchMulti (CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split, const std::vector< 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

std::vector< NumericTypebestParam
 

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::RandomGridSearchMulti< NumericType, Model, Metric, Split, typename >

Definition at line 95 of file randomgridsearch.h.

Constructor & Destructor Documentation

◆ RandomGridSearchMulti() [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::RandomGridSearchMulti< NumericType, Model, Metric, Split, typename >::RandomGridSearchMulti ( )
delete

◆ RandomGridSearchMulti() [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::RandomGridSearchMulti< NumericType, Model, Metric, Split, typename >::RandomGridSearchMulti ( CosanData< NumericType > &  CRD,
Model &  estimator,
Metric &  metric,
Split &  split,
const std::vector< std::vector< NumericType >> &  paramGrid,
long unsigned int  nsamples = 100 
)
inline

Definition at line 98 of file randomgridsearch.h.

103  : Search() {
104  NumericType minError = std::numeric_limits<NumericType>::infinity();
105  NumericType currError;
106  std::vector<std::vector<NumericType>> RandomChoice;
107  std::sample(paramGrid.begin(), paramGrid.end(), std::back_inserter(RandomChoice),
108  std::min({paramGrid.size(),nsamples}), std::mt19937{std::random_device{}()});
109 
110  decltype(bestParam) currParam;
111 
112  for (gsl::index i = 0; i < RandomChoice.size(); ++i){
113  currParam = paramGrid[i];
114  estimator.SetParams(paramGrid[i]);
115  currError = crossValidation(CRD, estimator, metric, split);
116  if (currError < minError)
117  {
118  minError = currError;
119  bestParam = currParam;
120  }
121  }
122  }

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::RandomGridSearchMulti< NumericType, Model, Metric, Split, typename >::GetBestParams ( )
inline

Definition at line 123 of file randomgridsearch.h.

123 {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>
std::vector<NumericType> Cosan::RandomGridSearchMulti< NumericType, Model, Metric, Split, typename >::bestParam
private

Definition at line 126 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::RandomGridSearchMulti::bestParam
std::vector< NumericType > bestParam
Definition: randomgridsearch.h:126
Cosan::Search::Search
Search()
Definition: selection.h:29