Cosan  1.0
Data Analytics Library
Cosan Namespace Reference

Classes

class  CosanBO
 Cosan Base Object. More...
 
class  CosanData
 Data container. More...
 
class  CosanElasticNet
 
class  CosanLasso
 
class  CosanLinearModel
 CosanLinear Model. All linear model inherit this object. More...
 
class  CosanLinearRegression
 
class  CosanMetric
 CosanMetric class for metric functionality. More...
 
class  CosanModel
 Base Object for CosanModel. More...
 
class  CosanPCRRidge
 
class  CosanPrincipalComponentRegression
 
class  CosanRawData
 Raw Data container. More...
 
class  CosanRidgeRegression
 
class  CustomTransform
 
class  DiffSizeException
 
class  Encoder
 
class  Evaluation
 
class  GridSearch
 
class  GridSearchMulti
 
class  GridSearchMultiParallel
 
class  GridSearchParallel
 
class  InvalidLabelShapeException
 
class  KFold
 
class  KFoldParallel
 
class  MaxError
 maximum error More...
 
class  MeanAbsError
 Mean absolute error. More...
 
class  MeanSquareError
 Mean squared error. More...
 
class  MinmaxScaler
 
class  MissingValues
 
class  Normalizer
 
class  OnehotEncoder
 
class  OrdinalEncoder
 
class  OverUnderFlow
 
class  PolynomialFeatures
 
class  Preprocessor
 
class  PrincipalComponentAnalysis
 
class  R2Score
 R2 square. More...
 
class  RandomGridSearch
 
class  RandomGridSearchMulti
 
class  RandomGridSearchMultiParallel
 
class  RandomGridSearchParallel
 
class  RandomKFold
 
class  RandomKFoldParallel
 
class  Search
 
class  Selection
 
class  Splitter
 
class  StandardScaler
 
class  SummaryStatistics
 Class for statistics results. More...
 
class  Test
 
class  TimeSeriesSplit
 
class  TimeSeriesSplitParallel
 
class  TooSmallSizeException
 

Typedefs

template<Numeric NumericType>
using CosanMatrix = Eigen::Matrix< NumericType, Eigen::Dynamic, Eigen::Dynamic >
 
template<Numeric NumericType>
using CosanColVector = Eigen::Matrix< NumericType, Eigen::Dynamic, 1 >
 
template<Numeric NumericType>
using CosanRowVector = Eigen::Matrix< NumericType, 1, Eigen::Dynamic >
 
template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
using vec = std::vector< NumericType >
 

Enumerations

enum  EProblemType { PdNone = 0, PdBinaryClassification = 1, PdUnivariateRegression =2 }
 
enum  EModelType {
  MdNone = 0, MdLinearRegression =1, MdRidgeRegression =2, MdPrincipalComponentRegression =3,
  MdRidgePrincipalComponentRegression =4
}
 
enum  ESolverType { SrAuto = 0, ADMM = 1 }
 

Functions

template<Numeric NumericType>
NumericType getVMean (const std::vector< NumericType > &v)
 Calculate the mean of std::vector<NumericType> More...
 
template<Numeric NumericType>
NumericType StringToNum (const std::string &arg, std::size_t *pos=0)
 General string to number conversion function. More...
 
template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
NumericType crossValidation (CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split)
 
template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
NumericType crossValidationParallel (CosanData< NumericType > &CRD, Model &estimator, Metric &metric, Split &split, int nthreads=-1)
 
template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
bool SameSize (const CosanMatrix< NumericType > &m1, const CosanMatrix< NumericType > &m2)
 
template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
bool LabelShape (const CosanMatrix< NumericType > &m)
 
template<typename NumericType = std::string>
NumericType StringToNum (std::string arg)
 

Variables

Cosan::DiffSizeException DiffSize
 
Cosan::TooSmallSizeException SmallRows
 
Cosan::InvalidLabelShapeException InvalidLabelShape
 

Typedef Documentation

◆ CosanColVector

template<Numeric NumericType>
using Cosan::CosanColVector = typedef Eigen::Matrix<NumericType, Eigen::Dynamic, 1>

Description: data structure for column vector. Will be used throughout the project.

Definition at line 44 of file CosanBO.h.

◆ CosanMatrix

template<Numeric NumericType>
using Cosan::CosanMatrix = typedef Eigen::Matrix<NumericType, Eigen::Dynamic, Eigen::Dynamic>

Description: data structure for matrix. Will be used throughout the project.

Definition at line 37 of file CosanBO.h.

◆ CosanRowVector

template<Numeric NumericType>
using Cosan::CosanRowVector = typedef Eigen::Matrix<NumericType, 1, Eigen::Dynamic>

Description: data structure for row vector. Will be used throughout the project.

