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>
18 
19 namespace mlpack {
20 namespace regression {
21 
27 template<typename MatType = arma::mat>
29 {
30  public:
38  LogisticRegressionFunction(const MatType& predictors,
39  const arma::Row<size_t>& responses,
40  const double lambda = 0);
41 
50  LogisticRegressionFunction(const MatType& predictors,
51  const arma::Row<size_t>& responses,
52  const arma::vec& initialPoint,
53  const double lambda = 0);
54 
56  const arma::mat& InitialPoint() const { return initialPoint; }
58  arma::mat& InitialPoint() { return initialPoint; }
59 
61  const double& Lambda() const { return lambda; }
63  double& Lambda() { return lambda; }
64 
66  const MatType& Predictors() const { return predictors; }
68  const arma::Row<size_t>& Responses() const { return responses; }
69 
73  void Shuffle();
74 
86  double Evaluate(const arma::mat& parameters) const;
87 
105  double Evaluate(const arma::mat& parameters,
106  const size_t begin,
107  const size_t batchSize = 1) const;
108 
116  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
117 
131  template<typename GradType>
132  void Gradient(const arma::mat& parameters,
133  const size_t begin,
134  GradType& gradient,
135  const size_t batchSize = 1) const;
136 
148  void PartialGradient(const arma::mat& parameters,
149  const size_t j,
150  arma::sp_mat& gradient) const;
151 
156  template<typename GradType>
157  double EvaluateWithGradient(const arma::mat& parameters,
158  GradType& gradient) const;
159 
165  template<typename GradType>
166  double EvaluateWithGradient(const arma::mat& parameters,
167  const size_t begin,
168  GradType& gradient,
169  const size_t batchSize = 1) const;
170 
172  const arma::mat& GetInitialPoint() const { return initialPoint; }
173 
175  size_t NumFunctions() const { return predictors.n_cols; }
176 
178  size_t NumFeatures() const { return predictors.n_rows + 1; }
179 
180  private:
182  arma::mat initialPoint;
185  MatType predictors;
188  arma::Row<size_t> responses;
190  double lambda;
191 };
192 
193 } // namespace regression
194 } // namespace mlpack
195 
196 // Include implementation.
197 #include "logistic_regression_function_impl.hpp"
198 
199 #endif // MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
LogisticRegressionFunction(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
Creates the LogisticRegressionFunction.
The log-likelihood function for the logistic regression objective function.
.hpp
Definition: add_to_po.hpp:21
double Evaluate(const arma::mat &parameters) const
Evaluate the logistic regression log-likelihood function with the given parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const double & Lambda() const
Return the regularization parameter (lambda).
double EvaluateWithGradient(const arma::mat &parameters, GradType &gradient) const
Evaluate the objective function and gradient of the logistic regression log-likelihood function simul...
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
void Shuffle()
Shuffle the order of function visitation.
arma::mat & InitialPoint()
Modify the initial point for the optimization.
const arma::mat & InitialPoint() const
Return the initial point for the optimization.
const MatType & Predictors() const
Return the matrix of predictors.
const arma::Row< size_t > & Responses() const
Return the vector of responses.
double & Lambda()
Modify the regularization parameter (lambda).
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...
size_t NumFeatures() const
Return the number of features(add 1 for the intercept term).
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluate the gradient of the logistic regression log-likelihood function with the given parameters...