Machine learning algorithms in C++
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
MLP Class Reference

Multi-layer perceptron. More...

#include <MLP.hpp>

Collaboration diagram for MLP:

Public Types

enum  ActivationFunction { SIGMOID, TANH }
 
enum  WeightInitialization { NORMAL, UNIFORM, GLOROT }
 
enum  OutputFormat { ACTIVATION, SOFTMAX, ONEHOT, SUMMARY }
 

Public Member Functions

 MLP ()
 
void fit (MatrixD X, MatrixD y, vector< size_t > hiddenConfig, int maxIters, size_t batchSize=0, double learningRate=0.01, double errorThreshold=0.0001, double regularization=0, ActivationFunction func=SIGMOID, WeightInitialization weightInit=UNIFORM, bool adaptiveLR=false, bool standardize=true, bool verbose=true)
 Train a multiplayer perceptron. More...
 
void fit (MatrixD X, MatrixD y, vector< MatrixD > hiddenLayers, unsigned int maxIters, size_t batchSize=0, double learningRate=0.01, double errorThreshold=0.0001, double regularization=0, ActivationFunction func=SIGMOID, bool adaptiveLR=false, bool standardize=true, bool verbose=true)
 Train a multiplayer perceptron. More...
 
MatrixD predict (MatrixD X, OutputFormat of=ACTIVATION)
 Predict the classes of a data set. More...
 

Private Member Functions

MatrixD summarize (MatrixD m)
 

Static Private Member Functions

static double pow2 (double x)
 
static double sigmoid (double x)
 
static double sigmoidDerivative (double x)
 
static double tanh (double x)
 
static double tanhDerivative (double x)
 
static MatrixD initNormal (size_t in, size_t out)
 Initialize a matrix according to a normal distribution N(0; 1) More...
 
static MatrixD initNormal (size_t in, size_t out, double mean, double stddev)
 Initialize a matrix according to a normal distribution N(mean; stddev) More...
 
static MatrixD initUniform (size_t in, size_t out)
 Initialize a matrix according to the uniform distribution U(0;1) More...
 
static MatrixD initUniform (size_t in, size_t out, double min, double max)
 Initialize a matrix according to the uniform distribution U(min; max) More...
 
static MatrixD binarize (MatrixD m)
 
static MatrixD softmax (MatrixD m)
 

Private Attributes

MatrixD data
 
MatrixD dataMean
 
MatrixD dataDev
 
MatrixD classes
 
MatrixD originalClasses
 
vector< MatrixD > W
 

Detailed Description

Multi-layer perceptron.

Definition at line 23 of file MLP.hpp.

Member Enumeration Documentation

◆ ActivationFunction

Enumerator
SIGMOID 
TANH 

Definition at line 150 of file MLP.hpp.

◆ OutputFormat

Enumerator
ACTIVATION 
SOFTMAX 
ONEHOT 
SUMMARY 

Definition at line 152 of file MLP.hpp.

◆ WeightInitialization

Enumerator
NORMAL 
UNIFORM 
GLOROT 

Definition at line 151 of file MLP.hpp.

Constructor & Destructor Documentation

◆ MLP()

MLP::MLP ( )
inline

Definition at line 154 of file MLP.hpp.

Member Function Documentation

◆ binarize()

static MatrixD MLP::binarize ( MatrixD  m)
inlinestaticprivate

Definition at line 107 of file MLP.hpp.

Here is the caller graph for this function:

◆ fit() [1/2]

void MLP::fit ( MatrixD  X,
MatrixD  y,
vector< size_t >  hiddenConfig,
int  maxIters,
size_t  batchSize = 0,
double  learningRate = 0.01,
double  errorThreshold = 0.0001,
double  regularization = 0,
ActivationFunction  func = SIGMOID,
WeightInitialization  weightInit = UNIFORM,
bool  adaptiveLR = false,
bool  standardize = true,
bool  verbose = true 
)
inline

Train a multiplayer perceptron.

Parameters
XInput data, with rows representing examples and columns representing features
yInput labels as a column vector
hiddenConfigvector containing the number of neurons in each hidden layer
maxItersmaximum number of training iterations
batchSizesize of the batch. If <= 0, the whole data is used in every iteration
learningRatelearning rate
errorThresholdminimum error for early stopping
regularizationthe regularization parameter. 0 indicates no regularization.
funcactivation function
weightInitweight initilization procedure
adaptiveLRif true, the learning rate linearly decreases according to the number of iterations
standardizeif true, data is standardized according to its mean and standard deviation
verboseoutput training summary at each iteration

Definition at line 171 of file MLP.hpp.

◆ fit() [2/2]

void MLP::fit ( MatrixD  X,
MatrixD  y,
vector< MatrixD >  hiddenLayers,
unsigned int  maxIters,
size_t  batchSize = 0,
double  learningRate = 0.01,
double  errorThreshold = 0.0001,
double  regularization = 0,
ActivationFunction  func = SIGMOID,
bool  adaptiveLR = false,
bool  standardize = true,
bool  verbose = true 
)
inline

