mlpack 3.4.2
logistic_regression_function.hpp
Go to the documentation of this file.
1
14#ifndef MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
15#define MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
16
17#include <mlpack/prereqs.hpp>
20
21namespace mlpack {
22namespace regression {
23
29template<typename MatType = arma::mat>
31{
32 public:
40 LogisticRegressionFunction(const MatType& predictors,
41 const arma::Row<size_t>& responses,
42 const double lambda = 0);
43
45 const double& Lambda() const { return lambda; }
47 double& Lambda() { return lambda; }
48
50 const MatType& Predictors() const { return predictors; }
52 const arma::Row<size_t>& Responses() const { return responses; }
53
57 void Shuffle();
58
70 double Evaluate(const arma::mat& parameters) const;
71
89 double Evaluate(const arma::mat& parameters,
90 const size_t begin,
91 const size_t batchSize = 1) const;
92
100 void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
101
115 template<typename GradType>
116 void Gradient(const arma::mat& parameters,
117 const size_t begin,
118 GradType& gradient,
119 const size_t batchSize = 1) const;
120
132 void PartialGradient(const arma::mat& parameters,
133 const size_t j,
134 arma::sp_mat& gradient) const;
135
140 template<typename GradType>
141 double EvaluateWithGradient(const arma::mat& parameters,
142 GradType& gradient) const;
143
149 template<typename GradType>
150 double EvaluateWithGradient(const arma::mat& parameters,
151 const size_t begin,
152 GradType& gradient,
153 const size_t batchSize = 1) const;
154
156 size_t NumFunctions() const { return predictors.n_cols; }
157
159 size_t NumFeatures() const { return predictors.n_rows + 1; }
160
161 private:
164 MatType predictors;
167 arma::Row<size_t> responses;
169 double lambda;
170};
171
172} // namespace regression
173} // namespace mlpack
174
175// Include implementation.
176#include "logistic_regression_function_impl.hpp"
177
178#endif // MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
The log-likelihood function for the logistic regression objective function.
double EvaluateWithGradient(const arma::mat &parameters, GradType &gradient) const
Evaluate the objective function and gradient of the logistic regression log-likelihood function simul...
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
void Shuffle()
Shuffle the order of function visitation.
size_t NumFeatures() const
Return the number of features(add 1 for the intercept term).
const double & Lambda() const
Return the regularization parameter (lambda).
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,...
double & Lambda()
Modify the regularization parameter (lambda).
const MatType & Predictors() const
Return the matrix of predictors.
double Evaluate(const arma::mat &parameters) const
Evaluate the logistic regression log-likelihood function with the given parameters.
LogisticRegressionFunction(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
Creates the LogisticRegressionFunction.
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 ba...
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluate the gradient of the logistic regression log-likelihood function with the given parameters.
const arma::Row< size_t > & Responses() const
Return the vector of responses.
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 simul...
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,...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.