mlpack  master
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:
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::vec& Responses() const { return responses; }
54 
66  double Evaluate(const arma::mat& parameters) const;
67 
82  double Evaluate(const arma::mat& parameters, const size_t i) const;
83 
91  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
92 
103  void Gradient(const arma::mat& parameters,
104  const size_t i,
105  arma::mat& gradient) const;
106 
108  const arma::mat& GetInitialPoint() const { return initialPoint; }
109 
111  size_t NumFunctions() const { return predictors.n_cols; }
112 
113  private:
115  arma::mat initialPoint;
117  const MatType& predictors;
119  const arma::Row<size_t>& responses;
121  double lambda;
122 };
123 
124 } // namespace regression
125 } // namespace mlpack
126 
127 // Include implementation.
128 #include "logistic_regression_function_impl.hpp"
129 
130 #endif // MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_FUNCTION_HPP
The log-likelihood function for the logistic regression objective function.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
arma::mat initialPoint
The initial point, from which to start the optimization.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
const MatType & predictors
The matrix of data points (predictors).
double & Lambda()
Modify the regularization parameter (lambda).
const double & Lambda() const
Return the regularization parameter (lambda).
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
const arma::vec & Responses() const
Return the vector of responses.
const arma::Row< size_t > & responses
The vector of responses to the input data points.
double Evaluate(const arma::mat &parameters) const
Evaluate the logistic regression log-likelihood function with the given parameters.
const arma::mat & InitialPoint() const
Return the initial point for the optimization.
arma::mat & InitialPoint()
Modify the initial point for the optimization.
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluate the gradient of the logistic regression log-likelihood function with the given parameters...
double lambda
The regularization parameter for L2-regularization.
const MatType & Predictors() const
Return the matrix of predictors.
LogisticRegressionFunction(const MatType &predictors, const arma::Row< size_t > &responses, const double lambda=0)