mlpack
|
The log-likelihood function for the logistic regression objective function. More...
#include <logistic_regression_function.hpp>
Public Member Functions | |
LogisticRegressionFunction (const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0) | |
Creates the LogisticRegressionFunction. More... | |
const double & | Lambda () const |
Return the regularization parameter (lambda). | |
double & | Lambda () |
Modify the regularization parameter (lambda). | |
const MatType & | Predictors () const |
Return the matrix of predictors. | |
const arma::Row< size_t > & | Responses () const |
Return the vector of responses. | |
void | Shuffle () |
Shuffle the order of function visitation. More... | |
double | Evaluate (const arma::mat ¶meters) const |
Evaluate the logistic regression log-likelihood function with the given parameters. More... | |
double | Evaluate (const arma::mat ¶meters, 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... | |
void | Gradient (const arma::mat ¶meters, 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 ¶meters, 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... | |
void | PartialGradient (const arma::mat ¶meters, 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... | |
template<typename GradType > | |
double | EvaluateWithGradient (const arma::mat ¶meters, GradType &gradient) const |
Evaluate the objective function and gradient of the logistic regression log-likelihood function simultaneously with the given parameters. | |
template<typename GradType > | |
double | EvaluateWithGradient (const arma::mat ¶meters, 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. | |
size_t | NumFunctions () const |
Return the number of separable functions (the number of predictor points). | |
size_t | NumFeatures () const |
Return the number of features(add 1 for the intercept term). | |
The log-likelihood function for the logistic regression objective function.
This is used by various mlpack optimizers to train a logistic regression model.
mlpack::regression::LogisticRegressionFunction< MatType >::LogisticRegressionFunction | ( | const MatType & | predictors, |
const arma::Row< size_t > & | responses, | ||
const double | lambda = 0 |
||
) |
Creates the LogisticRegressionFunction.
predictors | The matrix of data points. |
responses | The measured data for each point in predictors. |
lambda | Regularization constant for ridge regression. |
double mlpack::regression::LogisticRegressionFunction< MatType >::Evaluate | ( | const arma::mat & | parameters | ) | const |
Evaluate the logistic regression log-likelihood function with the given parameters.
Evaluate the logistic regression objective function given the estimated 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 | Vector of logistic regression parameters. |
double mlpack::regression::LogisticRegressionFunction< MatType >::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.
Evaluate the logistic regression objective function given the estimated parameters for a given batch from a given point.
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 | Vector of logistic regression parameters. |
begin | Index of the starting point to use for objective function evaluation. |
batchSize | Number of points to be passed at a time to use for objective function evaluation. |
void mlpack::regression::LogisticRegressionFunction< MatType >::Gradient | ( | const arma::mat & | parameters, |
arma::mat & | gradient | ||
) | const |
Evaluate the gradient of the logistic regression log-likelihood function with the given parameters.
Evaluate the gradient of the logistic regression objective function.
parameters | Vector of logistic regression parameters. |
gradient | Vector to output gradient into. |
void mlpack::regression::LogisticRegressionFunction< MatType >::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.
Evaluate the gradient of the logistic regression objective function for a given batch size.
This is useful for optimizers such as SGD, which require a separable objective function.
parameters | Vector of logistic regression parameters. |
begin | Index of the starting point to use for objective function gradient evaluation. |
gradient | Vector to output gradient into. |
batchSize | Number of points to be processed as a batch for objective function gradient evaluation. |
void mlpack::regression::LogisticRegressionFunction< MatType >::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.
Evaluate the partial gradient of the logistic regression objective function with respect to the individual features in the parameter.
This is useful for optimizers such as SCD, which require partial gradients.
parameters | Vector of logistic regression parameters. |
j | Index of the feature with respect to which the gradient is to be computed. |
gradient | Sparse matrix to output gradient into. |
void mlpack::regression::LogisticRegressionFunction< MatType >::Shuffle | ( | ) |
Shuffle the order of function visitation.
Shuffle the datapoints.
This may be called by the optimizer.