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

#include <randomgridsearch.h>

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

Public Member Functions

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

Definition at line 54 of file randomgridsearch.h.

Constructor & Destructor Documentation

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

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

Definition at line 57 of file randomgridsearch.h.

61  : Search() {
62  NumericType minError = std::numeric_limits<NumericType>::infinity();
63 
64  NumericType currError;
65  std::vector<NumericType> RandomChoice;
66  std::sample(paramGrid.begin(), paramGrid.end(), std::back_inserter(RandomChoice),
67  std::min({paramGrid.size(),nsamples}), std::mt19937{std::random_device{}()});
68 
69  std::vector<NumericType> allError(RandomChoice.size());
70  if (nthreads == -1){
71  omp_set_num_threads(omp_get_max_threads());
72  }
73  else{
74  omp_set_num_threads(nthreads);
75  }
76  #pragma omp parallel for
77  for (gsl::index i = 0; i < RandomChoice.size(); ++i){
78  estimator.SetParams(RandomChoice[i]);
79  allError[i] = crossValidation(CRD, estimator, metric, split);
80  }
81  bestParam =RandomChoice[std::distance(allError.begin(), std::min_element(allError.begin(), allError.end()))];
82 
83  }

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

Definition at line 84 of file randomgridsearch.h.

84 {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::RandomGridSearchParallel< NumericType, Model, Metric, Split, typename >::bestParam
private

Definition at line 87 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::RandomGridSearchParallel::bestParam
NumericType bestParam
Definition: randomgridsearch.h:87
Cosan::Search::Search
Search()
Definition: selection.h:29