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.
313 #include "bayesian_linear_regression_impl.hpp"
314 
315 #endif
double Tolerance() const
Get the tolerance for training to converge.
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...
const arma::colvec & Omega() const
Get the solution vector.
double Variance() const
Get the estimated variance.
Linear algebra utility functions, generally performed on matrices or vectors.
void serialize(Archive &ar, const uint32_t version)
Serialize the BayesianLinearRegression model.
bool & ScaleData()
Modify whether the data will be scaled by standard deviations during training.
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.
double Beta() const
Get the precision (or inverse variance) beta of the model.
size_t & MaxIterations()
Modify the maximum number of iterations for training.
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.
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...
double Train(const arma::mat &data, const arma::rowvec &responses)
Run BayesianLinearRegression.
double Alpha() const
Get the precision (or inverse variance) of the gaussian prior.
double & Tolerance()
Modify the tolerance for training to converge.
A Bayesian approach to the maximum likelihood estimation of the parameters of the linear regression ...
bool CenterData() const
Get whether the data will be centered during training.
bool ScaleData() const
Get whether the data will be scaled by standard deviations during training.
bool & CenterData()
Modify whether the data will be centered during training.
double ResponsesOffset() const
Get the mean value of the train responses.
size_t MaxIterations() const
Get the maximum number of iterations for training.
const arma::colvec & DataScale() const
Get the vector of standard deviations computed on the features over the training points.