mlpack  3.4.2
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
mlpack::regression::BayesianLinearRegression::Beta
double Beta() const
Get the precision (or inverse variance) beta of the model.
Definition: bayesian_linear_regression.hpp:186
mlpack::regression::BayesianLinearRegression::BayesianLinearRegression
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.
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::regression::BayesianLinearRegression::Variance
double Variance() const
Get the estimated variance.
Definition: bayesian_linear_regression.hpp:193
mlpack::regression::BayesianLinearRegression::DataScale
const arma::colvec & DataScale() const
Get the vector of standard deviations computed on the features over the training points.
Definition: bayesian_linear_regression.hpp:208
mlpack::regression::BayesianLinearRegression
A Bayesian approach to the maximum likelihood estimation of the parameters of the linear regression ...
Definition: bayesian_linear_regression.hpp:99
mlpack::regression::BayesianLinearRegression::RMSE
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...
mlpack::regression::BayesianLinearRegression::DataOffset
const arma::colvec & DataOffset() const
Get the mean vector computed on the features over the training points.
Definition: bayesian_linear_regression.hpp:200
mlpack::regression::BayesianLinearRegression::Alpha
double Alpha() const
Get the precision (or inverse variance) of the gaussian prior.
Definition: bayesian_linear_regression.hpp:178
mlpack::regression::BayesianLinearRegression::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the BayesianLinearRegression model.
std
Definition: prereqs.hpp:67
mlpack::regression::BayesianLinearRegression::Predict
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...
mlpack::regression::BayesianLinearRegression::Train
double Train(const arma::mat &data, const arma::rowvec &responses)
Run BayesianLinearRegression.
mlpack::regression::BayesianLinearRegression::Omega
const arma::colvec & Omega() const
Get the solution vector.
Definition: bayesian_linear_regression.hpp:170
mlpack::regression::BayesianLinearRegression::ResponsesOffset
double ResponsesOffset() const
Get the mean value of the train responses.
Definition: bayesian_linear_regression.hpp:215
mlpack::regression::BayesianLinearRegression::Predict
void Predict(const arma::mat &points, arma::rowvec &predictions, arma::rowvec &std) const
Predict and the standard deviation of the predictive posterior distribution for each data point in t...