philsupertramp/game-math
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
LogRegSGD Class Reference

#include <LogRegSGD.h>

Inheritance diagram for LogRegSGD:
ANNClassifier Classifier Predictor

Public Member Functions

 LogRegSGD (double _eta=0.01, int iter=10, bool _shuffle=false, int _randomState=0)
 
void fit (const Matrix< double > &X, const Matrix< double > &y) override
 
void partial_fit (const Matrix< double > &X, const Matrix< double > &y)
 
Matrix< double > netInput (const Matrix< double > &X) override
 
Matrix< double > activation (const Matrix< double > &X) override
 
Matrix< double > predict (const Matrix< double > &X) override
 
double costFunction (const Matrix< double > &mat) override
 
- Public Member Functions inherited from ANNClassifier
 ANNClassifier (double _eta, int _n_iter)
 
virtual Matrix< double > activation (const Matrix< double > &)=0
 
virtual Matrix< double > netInput (const Matrix< double > &)=0
 
virtual double costFunction (const Matrix< double > &)=0
 
- Public Member Functions inherited from Classifier
 Classifier ()
 
void initialize_weights (size_t numRows, size_t numColumns=1)
 
void update_weights (const Matrix< double > &update, const Matrix< double > &delta)
 
Matrix< double > transform (const Matrix< double > &in) override
 
virtual void fit (const Matrix< double > &X, const Matrix< double > &y)=0
 
virtual Matrix< double > predict (const Matrix< double > &)=0
 
virtual Matrix< double > transform (const Matrix< double > &)=0
 

Public Attributes

bool shuffle
 signalizes whether given dataset should be shuffled while fitting More...
 
int randomState
 initialize weights with random state More...
 
SGDsgd = nullptr
 algorithmic object to represent fitting algorithm More...
 
- Public Attributes inherited from Classifier
Matrix< double > weights
 Vector holding weights. More...
 
Matrix< double > costs
 Vector holding classification error per epoch. More...
 

Private Member Functions

void initialize_weights (size_t m)
 
double update_weights (const Matrix< double > &xi, const Matrix< double > &target)
 

Static Private Member Functions

static Matrix< double > Log (const Matrix< double > &in)
 

Additional Inherited Members

- Protected Attributes inherited from ANNClassifier
double eta
 Learning rate. More...
 
int n_iter
 number epochs More...
 
- Protected Attributes inherited from Classifier
bool w_initialized = false
 flag to initialize weights only once More...
 

Detailed Description

Logistical regression model using statistic gradient decent method for model fitting.

Examples
ds/TestLogRegSGD.cpp.

Constructor & Destructor Documentation

◆ LogRegSGD()

LogRegSGD::LogRegSGD ( double  _eta = 0.01,
int  iter = 10,
bool  _shuffle = false,
int  _randomState = 0 
)
inlineexplicit

default constructor

Parameters
_etalearning rate
iternumber learning iterations
_shuffleshuffle data in each iteration?
_randomStateseed for random state

Member Function Documentation

◆ activation()

Matrix< double > LogRegSGD::activation ( const Matrix< double > &  X)
inlineoverridevirtual

activate given input $$x\mapsto \phi(x)$$

Parameters
Xinput values
Returns
activated values

Implements ANNClassifier.

◆ costFunction()

double LogRegSGD::costFunction ( const Matrix< double > &  mat)
inlineoverridevirtual

do not use!

Parameters
mat
Returns

Implements ANNClassifier.

◆ fit()

void LogRegSGD::fit ( const Matrix< double > &  X,
const Matrix< double > &  y 
)
inlineoverridevirtual

fits the weights of the model for given input values

Parameters
Xarray-like with the shape: [n_samples, n_features]
yarray-like with shape: [n_samples, 1]
Returns
this

Implements Predictor.

◆ initialize_weights()

void LogRegSGD::initialize_weights ( size_t  m)
inlineprivate

helper to initialize weights matrix

Parameters
mdimension

◆ Log()

static Matrix< double > LogRegSGD::Log ( const Matrix< double > &  in)
inlinestaticprivate

Calculates log of each element. Implementation doesn't use Matrix::Apply

Parameters
ininput matrix
Returns

◆ netInput()

Matrix< double > LogRegSGD::netInput ( const Matrix< double > &  X)
inlineoverridevirtual

calculate netinput

Parameters
Xinput values
Returns

Implements ANNClassifier.

◆ partial_fit()

void LogRegSGD::partial_fit ( const Matrix< double > &  X,
const Matrix< double > &  y 
)
inline

partially fit weights

Parameters
Xinput values
ytarget output values

◆ predict()

Matrix< double > LogRegSGD::predict ( const Matrix< double > &  X)
inlineoverridevirtual

predict output for given input

Parameters
Xinput values
Returns
predicted output for given input

Implements Predictor.

◆ update_weights()

double LogRegSGD::update_weights ( const Matrix< double > &  xi,
const Matrix< double > &  target 
)
inlineprivate

logistical regression

Parameters
xiinput values
targettarget output values
Returns
cost

Member Data Documentation

◆ randomState

int LogRegSGD::randomState

initialize weights with random state

◆ sgd

SGD* LogRegSGD::sgd = nullptr

algorithmic object to represent fitting algorithm

◆ shuffle

bool LogRegSGD::shuffle

signalizes whether given dataset should be shuffled while fitting


The documentation for this class was generated from the following file: