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

#include <CosanPCRRidge.h>

Inheritance diagram for Cosan::CosanPCRRidge< NumericType >:
Cosan::CosanPrincipalComponentRegression< NumericType > Cosan::CosanLinearModel< NumericType > Cosan::CosanModel Cosan::CosanBO

Public Member Functions

 CosanPCRRidge ()
 
 CosanPCRRidge (std::vector< NumericType > params, bool bias=false)
 
 CosanPCRRidge (CosanRawData< NumericType > &RD, std::vector< NumericType > params, bool bias=false)
 
 CosanPCRRidge (CosanData< NumericType > &CD, std::vector< NumericType > params, bool bias=false)
 
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
 CosanPCRRidge (T &&X, const CosanMatrix< NumericType > &Y, std::vector< NumericType > params, bool bias=false)
 
virtual EModelType GetModelType () override
 
virtual EProblemType GetProblemType ()
 
virtual const std::string GetName () const override
 Get the name of the objects. More...
 
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
void fit (T &&X, const CosanMatrix< NumericType > &Y)
 
void SetParams (std::vector< NumericType > params)
 
NumericType GetParams ()
 
CosanMatrix< NumericType > & GetPC ()
 
- Public Member Functions inherited from Cosan::CosanPrincipalComponentRegression< NumericType >
 CosanPrincipalComponentRegression ()
 
 CosanPrincipalComponentRegression (NumericType ncomp, bool bias=false)
 
 CosanPrincipalComponentRegression (CosanRawData< NumericType > &RD, NumericType ncomp, bool bias=false)
 
 CosanPrincipalComponentRegression (CosanData< NumericType > &CD, NumericType ncomp, bool bias=false)
 
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
 CosanPrincipalComponentRegression (T &&X, const CosanMatrix< NumericType > &Y, NumericType ncomp, bool bias=false)
 
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
void fit (T &&X, const CosanMatrix< NumericType > &Y)
 
virtual CosanMatrix< NumericTypepredict (const CosanMatrix< NumericType > &X) override
 
CosanMatrix< NumericType > & GetPC ()
 
void SetParams (NumericType ncomp)
 
NumericType GetParams ()
 
- Public Member Functions inherited from Cosan::CosanLinearModel< NumericType >
 CosanLinearModel ()=delete
 
 CosanLinearModel (bool Bias)
 
void SetBias (const bool NewBias)
 
virtual void SetBeta (CosanMatrix< NumericType > InitBeta)
 
const CosanMatrix< NumericType > & GetBeta () const
 
bool GetBias () const
 
- Public Member Functions inherited from Cosan::CosanModel
 CosanModel ()
 
virtual void SetMaxTrainTime (double t)
 
virtual double GetMaxTrainTime () const
 
virtual ESolverType GetSolverType () const
 
void SetSolverType (ESolverType sr)
 
- Public Member Functions inherited from Cosan::CosanBO
 CosanBO ()
 Default constructor. More...
 

Private Attributes

NumericType MLambda
 

Additional Inherited Members

- Protected Attributes inherited from Cosan::CosanPrincipalComponentRegression< NumericType >
NumericType __ncomp
 
CosanMatrix< NumericTypePC
 
CosanMatrix< NumericTypeDerivatedCovariate
 
- Protected Attributes inherited from Cosan::CosanLinearModel< NumericType >
CosanMatrix< NumericTypeMBeta
 
bool MBias
 
- Protected Attributes inherited from Cosan::CosanModel
double MaxTrainTime
 
ESolverType SolverType
 

Detailed Description

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

principal component regression with L2 square penaly term on coefficient beta.

Template Parameters
NumericTypehttps://en.wikipedia.org/wiki/Principal_component_regression

Definition at line 19 of file CosanPCRRidge.h.

Constructor & Destructor Documentation

◆ CosanPCRRidge() [1/5]

template<Numeric NumericType>
Cosan::CosanPCRRidge< NumericType >::CosanPCRRidge ( )
inline

Definition at line 22 of file CosanPCRRidge.h.

22 : CosanPrincipalComponentRegression<NumericType>(){}

◆ CosanPCRRidge() [2/5]

template<Numeric NumericType>
Cosan::CosanPCRRidge< NumericType >::CosanPCRRidge ( std::vector< NumericType params,
bool  bias = false 
)
inline

Definition at line 23 of file CosanPCRRidge.h.

23  : CosanPrincipalComponentRegression<NumericType>(params[0]){
24  MLambda = params[1];}

◆ CosanPCRRidge() [3/5]

template<Numeric NumericType>
Cosan::CosanPCRRidge< NumericType >::CosanPCRRidge ( CosanRawData< NumericType > &  RD,
std::vector< NumericType params,
bool  bias = false 
)
inline

Definition at line 26 of file CosanPCRRidge.h.

26  : CosanPrincipalComponentRegression<NumericType>(params[0]){
27  MLambda = params[1];
28  fit(RD.GetInput(),RD.GetTarget());
29  }

◆ CosanPCRRidge() [4/5]

template<Numeric NumericType>
Cosan::CosanPCRRidge< NumericType >::CosanPCRRidge ( CosanData< NumericType > &  CD,
std::vector< NumericType params,
bool  bias = false 
)
inline

Definition at line 30 of file CosanPCRRidge.h.