Definition at line 52 of file CosanBO.h.

◆ vec

template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
using Cosan::vec = typedef std::vector<NumericType>

Definition at line 14 of file templateTest.cpp.

Enumeration Type Documentation

◆ EModelType

Model Type

Enumerator
MdNone 
MdLinearRegression 
MdRidgeRegression 
MdPrincipalComponentRegression 
MdRidgePrincipalComponentRegression 

Definition at line 21 of file CosanModel.h.

◆ EProblemType

Problem Type.

Enumerator
PdNone 
PdBinaryClassification 
PdUnivariateRegression 

Definition at line 13 of file CosanModel.h.

13  {
14  PdNone = 0,
17  };

◆ ESolverType

Solver Type

Enumerator
SrAuto 
ADMM 

Definition at line 31 of file CosanModel.h.

31  {
32  SrAuto = 0,
33  ADMM = 1
34 
35  };

Function Documentation

◆ crossValidation()

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
NumericType Cosan::crossValidation ( CosanData< NumericType > &  CRD,
Model &  estimator,
Metric &  metric,
Split &  split 
)

Definition at line 32 of file crossvalidation.h.

35  {
36  split.SetSplit(CRD.GetrowsX());
37  CosanMatrix<NumericType> X = CRD.GetInput();
38  CosanMatrix<NumericType> Y = CRD.GetTarget();
39  std::vector<NumericType> errors;
40  errors.resize(split.GetKFoldNumber());
41  std::vector< std::tuple<std::vector<gsl::index>,std::vector<gsl::index> > > split_idx = split.GetSplit();
42 // #pragma omp parallel for
43  for (gsl::index i =0;i<split.GetKFoldNumber();i++){
44  auto & each = split_idx[i];
45  CosanMatrix<NumericType> X_train = X(std::get<0>(each),Eigen::all),Y_train = Y(std::get<0>(each),Eigen::all);
46  CosanMatrix<NumericType> X_test = X(std::get<1>(each),Eigen::all),Y_test = Y(std::get<1>(each),Eigen::all);
47  estimator.fit(X_train, Y_train);
48  errors[i] = metric.GetError(estimator.predict(X_test ),Y_test);
49  }
50  return std::accumulate(errors.begin(), errors.end(), 0)/errors.size();
51  };

◆ crossValidationParallel()

template<Numeric NumericType, Derived< CosanModel > Model, Derived< CosanMetric< NumericType >> Metric, Derived< Splitter > Split>
NumericType Cosan::crossValidationParallel ( CosanData< NumericType > &  CRD,
Model &  estimator,
Metric &  metric,
Split &  split,
int  nthreads = -1 
)

Definition at line 62 of file crossvalidation.h.

65  {
66  split.SetSplit(CRD.GetrowsX());
67  CosanMatrix<NumericType> X = CRD.GetInput();
68  CosanMatrix<NumericType> Y = CRD.GetTarget();
69  std::vector<NumericType> errors;
70  errors.resize(split.GetKFoldNumber());
71  std::vector< std::tuple<std::vector<gsl::index>,std::vector<gsl::index> > > split_idx = split.GetSplit();
72  if (nthreads == -1){
73  omp_set_num_threads(omp_get_max_threads());
74  }
75  else{
76  omp_set_num_threads(nthreads);
77  }
78  #pragma omp parallel for
79  for (gsl::index i =0;i<split.GetKFoldNumber();i++){
80  auto & each = split_idx[i];
81  CosanMatrix<NumericType> X_train = X(std::get<0>(each),Eigen::all),Y_train = Y(std::get<0>(each),Eigen::all);
82  CosanMatrix<NumericType> X_test = X(std::get<1>(each),Eigen::all),Y_test = Y(std::get<1>(each),Eigen::all);
83  estimator.fit(X_train, Y_train);
84  errors[i] = metric.GetError(estimator.predict(X_test ),Y_test);
85  }
86  return std::accumulate(errors.begin(), errors.end(), 0)/errors.size();
87  };

◆ getVMean()

template<Numeric NumericType>
NumericType Cosan::getVMean ( const std::vector< NumericType > &  v)

Calculate the mean of std::vector<NumericType>

Template Parameters
NumericType
Parameters
v
Returns
NumericType

Definition at line 96 of file statistics.h.

96  {
97  return std::accumulate(v.begin(), v.end(), 0)/v.size();
98 // NumericType total = 0;
99 // int size = v.size();
100 // std::accumulate(v.begin(), v.end(), 0)/v.size();
101 //
102 // for (vector<double>::iterator it = v.begin(); it != v.end(); ++it)
103 // {
104 // total += *it;
105 // }
106 //
107 // return total/size;
108  }

◆ LabelShape()

