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

#include <randomgridsearch.h>

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

Public Member Functions

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

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

Definition at line 134 of file randomgridsearch.h.

Constructor & Destructor Documentation

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

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

Definition at line 137 of file randomgridsearch.h.

142  : Search() {
143  NumericType minError = std::numeric_limits<NumericType>::infinity();
144  NumericType currError;
145  std::vector<NumericType> RandomChoice;
146  std::sample(paramGrid.begin(), paramGrid.end(), std::back_inserter(RandomChoice),
147  std::min({paramGrid.size(),nsamples}), std::mt19937{std::random_device{}()});
148  std::vector<std::vector<NumericType>> allError(paramGrid.size());
149  if (nthreads == -1){
150  omp_set_num_threads(omp_get_max_threads());
151  }
152  else{
153  omp_set_num_threads(nthreads);
154  }
155  #pragma omp parallel for
156  for (gsl::index i = 0; i < paramGrid.size(); ++i){
157  estimator.SetParams(paramGrid[i]);
158  allError[i] = crossValidation(CRD, estimator, metric, split);
159  }
160  bestParam =paramGrid[std::distance(allError.begin(), std::min_element(allError.begin(), allError.end()))];
161  }

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

Definition at line 162 of file randomgridsearch.h.

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

Definition at line 165 of file randomgridsearch.h.


The documentation for this class was generated from the following file:
Cosan::RandomGridSearchMultiParallel::bestParam
std::vector< NumericType > bestParam
Definition: randomgridsearch.h:165
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