LogisticRegressionFunction< MatType > Class Template Reference

The log-likelihood function for the logistic regression objective function. More...

Public Member Functions

 LogisticRegressionFunction (const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
 Creates the LogisticRegressionFunction. More...

 
 LogisticRegressionFunction (const MatType &predictors, const arma::Row< size_t > &responses, const arma::vec &initialPoint, const double lambda=0)
 Creates the LogisticRegressionFunction with initialPoint. More...

 
double Evaluate (const arma::mat &parameters) const
 Evaluate the logistic regression log-likelihood function with the given parameters. More...

 
double Evaluate (const arma::mat &parameters, const size_t begin, const size_t batchSize=1) const
 Evaluate the logistic regression log-likelihood function with the given parameters using the given batch size from the given point index. More...

 
template
<
typename
GradType
>
double EvaluateWithGradient (const arma::mat &parameters, GradType &gradient) const
 Evaluate the objective function and gradient of the logistic regression log-likelihood function simultaneously with the given parameters. More...

 
template
<
typename
GradType
>
double EvaluateWithGradient (const arma::mat &parameters, const size_t begin, GradType &gradient, const size_t batchSize=1) const
 Evaluate the objective function and gradient of the logistic regression log-likelihood function simultaneously with the given parameters, for the given batch size from a given point in the dataset. More...

 
const arma::mat & GetInitialPoint () const
 Return the initial point for the optimization. More...

 
void Gradient (const arma::mat &parameters, arma::mat &gradient) const
 Evaluate the gradient of the logistic regression log-likelihood function with the given parameters. More...

 
template
<
typename
GradType
>
void Gradient (const arma::mat &parameters, const size_t begin, GradType &gradient, const size_t batchSize=1) const
 Evaluate the gradient of the logistic regression log-likelihood function with the given parameters, for the given batch size from a given point in the dataset. More...

 
const arma::mat & InitialPoint () const
 Return the initial point for the optimization. More...

 
arma::mat & InitialPoint ()
 Modify the initial point for the optimization. More...

 
const double & Lambda () const
 Return the regularization parameter (lambda). More...

 
double & Lambda ()
 Modify the regularization parameter (lambda). More...

 
size_t NumFeatures () const
 Return the number of features(add 1 for the intercept term). More...

 
size_t NumFunctions () const
 Return the number of separable functions (the number of predictor points). More...

 
void PartialGradient (const arma::mat &parameters, const size_t j, arma::sp_mat &gradient) const
 Evaluate the gradient of the logistic regression log-likelihood function with the given parameters, and with respect to only one feature in the dataset. More...

 
const MatType & Predictors () const
 Return the matrix of predictors. More...

 
const arma::Row< size_t > & Responses () const
 Return the vector of responses. More...

 
void Shuffle ()
 Shuffle the order of function visitation. More...

 

Detailed Description


template
<
typename
MatType
=
arma::mat
>

class mlpack::regression::LogisticRegressionFunction< MatType >

The log-likelihood function for the logistic regression objective function.

This is used by various mlpack optimizers to train a logistic regression model.

Definition at line 28 of file logistic_regression_function.hpp.

Constructor & Destructor Documentation

◆ LogisticRegressionFunction() [1/2]

LogisticRegressionFunction ( const MatType &  predictors,
const arma::Row< size_t > &  responses,
const double  lambda = 0 
)

Creates the LogisticRegressionFunction.

Parameters
predictorsThe matrix of data points.
responsesThe measured data for each point in predictors.
lambdaRegularization constant for ridge regression.

◆ LogisticRegressionFunction() [2/2]

LogisticRegressionFunction ( const MatType &  predictors,
const arma::Row< size_t > &  responses,
const arma::vec &  initialPoint,
const double  lambda = 0 
)

Creates the LogisticRegressionFunction with initialPoint.

Parameters
predictorsThe matrix of data points.
responsesThe measured data for each point in predictors.
initialPointPoint from which to start the optimization.
lambdaRegularization constant for ridge regression.

Member Function Documentation

◆ Evaluate() [1/2]

double Evaluate ( const arma::mat &  parameters) const

Evaluate the logistic regression log-likelihood function with the given parameters.

Note that if a point has 0 probability of being classified directly with the given parameters, then Evaluate() will return nan (this is kind of a corner case and should not happen for reasonable models).

The optimum (minimum) of this function is 0.0, and occurs when each point is classified correctly with very high probability.

Parameters
parametersVector of logistic regression parameters.

Referenced by LogisticRegressionFunction< MatType >::Responses().

◆ Evaluate() [2/2]

double Evaluate ( const arma::mat &  parameters,
const size_t  begin,
const size_t  batchSize = 1 
) const

Evaluate the logistic regression log-likelihood function with the given parameters using the given batch size from the given point index.

This is useful for optimizers such as SGD, which require a separable objective function. Note that if the points have 0 probability of being classified correctly with the given parameters, then Evaluate() will return nan (this is kind of a corner case and should not happen for reasonable models).

The optimum (minimum) of this function is 0.0, and occurs when the points are classified correctly with very high probability.

Parameters
parametersVector of logistic regression parameters.
beginIndex of the starting point to use for objective function evaluation.
batchSizeNumber of points to be passed at a time to use for objective function evaluation.

◆ EvaluateWithGradient() [1/2]

double EvaluateWithGradient ( const arma::mat &  parameters,
GradType &  gradient 
) const

Evaluate the objective function and gradient of the logistic regression log-likelihood function simultaneously with the given parameters.

Referenced by LogisticRegressionFunction< MatType >::Responses().

◆ EvaluateWithGradient() [2/2]

double EvaluateWithGradient ( const arma::mat &  parameters,
const size_t  begin,
GradType &  gradient,
const size_t  batchSize = 1 
) const

Evaluate the objective function and gradient of the logistic regression log-likelihood function simultaneously with the given parameters, for the given batch size from a given point in the dataset.

◆ GetInitialPoint()

const arma::mat& GetInitialPoint ( ) const
inline

Return the initial point for the optimization.

Definition at line 172 of file logistic_regression_function.hpp.

◆ Gradient() [1/2]

void Gradient ( const arma::mat &  parameters,
arma::mat &  gradient 
) const

Evaluate the gradient of the logistic regression log-likelihood function with the given parameters.

Parameters
parametersVector of logistic regression parameters.
gradientVector to output gradient into.

Referenced by LogisticRegressionFunction< MatType >::Responses().

◆ Gradient() [2/2]

void Gradient ( const arma::mat &  parameters,
const size_t  begin,
GradType &  gradient,
const size_t  batchSize = 1 
) const

Evaluate the gradient of the logistic regression log-likelihood function with the given parameters, for the given batch size from a given point in the dataset.

This is useful for optimizers such as SGD, which require a separable objective function.

Parameters
parametersVector of logistic regression parameters.
beginIndex of the starting point to use for objective function gradient evaluation.
gradientVector to output gradient into.
batchSizeNumber of points to be processed as a batch for objective function gradient evaluation.

◆ InitialPoint() [1/2]

const arma::mat& InitialPoint ( ) const
inline

Return the initial point for the optimization.

Definition at line 56 of file logistic_regression_function.hpp.

◆ InitialPoint() [2/2]

arma::mat& InitialPoint ( )
inline

Modify the initial point for the optimization.

Definition at line 58 of file logistic_regression_function.hpp.

◆ Lambda() [1/2]

const double& Lambda ( ) const
inline

Return the regularization parameter (lambda).

Definition at line 61 of file logistic_regression_function.hpp.

◆ Lambda() [2/2]

double& Lambda ( )
inline

Modify the regularization parameter (lambda).

Definition at line 63 of file logistic_regression_function.hpp.

◆ NumFeatures()

size_t NumFeatures ( ) const
inline

Return the number of features(add 1 for the intercept term).

Definition at line 178 of file logistic_regression_function.hpp.

◆ NumFunctions()

size_t NumFunctions ( ) const
inline

Return the number of separable functions (the number of predictor points).

Definition at line 175 of file logistic_regression_function.hpp.

◆ PartialGradient()

void PartialGradient ( const arma::mat &  parameters,
const size_t  j,
arma::sp_mat &  gradient 
) const

Evaluate the gradient of the logistic regression log-likelihood function with the given parameters, and with respect to only one feature in the dataset.

This is useful for optimizers such as SCD, which require partial gradients.

Parameters
parametersVector of logistic regression parameters.
jIndex of the feature with respect to which the gradient is to be computed.
gradientSparse matrix to output gradient into.

Referenced by LogisticRegressionFunction< MatType >::Responses().

◆ Predictors()

const MatType& Predictors ( ) const
inline

Return the matrix of predictors.

Definition at line 66 of file logistic_regression_function.hpp.

◆ Responses()

◆ Shuffle()

void Shuffle ( )

Shuffle the order of function visitation.

This may be called by the optimizer.

Referenced by LogisticRegressionFunction< MatType >::Responses().


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