mlpack  3.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
99 {
100  public:
114  BayesianLinearRegression(const bool centerData = true,
115  const bool scaleData = false,
116  const size_t nIterMax = 50,
117  const double tol = 1e-4);
118 
127  double Train(const arma::mat& data,
128  const arma::rowvec& responses);
129 
138  void Predict(const arma::mat& points,
139  arma::rowvec& predictions) const;
140 
150  void Predict(const arma::mat& points,
151  arma::rowvec& predictions,
152  arma::rowvec& std) const;
153 
162  double RMSE(const arma::mat& data,
163  const arma::rowvec& responses) const;
164 
170  const arma::colvec& Omega() const { return omega; }
171 
178  double Alpha() const { return alpha; }
179 
186  double Beta() const { return beta; }
187 
193  double Variance() const { return 1.0 / Beta(); }
194 
200  const arma::colvec& DataOffset() const { return dataOffset; }
201 
208  const arma::colvec& DataScale() const { return dataScale; }
209 
215  double ResponsesOffset() const { return responsesOffset; }
216 
220  template<typename Archive>
221  void serialize(Archive& ar, const unsigned int /* version */);
222 
223  private:
225  bool centerData;
226 
228  bool scaleData;
229 
231  size_t nIterMax;
232 
234  double tol;
235 
237  arma::colvec dataOffset;
238 
240  arma::colvec dataScale;
241 
243  double responsesOffset;
244 
246  double alpha;
247 
249  double beta;
250 
252  double gamma;
253 
255  arma::colvec omega;
256 
258  arma::mat matCovariance;
259 
270  double CenterScaleData(const arma::mat& data,
271  const arma::rowvec& responses,
272  arma::mat& dataProc,
273  arma::rowvec& responsesProc);
274 
281  void CenterScaleDataPred(const arma::mat& data,
282  arma::mat& dataProc) const;
283 };
284 } // namespace regression
285 } // namespace mlpack
286 
287 // Include implementation of serialize.
288 #include "bayesian_linear_regression_impl.hpp"
289 
290 #endif
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 ResponsesOffset() const
Get the mean value of the train responses.
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...
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...
const arma::colvec & Omega() const
Get the solution vector.
double Variance() const
Get the estimated variance.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Beta() const
Get the precision (or inverse variance) beta of the model.
double Alpha() const
Get the precision (or inverse variance) of the gaussian prior.
const arma::colvec & DataOffset() const
Get the mean vector computed on the features over the training points.
double Train(const arma::mat &data, const arma::rowvec &responses)
Run BayesianLinearRegression.
const arma::colvec & DataScale() const
Get the vector of standard deviations computed on the features over the training points.
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.