template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
bool Cosan::LabelShape ( const CosanMatrix< NumericType > &  m)

Definition at line 46 of file ArgCheck.h.

47  {
48  if ((m.rows() >= 1) && (m.cols() == 1)) {
49  return true;}
50  else{
51  return false;}
52  }

◆ SameSize()

template<typename NumericType , typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
bool Cosan::SameSize ( const CosanMatrix< NumericType > &  m1,
const CosanMatrix< NumericType > &  m2 
)

Definition at line 29 of file ArgCheck.h.

30  {
31  if ((m1.rows() == m2.rows) && (m1.cols() == m2.cols() ) ){
32  return true;}
33  else{
34  return false;}
35  };

◆ StringToNum() [1/2]

template<Numeric NumericType>
NumericType Cosan::StringToNum ( const std::string &  arg,
std::size_t *  pos = 0 
)

General string to number conversion function.

As we allow for user-determined numeric type NumericType, the detailed implementation or functions needed maybe slightly different among each other. For instance, when we are trying to read data from csv file. Different data type requires different string-to-numeric function. For double, one is required std::stod while 'std::stof' is the candidate function if float is chosen. To take care of this variant before running time, we conside the static-i. The feature allows us to discard branches of an if statement at compile-time based on a constant expression condition. In the following code as an example, we define a template function with input requiring NumericType as numeric and then the implementation is decided via if constexpr statement.

Definition at line 25 of file utils.h.

25  {
26  static_assert(std::is_arithmetic<NumericType>::value, "NumericType must be numeric");
27  if constexpr (std::is_same_v<NumericType, unsigned long>) {
28  return std::stoul(arg,pos);
29  }
30  else if constexpr (std::is_same_v<NumericType, unsigned long long>){
31  return std::stoull(arg,pos);
32  }
33  else if constexpr (std::is_same_v<NumericType, int>){
34  return std::stoi(arg,pos);
35  }
36  else if constexpr (std::is_same_v<NumericType, long>){
37  return std::stol(arg,pos);
38  }
39  else if constexpr (std::is_same_v<NumericType, long long>){
40  return std::stoll(arg,pos);
41  }
42  else if constexpr (std::is_same_v<NumericType, float>){
43  return std::stof(arg,pos);
44  }
45  else if constexpr (std::is_same_v<NumericType, double>){
46  return std::stod(arg,pos);
47  }
48  else{
49  return std::stold(arg,pos);
50  }
51  }

◆ StringToNum() [2/2]

template<typename NumericType = std::string>
NumericType Cosan::StringToNum ( std::string  arg)

Definition at line 22 of file templateTest.cpp.

22  {
23  if constexpr (std::is_same_v<NumericType, unsigned long>) {
24  return std::stoul(arg);
25  }
26  else if constexpr (std::is_same_v<NumericType, unsigned long long>){
27  return std::stoull(arg);
28  }
29  else if constexpr (std::is_same_v<NumericType, int>){
30  return std::stoi(arg);
31  }
32  else if constexpr (std::is_same_v<NumericType, long>){
33  return std::stol(arg);
34  }
35  else if constexpr (std::is_same_v<NumericType, long long>){
36  return std::stoll(arg);
37  }
38  else if constexpr (std::is_same_v<NumericType, float>){
39  return std::stof(arg);
40  }
41  else if constexpr (std::is_same_v<NumericType, double>){
42  return std::stod(arg);
43  }
44  else{
45  return std::stold(arg);
46  }
47  }

Variable Documentation

◆ DiffSize

Cosan::DiffSizeException Cosan::DiffSize

◆ InvalidLabelShape

Cosan::InvalidLabelShapeException Cosan::InvalidLabelShape

◆ SmallRows

Cosan::TooSmallSizeException Cosan::SmallRows
Cosan::SrAuto
@ SrAuto
Definition: CosanModel.h:32
Cosan::MdRidgeRegression
@ MdRidgeRegression
Definition: CosanModel.h:24
Cosan::PdBinaryClassification
@ PdBinaryClassification
Definition: CosanModel.h:15
Cosan::MdRidgePrincipalComponentRegression
@ MdRidgePrincipalComponentRegression
Definition: CosanModel.h:26
Cosan::ADMM
@ ADMM
Definition: CosanModel.h:33
Cosan::PdNone
@ PdNone
Definition: CosanModel.h:14
Cosan::MdNone
@ MdNone
Definition: CosanModel.h:22
Cosan::MdLinearRegression
@ MdLinearRegression
Definition: CosanModel.h:23
Cosan::PdUnivariateRegression
@ PdUnivariateRegression
Definition: CosanModel.h:16
Cosan::MdPrincipalComponentRegression
@ MdPrincipalComponentRegression
Definition: CosanModel.h:25