Train a multiplayer perceptron.

Parameters
XInput data, with rows representing examples and columns representing features
yInput labels as a column vector
hiddenLayersa vector of matrices, each one containing the weights for a hidden layer
maxItersmaximum number of training iterations
batchSizesize of the batch. If <= 0, the whole data is used in every iteration
learningRatelearning rate
errorThresholdminimum error for early stopping
regularizationthe regularization parameter. 0 indicates no regularization.
funcactivation function
adaptiveLRif true, the learning rate linearly decreases according to the number of iterations
standardizeif true, data is standardized according to its mean and standard deviation
verboseoutput training summary at each iteration

Definition at line 239 of file MLP.hpp.

Here is the call graph for this function:

◆ initNormal() [1/2]

static MatrixD MLP::initNormal ( size_t  in,
size_t  out 
)
inlinestaticprivate

Initialize a matrix according to a normal distribution N(0; 1)

Parameters
innumber of rows
outnumber of columns
Returns
a matrix of doubles, initialized according to the distribution

Definition at line 67 of file MLP.hpp.

◆ initNormal() [2/2]

static MatrixD MLP::initNormal ( size_t  in,
size_t  out,
double  mean,
double  stddev 
)
inlinestaticprivate

Initialize a matrix according to a normal distribution N(mean; stddev)

Parameters
innumber of rows
outnumber of columns
meanmean of the normal distribution
stddevstandard deviation of the normal distribution
Returns
a matrix of doubles, initialized according to the distribution

Definition at line 79 of file MLP.hpp.

◆ initUniform() [1/2]

static MatrixD MLP::initUniform ( size_t  in,
size_t  out 
)
inlinestaticprivate

Initialize a matrix according to the uniform distribution U(0;1)

Parameters
innumber of rows
outnumber of columns
Returns
a matrix of doubles, initialized according to the distribution

Definition at line 89 of file MLP.hpp.

◆ initUniform() [2/2]

static MatrixD MLP::initUniform ( size_t  in,
size_t  out,
double  min,
double  max 
)
inlinestaticprivate

Initialize a matrix according to the uniform distribution U(min; max)

Parameters
innumber of rows
outnumber of columns
minminimum value
maxmaximum value
Returns
a matrix of doubles, initialized according to the distribution

Definition at line 101 of file MLP.hpp.

◆ pow2()

static double MLP::pow2 ( double  x)
inlinestaticprivate
Parameters
x
Returns
x to the power of 2

Definition at line 32 of file MLP.hpp.

◆ predict()

MatrixD MLP::predict ( MatrixD  X,
OutputFormat  of = ACTIVATION 
)
inline

Predict the classes of a data set.

Parameters
XInput data to be classified
ofoutput format of the method
Returns
a matrix, each row containing the output of the network for an example of X

Definition at line 410 of file MLP.hpp.

Here is the call graph for this function:

◆ sigmoid()

static double MLP::sigmoid ( double  x)
inlinestaticprivate
Parameters
x
Returns
Sigmoid of x

Definition at line 38 of file MLP.hpp.

◆ sigmoidDerivative()

static double MLP::sigmoidDerivative ( double  x)
inlinestaticprivate
Parameters
x
Returns
Derivative of the sigmoid of x

Definition at line 44 of file MLP.hpp.

◆ softmax()

static MatrixD MLP::softmax ( MatrixD  m)
inlinestaticprivate

Definition at line 134 of file MLP.hpp.

Here is the caller graph for this function:

◆ summarize()

MatrixD MLP::summarize ( MatrixD  m)
inlineprivate

Definition at line 120 of file MLP.hpp.

Here is the caller graph for this function:

◆ tanh()

static double MLP::tanh ( double  x)
inlinestaticprivate
Parameters
x
Returns
Hyperbolic tangent of x

Definition at line 51 of file MLP.hpp.

◆ tanhDerivative()

static double MLP::tanhDerivative ( double  x)
inlinestaticprivate
Parameters
x
Returns
Derivative of the hyperbolic tangent of x

Definition at line 57 of file MLP.hpp.

Field Documentation

◆ classes

MatrixD MLP::classes
private

Definition at line 25 of file MLP.hpp.

◆ data

MatrixD MLP::data
private

Definition at line 25 of file MLP.hpp.

◆ dataDev

MatrixD MLP::dataDev
private

Definition at line 25 of file MLP.hpp.

◆ dataMean

MatrixD MLP::dataMean
private

Definition at line 25 of file MLP.hpp.

◆ originalClasses

MatrixD MLP::originalClasses
private

Definition at line 25 of file MLP.hpp.

◆ W

vector<MatrixD> MLP::W
private

Definition at line 26 of file MLP.hpp.


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