30  : CosanPrincipalComponentRegression<NumericType>(params[0]){
31  MLambda = params[1];
32  fit(CD.GetInput(),CD.GetTarget());
33  }

◆ CosanPCRRidge() [5/5]

template<Numeric NumericType>
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
Cosan::CosanPCRRidge< NumericType >::CosanPCRRidge ( T &&  X,
const CosanMatrix< NumericType > &  Y,
std::vector< NumericType params,
bool  bias = false 
)
inline

Definition at line 36 of file CosanPCRRidge.h.

36  : CosanPrincipalComponentRegression<NumericType>(params[0]){
37  MLambda = params[1];
38  this->PC = PrincipalComponentAnalysis(X,this->__ncomp).GetPC();
39  this->DerivatedCovariate = X*(this->PC);
40  CosanMatrix<NumericType> Identity = MLambda*CosanMatrix<NumericType>::Identity((this->PC).cols(),(this->PC).cols());
41  this->MBeta = ((this->DerivatedCovariate).transpose()*(this->DerivatedCovariate)+Identity).ldlt().solve((this->DerivatedCovariate).transpose()*Y);
42  }

Member Function Documentation

◆ fit()

template<Numeric NumericType>
template<class T , std::enable_if_t< std::is_same_v< std::decay_t< T >, CosanMatrix< NumericType >>, bool > = true>
void Cosan::CosanPCRRidge< NumericType >::fit ( T &&  X,
const CosanMatrix< NumericType > &  Y 
)
inline

Definition at line 56 of file CosanPCRRidge.h.

56  {
57  this->PC = PrincipalComponentAnalysis(X,this->__ncomp).GetPC();
58  this->DerivatedCovariate = X*(this->PC);
59  CosanMatrix<NumericType> Identity = MLambda*CosanMatrix<NumericType>::Identity((this->PC).cols(),(this->PC).cols());
60  this->MBeta = ((this->DerivatedCovariate).transpose()*(this->DerivatedCovariate)+Identity).ldlt().solve((this->DerivatedCovariate).transpose()*Y);
61  }

◆ GetModelType()

template<Numeric NumericType>
virtual EModelType Cosan::CosanPCRRidge< NumericType >::GetModelType ( )
inlineoverridevirtual

Reimplemented from Cosan::CosanPrincipalComponentRegression< NumericType >.

Definition at line 44 of file CosanPCRRidge.h.

44  {
46  };

◆ GetName()

template<Numeric NumericType>
virtual const std::string Cosan::CosanPCRRidge< NumericType >::GetName ( ) const
inlineoverridevirtual

Get the name of the objects.

Description: Get the name of the object. It should return "Abstract Object"

Reimplemented from Cosan::CosanPrincipalComponentRegression< NumericType >.

Definition at line 50 of file CosanPCRRidge.h.

50  {
51  return "Principal Component Regression with least square and ridge regularization";}

◆ GetParams()

template<Numeric NumericType>
NumericType Cosan::CosanPCRRidge< NumericType >::GetParams ( )
inline

Definition at line 65 of file CosanPCRRidge.h.

65 {return {this->__ncomp ,MLambda};}

◆ GetPC()

template<Numeric NumericType>
CosanMatrix<NumericType>& Cosan::CosanPCRRidge< NumericType >::GetPC ( )
inline

Definition at line 66 of file CosanPCRRidge.h.

66 {return this->PC;}

◆ GetProblemType()

template<Numeric NumericType>
virtual EProblemType Cosan::CosanPCRRidge< NumericType >::GetProblemType ( )
inlinevirtual

Reimplemented from Cosan::CosanPrincipalComponentRegression< NumericType >.

Definition at line 48 of file CosanPCRRidge.h.

48  {
49  return PdUnivariateRegression;}

◆ SetParams()

template<Numeric NumericType>
void Cosan::CosanPCRRidge< NumericType >::SetParams ( std::vector< NumericType params)
inline

Definition at line 62 of file CosanPCRRidge.h.

62  {
63  this->__ncomp = params[0];
64  MLambda = params[1]; };

Member Data Documentation

◆ MLambda

template<Numeric NumericType>
NumericType Cosan::CosanPCRRidge< NumericType >::MLambda
private

Definition at line 68 of file CosanPCRRidge.h.


The documentation for this class was generated from the following file:
Cosan::CosanPCRRidge::fit
void fit(T &&X, const CosanMatrix< NumericType > &Y)
Definition: CosanPCRRidge.h:56
Cosan::CosanLinearModel::MBeta
CosanMatrix< NumericType > MBeta
Definition: CosanLinearModel.h:56
Cosan::CosanPrincipalComponentRegression::__ncomp
NumericType __ncomp
Definition: CosanPrincipalComponentRegression.h:72
Cosan::MdRidgePrincipalComponentRegression
@ MdRidgePrincipalComponentRegression
Definition: CosanModel.h:26
Cosan::CosanPrincipalComponentRegression::PC
CosanMatrix< NumericType > PC
Definition: CosanPrincipalComponentRegression.h:73
Cosan::PdUnivariateRegression
@ PdUnivariateRegression
Definition: CosanModel.h:16
Cosan::CosanPrincipalComponentRegression::DerivatedCovariate
CosanMatrix< NumericType > DerivatedCovariate
Definition: CosanPrincipalComponentRegression.h:74
Cosan::CosanPCRRidge::MLambda
NumericType MLambda
Definition: CosanPCRRidge.h:68