softmax_regression_function.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_FUNCTION_HPP
14 #define MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_FUNCTION_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace regression {
20 
22 {
23  public:
35  SoftmaxRegressionFunction(const arma::mat& data,
36  const arma::Row<size_t>& labels,
37  const size_t numClasses,
38  const double lambda = 0.0001,
39  const bool fitIntercept = false);
40 
42  const arma::mat InitializeWeights();
43 
47  void Shuffle();
48 
58  static const arma::mat InitializeWeights(const size_t featureSize,
59  const size_t numClasses,
60  const bool fitIntercept = false);
61 
71  static void InitializeWeights(arma::mat &weights,
72  const size_t featureSize,
73  const size_t numClasses,
74  const bool fitIntercept = false);
75 
82  void GetGroundTruthMatrix(const arma::Row<size_t>& labels,
83  arma::sp_mat& groundTruth);
84 
96  void GetProbabilitiesMatrix(const arma::mat& parameters,
97  arma::mat& probabilities,
98  const size_t start,
99  const size_t batchSize) const;
100 
110  double Evaluate(const arma::mat& parameters) const;
111 
123  double Evaluate(const arma::mat& parameters,
124  const size_t start,
125  const size_t batchSize = 1) const;
126 
136  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
137 
149  void Gradient(const arma::mat& parameters,
150  const size_t start,
151  arma::mat& gradient,
152  const size_t batchSize = 1) const;
153 
163  void PartialGradient(const arma::mat& parameters,
164  size_t j,
165  arma::sp_mat& gradient) const;
166 
168  const arma::mat& GetInitialPoint() const { return initialPoint; }
169 
171  size_t NumClasses() const { return numClasses; }
172 
174  size_t NumFeatures() const
175  {
176  return initialPoint.n_cols;
177  }
182  size_t NumFunctions() const { return data.n_cols; }
183 
185  double& Lambda() { return lambda; }
187  double Lambda() const { return lambda; }
188 
190  bool FitIntercept() const { return fitIntercept; }
191 
192  private:
194  arma::mat data;
196  arma::sp_mat groundTruth;
198  arma::mat initialPoint;
200  size_t numClasses;
202  double lambda;
204  bool fitIntercept;
205 };
206 
207 } // namespace regression
208 } // namespace mlpack
209 
210 #endif
double Lambda() const
Gets the regularization parameter.
strip_type.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluates the gradient values of the objective function given the current set of parameters.
double & Lambda()
Sets the regularization parameter.
size_t NumClasses() const
Gets the number of classes.
size_t NumFeatures() const
Gets the features size of the training data.
SoftmaxRegressionFunction(const arma::mat &data, const arma::Row< size_t > &labels, const size_t numClasses, const double lambda=0.0001, const bool fitIntercept=false)
Construct the Softmax Regression objective function with the given parameters.
void GetProbabilitiesMatrix(const arma::mat &parameters, arma::mat &probabilities, const size_t start, const size_t batchSize) const
Evaluate the probabilities matrix with the passed parameters.
const arma::mat InitializeWeights()
Initializes the parameters of the model to suitable values.
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 GetGroundTruthMatrix(const arma::Row< size_t > &labels, arma::sp_mat &groundTruth)
Constructs the ground truth label matrix with the passed labels.
void PartialGradient(const arma::mat &parameters, size_t j, arma::sp_mat &gradient) const
Evaluates the gradient values of the objective function given the current set of parameters for a sin...
double Evaluate(const arma::mat &parameters) const
Evaluates the objective function of the softmax regression model using the given parameters.