bayesian_linear_regression.hpp
Go to the documentation of this file.
1 
10 #ifndef MLPACK_METHODS_BAYESIAN_LINEAR_REGRESSION_HPP
11 #define MLPACK_METHODS_BAYESIAN_LINEAR_REGRESSION_HPP
12 
13 #include <mlpack/prereqs.hpp>
14 
15 namespace mlpack {
16 namespace regression {
17 
94 {
95  public:
109  BayesianLinearRegression(const bool centerData = true,
110  const bool scaleData = false,
111  const size_t nIterMax = 50,
112  const double tol = 1e-4);
113 
122  double Train(const arma::mat& data,
123  const arma::rowvec& responses);
124 
133  void Predict(const arma::mat& points,
134  arma::rowvec& predictions) const;
135 
145  void Predict(const arma::mat& points,
146  arma::rowvec& predictions,
147  arma::rowvec& std) const;
148 
157  double RMSE(const arma::mat& data,
158  const arma::rowvec& responses) const;
159 
165  const arma::colvec& Omega() const { return omega; }
166 
173  double Alpha() const { return alpha; }
174 
181  double Beta() const { return beta; }
182 
188  double Variance() const { return 1.0 / Beta(); }
189 
195  const arma::colvec& DataOffset() const { return dataOffset; }
196 
203  const arma::colvec& DataScale() const { return dataScale; }
204 
210  double ResponsesOffset() const { return responsesOffset; }
211 
215  template<typename Archive>
216  void serialize(Archive& ar, const unsigned int /* version */);
217 
218  private:
220  bool centerData;
221 
223  bool scaleData;
224 
226  size_t nIterMax;
227 
229  double tol;
230 
232  arma::colvec dataOffset;
233 
235  arma::colvec dataScale;
236 
238  double responsesOffset;
239 
241  double alpha;
242 
244  double beta;
245 
247  double gamma;
248 
250  arma::colvec omega;
251 
253  arma::mat matCovariance;
254 
265  double CenterScaleData(const arma::mat& data,
266  const arma::rowvec& responses,
267  arma::mat& dataProc,
268  arma::rowvec& responsesProc);
269 
276  void CenterScaleDataPred(const arma::mat& data,
277  arma::mat& dataProc) const;
278 };
279 } // namespace regression
280 } // namespace mlpack
281 
282 // Include implementation of serialize.
283 #include "bayesian_linear_regression_impl.hpp"
284 
285 #endif
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.
BayesianLinearRegression(const bool centerData=true, const bool scaleData=false, const size_t nIterMax=50, const double tol=1e-4)
Set the parameters of Bayesian Ridge regression object.
double Variance() const
Get the estimated variance.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Definition: prereqs.hpp:67
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.
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.
A Bayesian approach to the maximum likelihood estimation of the parameters of the linear regression ...
void serialize(Archive &ar, const unsigned int)
Serialize the BayesianLinearRegression model.
double ResponsesOffset() const
Get the mean value of the train responses.
const arma::colvec & DataScale() const
Get the vector of standard deviations computed on the features over the training points.