mlpack
bayesian_linear_regression.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_METHODS_BAYESIAN_LINEAR_REGRESSION_HPP
16 #define MLPACK_METHODS_BAYESIAN_LINEAR_REGRESSION_HPP
17 
18 #include <mlpack/prereqs.hpp>
19 
20 namespace mlpack {
21 namespace regression {
22 
100 {
101  public:
115  BayesianLinearRegression(const bool centerData = true,
116  const bool scaleData = false,
117  const size_t maxIterations = 50,
118  const double tolerance = 1e-4);
119 
129  double Train(const arma::mat& data,
130  const arma::rowvec& responses);
131 
140  void Predict(const arma::mat& points,
141  arma::rowvec& predictions) const;
142 
153  void Predict(const arma::mat& points,
154  arma::rowvec& predictions,
155  arma::rowvec& std) const;
156 
165  double RMSE(const arma::mat& data,
166  const arma::rowvec& responses) const;
167 
173  const arma::colvec& Omega() const { return omega; }
174 
181  double Alpha() const { return alpha; }
182 
189  double Beta() const { return beta; }
190 
196  double Variance() const { return 1.0 / Beta(); }
197 
203  const arma::colvec& DataOffset() const { return dataOffset; }
204 
211  const arma::colvec& DataScale() const { return dataScale; }
212 
218  double ResponsesOffset() const { return responsesOffset; }
219 
221  bool CenterData() const { return centerData; }
223  bool& CenterData() { return centerData; }
224 
227  bool ScaleData() const { return scaleData; }
230  bool& ScaleData() { return scaleData; }
231 
233  size_t MaxIterations() const { return maxIterations; }
235  size_t& MaxIterations() { return maxIterations; }
236 
238  double Tolerance() const { return tolerance; }
240  double& Tolerance() { return tolerance; }
241 
245  template<typename Archive>
246  void serialize(Archive& ar, const uint32_t version);
247 
248  private:
250  bool centerData;
251 
253  bool scaleData;
254 
256  size_t maxIterations;
257 
259  double tolerance;
260 
262  arma::colvec dataOffset;
263 
265  arma::colvec dataScale;
266 
268  double responsesOffset;
269 
271  double alpha;
272 
274  double beta;
275 
277  double gamma;
278 
280  arma::colvec omega;
281 
283  arma::mat matCovariance;
284 
295  double CenterScaleData(const arma::mat& data,
296  const arma::rowvec& responses,
297  arma::mat& dataProc,
298  arma::rowvec& responsesProc);
299 
306  void CenterScaleDataPred(const arma::mat& data,
307  arma::mat& dataProc) const;
308 };
309 } // namespace regression
310 } // namespace mlpack
311 
312 // Include implementation of serialize.
314 
315 #endif
const arma::colvec & Omega() const
Get the solution vector.
Definition: bayesian_linear_regression.hpp:173
void Predict(const arma::mat &points, arma::rowvec &predictions) const
Predict for each data point in the given data matrix using the currently-trained Bayesian Ridge mode...
Definition: bayesian_linear_regression.cpp:93
double Train(const arma::mat &data, const arma::rowvec &responses)
Run BayesianLinearRegression.
Definition: bayesian_linear_regression.cpp:33
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
bool CenterData() const
Get whether the data will be centered during training.
Definition: bayesian_linear_regression.hpp:221
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::colvec & DataOffset() const
Get the mean vector computed on the features over the training points.
Definition: bayesian_linear_regression.hpp:203
Definition: pointer_wrapper.hpp:23
double Alpha() const
Get the precision (or inverse variance) of the gaussian prior.
Definition: bayesian_linear_regression.hpp:181
size_t MaxIterations() const
Get the maximum number of iterations for training.
Definition: bayesian_linear_regression.hpp:233
const arma::colvec & DataScale() const
Get the vector of standard deviations computed on the features over the training points.
Definition: bayesian_linear_regression.hpp:211
double RMSE(const arma::mat &data, const arma::rowvec &responses) const
Compute the Root Mean Square Error between the predictions returned by the model and the true respons...
Definition: bayesian_linear_regression.cpp:114
BayesianLinearRegression(const bool centerData=true, const bool scaleData=false, const size_t maxIterations=50, const double tolerance=1e-4)
Set the parameters of Bayesian Ridge regression object.
Definition: bayesian_linear_regression.cpp:19
void serialize(Archive &ar, const uint32_t version)
Serialize the BayesianLinearRegression model.
Definition: bayesian_linear_regression_impl.hpp:24
double Variance() const
Get the estimated variance.
Definition: bayesian_linear_regression.hpp:196
A Bayesian approach to the maximum likelihood estimation of the parameters of the linear regression ...
Definition: bayesian_linear_regression.hpp:99
size_t & MaxIterations()
Modify the maximum number of iterations for training.
Definition: bayesian_linear_regression.hpp:235
double Tolerance() const
Get the tolerance for training to converge.
Definition: bayesian_linear_regression.hpp:238
bool & ScaleData()
Modify whether the data will be scaled by standard deviations during training.
Definition: bayesian_linear_regression.hpp:230
double Beta() const
Get the precision (or inverse variance) beta of the model.
Definition: bayesian_linear_regression.hpp:189
bool & CenterData()
Modify whether the data will be centered during training.
Definition: bayesian_linear_regression.hpp:223
double ResponsesOffset() const
Get the mean value of the train responses.
Definition: bayesian_linear_regression.hpp:218
bool ScaleData() const
Get whether the data will be scaled by standard deviations during training.
Definition: bayesian_linear_regression.hpp:227
double & Tolerance()
Modify the tolerance for training to converge.
Definition: bayesian_linear_regression.hpp:240