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:
31  LogisticRegressionFunction(const MatType& predictors,
32  const arma::Row<size_t>& responses,
33  const double lambda = 0);
34 
35  LogisticRegressionFunction(const MatType& predictors,
36  const arma::Row<size_t>& responses,
37  const arma::vec& initialPoint,
38  const double lambda = 0);
39 
41  const arma::mat& InitialPoint() const { return initialPoint; }
43  arma::mat& InitialPoint() { return initialPoint; }
44 
46  const double& Lambda() const { return lambda; }
48  double& Lambda() { return lambda; }
49 
51  const MatType& Predictors() const { return predictors; }
53  const arma::Row<size_t>& Responses() const { return responses; }
54 
58  void Shuffle();
59 
71  double Evaluate(const arma::mat& parameters) const;
72 
90  double Evaluate(const arma::mat& parameters,
91  const size_t begin,
92  const size_t batchSize = 1) const;
93 
101  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
102 
116  template<typename GradType>
117  void Gradient(const arma::mat& parameters,
118  const size_t begin,
119  GradType& gradient,
120  const size_t batchSize = 1) const;
121 
133  void PartialGradient(const arma::mat& parameters,
134  const size_t j,
135  arma::sp_mat& gradient) const;
136 
141  template<typename GradType>
142  double EvaluateWithGradient(const arma::mat& parameters,
143  GradType& gradient) const;
144 
145  template<typename GradType>
146  double EvaluateWithGradient(const arma::mat& parameters,
147  const size_t begin,
148  GradType& gradient,
149  const size_t batchSize = 1) const;
150 
152  const arma::mat& GetInitialPoint() const { return initialPoint; }
153 
155  size_t NumFunctions() const { return predictors.n_cols; }
156 
158  size_t NumFeatures() const { return predictors.n_rows + 1; }
159 
160  private:
162  arma::mat initialPoint;
165  MatType predictors;
168  arma::Row<size_t> responses;
170  double lambda;
171 };
172 
173 } // namespace regression
174 } // namespace mlpack
175 
176 // Include implementation.
177 #include "logistic_regression_function_impl.hpp"
178 
179 #endif // MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
LogisticRegressionFunction(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)
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...