mlpack  2.0.1
softmax_regression_function.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_FUNCTION_HPP
16 #define __MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_FUNCTION_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace regression {
22 
24 {
25  public:
37  SoftmaxRegressionFunction(const arma::mat& data,
38  const arma::Row<size_t>& labels,
39  const size_t numClasses,
40  const double lambda = 0.0001,
41  const bool fitIntercept = false);
42 
44  const arma::mat InitializeWeights();
45 
55  static const arma::mat InitializeWeights(const size_t featureSize,
56  const size_t numClasses,
57  const bool fitIntercept = false);
58 
68  static void InitializeWeights(arma::mat &weights,
69  const size_t featureSize,
70  const size_t numClasses,
71  const bool fitIntercept = false);
72 
79  void GetGroundTruthMatrix(const arma::Row<size_t>& labels,
80  arma::sp_mat& groundTruth);
81 
91  void GetProbabilitiesMatrix(const arma::mat& parameters,
92  arma::mat& probabilities) const;
93 
103  double Evaluate(const arma::mat& parameters) const;
104 
114  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
115 
117  const arma::mat& GetInitialPoint() const { return initialPoint; }
118 
120  size_t NumClasses() const { return numClasses; }
121 
123  size_t FeatureSize() const
124  {
125  return fitIntercept ? initialPoint.n_cols - 1 :
126  initialPoint.n_cols;
127  }
128 
130  double& Lambda() { return lambda; }
132  double Lambda() const { return lambda; }
133 
135  bool FitIntercept() const { return fitIntercept; }
136 
137  private:
139  const arma::mat& data;
141  arma::sp_mat groundTruth;
143  arma::mat initialPoint;
145  size_t numClasses;
147  double lambda;
150 };
151 
152 } // namespace regression
153 } // namespace mlpack
154 
155 #endif
double & Lambda()
Sets the regularization parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
void GetProbabilitiesMatrix(const arma::mat &parameters, arma::mat &probabilities) const
Evaluate the probabilities matrix with the passed parameters.
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.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
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.