Cosan  1.0
Data Analytics Library
Cosan::StandardScaler< NumericType > Class Template Reference

#include <standardScaler.h>

Inheritance diagram for Cosan::StandardScaler< NumericType >:
Cosan::Preprocessor< NumericType > Cosan::CosanBO

Public Member Functions

 StandardScaler ()=default
 
 StandardScaler (CosanRawData< NumericType > &RD)
 
CosanRowVector< NumericTypeGetMean () const
 
CosanRowVector< NumericTypeGetStd () const
 
void fit (CosanRawData< NumericType > &RD)
 
void fit (const CosanMatrix< NumericType > &X) override
 
CosanMatrix< NumericTypetransform (const CosanMatrix< NumericType > &X) override
 
CosanMatrix< NumericTypeInvTransform (const CosanMatrix< NumericType > &X)
 
- Public Member Functions inherited from Cosan::Preprocessor< NumericType >
 Preprocessor ()
 
virtual ~Preprocessor ()=default
 
- 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

CosanRowVector< NumericTypemean
 
CosanRowVector< NumericTypestd
 

Detailed Description

template<Numeric NumericType>
class Cosan::StandardScaler< NumericType >

Standardize features by removing the mean and scaling to unit variance

Definition at line 11 of file standardScaler.h.

Constructor & Destructor Documentation

◆ StandardScaler() [1/2]

template<Numeric NumericType>
Cosan::StandardScaler< NumericType >::StandardScaler ( )
default

◆ StandardScaler() [2/2]

template<Numeric NumericType>
Cosan::StandardScaler< NumericType >::StandardScaler ( CosanRawData< NumericType > &  RD)
inline

Definition at line 19 of file standardScaler.h.

19  :Preprocessor<NumericType>(){
20  this->fit(RD);
21  }

Member Function Documentation

◆ fit() [1/2]

template<Numeric NumericType>
void Cosan::StandardScaler< NumericType >::fit ( const CosanMatrix< NumericType > &  X)
inlineoverridevirtual

Reimplemented from Cosan::Preprocessor< NumericType >.

Definition at line 28 of file standardScaler.h.

28  {
29  fmt::print("*********************************\n");
30  fmt::print("Begin standardizing data \n");
31  this->mean = X.colwise().mean();
32  this->std = ((X.rowwise() - this->mean).array().pow(2).colwise().sum() / X.rows()).sqrt();
33  if ((this->std.array()==0).any()==true){
34  std::cout<<"Error!"<<std::endl;
35  for (gsl::index idx = 0;idx<this->std.size();idx++ ){
36  if (this->std[idx]==0){
37  std::cout<<"Column "<<idx<<" has identical values!"<<std::endl;
38  }
39  }
40  throw std::invalid_argument(
41  "Check your column! Some column has identical values!"
42  );
43  }
44 
45  fmt::print("End of standardizing data. One may transform or reverse-transform by .transform(),.InvTransform() function. \n");
46  fmt::print("*********************************\n");
47  };

◆ fit() [2/2]

template<Numeric NumericType>
void Cosan::StandardScaler< NumericType >::fit ( CosanRawData< NumericType > &  RD)
inline

Definition at line 24 of file standardScaler.h.

24  {
25  fit(RD.GetInput());
26  RD.UpdateData(transform(RD.GetInput()));
27  }

◆ GetMean()

template<Numeric NumericType>
CosanRowVector<NumericType> Cosan::StandardScaler< NumericType >::GetMean ( ) const
inline

Definition at line 22 of file standardScaler.h.

22 {return this->mean;}

◆ GetStd()

template<Numeric NumericType>
CosanRowVector<NumericType> Cosan::StandardScaler< NumericType >::GetStd ( ) const
inline

Definition at line 23 of file standardScaler.h.

23 {return this->std;}

◆ InvTransform()

template<Numeric NumericType>
CosanMatrix<NumericType> Cosan::StandardScaler< NumericType >::InvTransform ( const CosanMatrix< NumericType > &  X)
inline

Definition at line 52 of file standardScaler.h.

52  {
53  return (X.array().rowwise()*(this->std.array())).array().rowwise()+this->mean.array();
54  };

◆ transform()

template<Numeric NumericType>
CosanMatrix<NumericType> Cosan::StandardScaler< NumericType >::transform ( const CosanMatrix< NumericType > &  X)
inlineoverridevirtual

Reimplemented from Cosan::Preprocessor< NumericType >.

Definition at line 48 of file standardScaler.h.

48  {
49  return (X.rowwise() - this->mean).array().rowwise() / this->std.array();
50  };

Member Data Documentation

◆ mean

template<Numeric NumericType>
CosanRowVector<NumericType> Cosan::StandardScaler< NumericType >::mean
private

Definition at line 56 of file standardScaler.h.

◆ std

template<Numeric NumericType>
CosanRowVector<NumericType> Cosan::StandardScaler< NumericType >::std
private

Definition at line 57 of file standardScaler.h.


The documentation for this class was generated from the following file:
Cosan::StandardScaler::fit
void fit(CosanRawData< NumericType > &RD)
Definition: standardScaler.h:24
Cosan::StandardScaler::mean
CosanRowVector< NumericType > mean
Definition: standardScaler.h:54
Cosan::StandardScaler::transform
CosanMatrix< NumericType > transform(const CosanMatrix< NumericType > &X) override
Definition: standardScaler.h:48
Cosan::StandardScaler::std
CosanRowVector< NumericType > std
Definition: standardScaler.h:57