mlpack  master
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 
53  static const arma::mat InitializeWeights(const size_t featureSize,
54  const size_t numClasses,
55  const bool fitIntercept = false);
56 
66  static void InitializeWeights(arma::mat &weights,
67  const size_t featureSize,
68  const size_t numClasses,
69  const bool fitIntercept = false);
70 
77  void GetGroundTruthMatrix(const arma::Row<size_t>& labels,
78  arma::sp_mat& groundTruth);
79 
89  void GetProbabilitiesMatrix(const arma::mat& parameters,
90  arma::mat& probabilities) const;
91 
101  double Evaluate(const arma::mat& parameters) const;
102 
112  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
113 
115  const arma::mat& GetInitialPoint() const { return initialPoint; }
116 
118  size_t NumClasses() const { return numClasses; }
119 
121  size_t FeatureSize() const
122  {
123  return fitIntercept ? initialPoint.n_cols - 1 :
124  initialPoint.n_cols;
125  }
126 
128  double& Lambda() { return lambda; }
130  double Lambda() const { return lambda; }
131 
133  bool FitIntercept() const { return fitIntercept; }
134 
135  private:
137  const arma::mat& data;
139  arma::sp_mat groundTruth;
141  arma::mat initialPoint;
143  size_t numClasses;
145  double lambda;
148 };
149 
150 } // namespace regression
151 } // namespace mlpack
152 
153 #endif
double & Lambda()
Sets the regularization parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
void GetProbabilitiesMatrix(const arma::mat &parameters, arma::mat &probabilities) const
Evaluate the probabilities matrix with the passed parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Evaluate(const arma::mat &parameters) const
Evaluates the objective function of the softmax regression model using the given parameters.
size_t NumClasses() const
Gets the number of classes.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
const arma::mat InitializeWeights()
Initializes the parameters of the model to suitable values.
size_t FeatureSize() const
Gets the features size of the training data.
arma::sp_mat groundTruth
Label matrix for the provided data.
bool FitIntercept() const
Gets the intercept flag.
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 GetGroundTruthMatrix(const arma::Row< size_t > &labels, arma::sp_mat &groundTruth)
Constructs the ground truth label matrix with the passed labels.
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() const
Gets the regularization parameter.