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 
21 namespace mlpack {
22 namespace regression {
23 
29 template<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 
52  LogisticRegressionFunction(const MatType& predictors,
53  const arma::Row<size_t>& responses,
54  const arma::vec& initialPoint,
55  const double lambda = 0);
56 
58  const arma::mat& InitialPoint() const { return initialPoint; }
60  arma::mat& InitialPoint() { return initialPoint; }
61 
63  const double& Lambda() const { return lambda; }
65  double& Lambda() { return lambda; }
66 
68  const MatType& Predictors() const { return predictors; }
70  const arma::Row<size_t>& Responses() const { return responses; }
71 
75  void Shuffle();
76 
88  double Evaluate(const arma::mat& parameters) const;
89 
107  double Evaluate(const arma::mat& parameters,
108  const size_t begin,
109  const size_t batchSize = 1) const;
110 
118  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
119 
133  template<typename GradType>
134  void Gradient(const arma::mat& parameters,
135  const size_t begin,
136  GradType& gradient,
137  const size_t batchSize = 1) const;
138 
150  void PartialGradient(const arma::mat& parameters,
151  const size_t j,
152  arma::sp_mat& gradient) const;
153 
158  template<typename GradType>
159  double EvaluateWithGradient(const arma::mat& parameters,
160  GradType& gradient) const;
161 
167  template<typename GradType>
168  double EvaluateWithGradient(const arma::mat& parameters,
169  const size_t begin,
170  GradType& gradient,
171  const size_t batchSize = 1) const;
172 
174  const arma::mat& GetInitialPoint() const { return initialPoint; }
175 
177  size_t NumFunctions() const { return predictors.n_cols; }
178 
180  size_t NumFeatures() const { return predictors.n_rows + 1; }
181 
182  private:
184  arma::mat initialPoint;
187  MatType predictors;
190  arma::Row<size_t> responses;
192  double lambda;
193 };
194 
195 } // namespace regression
196 } // namespace mlpack
197 
198 // Include implementation.
199 #include "logistic_regression_function_impl.hpp"
200 
201 #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.
strip_type.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...