12 #ifndef MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_HPP 13 #define MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_HPP 16 #include <ensmallen.hpp> 21 namespace regression {
72 const size_t numClasses = 0,
73 const bool fitIntercept =
false);
88 template<
typename OptimizerType = ens::L_BFGS>
90 const arma::Row<size_t>& labels,
91 const size_t numClasses,
92 const double lambda = 0.0001,
93 const bool fitIntercept =
false,
94 OptimizerType optimizer = OptimizerType());
112 template<
typename OptimizerType,
typename... CallbackTypes>
114 const arma::Row<size_t>& labels,
115 const size_t numClasses,
117 const bool fitIntercept,
118 OptimizerType optimizer,
119 CallbackTypes&&... callbacks);
128 void Classify(
const arma::mat& dataset, arma::Row<size_t>& labels)
const;
136 template<
typename VecType>
137 size_t Classify(
const VecType& point)
const;
150 void Classify(
const arma::mat& dataset,
151 arma::Row<size_t>& labels,
152 arma::mat& probabilities)
const;
160 void Classify(
const arma::mat& dataset,
161 arma::mat& probabilities)
const;
172 const arma::Row<size_t>& labels)
const;
183 template<
typename OptimizerType = ens::L_BFGS>
184 double Train(
const arma::mat& data,
185 const arma::Row<size_t>& labels,
186 const size_t numClasses,
187 OptimizerType optimizer = OptimizerType());
201 template<
typename OptimizerType = ens::L_BFGS,
typename... CallbackTypes>
202 double Train(
const arma::mat& data,
203 const arma::Row<size_t>& labels,
204 const size_t numClasses,
205 OptimizerType optimizer,
206 CallbackTypes&&... callbacks);
228 {
return fitIntercept ? parameters.n_cols - 1:
234 template<
typename Archive>
237 ar(CEREAL_NVP(parameters));
238 ar(CEREAL_NVP(numClasses));
239 ar(CEREAL_NVP(lambda));
240 ar(CEREAL_NVP(fitIntercept));
245 arma::mat parameters;
258 #include "softmax_regression_impl.hpp" SoftmaxRegression(const size_t inputSize=0, const size_t numClasses=0, const bool fitIntercept=false)
Initialize the SoftmaxRegression without performing training.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Lambda() const
Gets the regularization parameter.
bool FitIntercept() const
Gets the intercept term flag. We can't change this after training.
size_t NumClasses() const
Gets the number of classes.
double Train(const arma::mat &data, const arma::Row< size_t > &labels, const size_t numClasses, OptimizerType optimizer=OptimizerType())
Train the softmax regression with the given training data.
Softmax Regression is a classifier which can be used for classification when the data available can t...
arma::mat & Parameters()
Get the model parameters.
double ComputeAccuracy(const arma::mat &testData, const arma::Row< size_t > &labels) const
Computes accuracy of the learned model given the feature data and the labels associated with each dat...
double & Lambda()
Sets the regularization parameter.
size_t FeatureSize() const
Gets the features size of the training data.
size_t & NumClasses()
Sets the number of classes.
void Classify(const arma::mat &dataset, arma::Row< size_t > &labels) const
Classify the given points, returning the predicted labels for each point.
const arma::mat & Parameters() const
Get the model parameters.
void serialize(Archive &ar, const uint32_t)
Serialize the SoftmaxRegression model.