2.1. bayesianLinearRegression package

2.1.1. Submodules

2.1.2. bayesianLinearRegression.bayesianLinearRegression module

bayesianLinearRegression.bayesianLinearRegression.batchWithSimplePrior(Phi, y, alpha, beta)[source]

Performs batch linear regression with the simple prior \(P(w)=\mathcal{N}(0,\alpha^{-1}I)\). It uses equations 3.53 and 3.54 from Bishop, 2006.

Parameters:
  • Phi (numpy array) – matrix of basis functions transformations of indendent variables. \(\text{Phi}\in\mathbb{R}^{NxP}\), where \(N\) is the number of observations and \(P\) the number of basis functions. \(\text{Phi}[n,j]=\phi_j(\mathbf{x}_n)\).

  • y (numpy array) – dependent variable. \(y\in\mathbb{R}^N\)

  • alpha (double) – prior precision

  • beta (double) – likelihood precision

Returns:

mean and covariance of the estimated coefficients

Return type:

mean: numpy array of size P; covariance: numpy array of size PxP

bayesianLinearRegression.bayesianLinearRegression.computeLogEvidence(Phi, y, mN, SN, alpha, beta)[source]

Calculcates the marginal log likelihood of a Bayesian linear regression model.

Parameters:
  • Phi (numpy array) – matrix of basis functions transformations of indendent variables. \(\text{Phi}\in\mathbb{R}^{NxP}\), where \(N\) is the number of observations and \(P\) the number of basis functions. \(\text{Phi}[n,j]=\phi_j(\mathbf{x}_n)\).

  • y (numpy array) – dependent variable. \(y\in\mathbb{R}^N\)

  • mN (numpy array) – current posterior mean. \(mn\in\mathbb{R}^P\)

  • SN (numpy array) – current posterior covariance. \(Sn\in\mathbb{R}^{P\times P}\)

  • alpha (double) – prior precision

  • beta (double) – likelihood precision

Returns:

marginal log likelihood

Return type:

double

bayesianLinearRegression.bayesianLinearRegression.onlineUpdate(mn, Sn, phi, y, alpha, beta)[source]

Updates the posterior mean, \(mn\), and posterior covariance, \(Sn\), with the new sample, \(phi\) (basis functions expansion of the independent variables) and \(y\) (dependent variable).

Parameters:
  • mn (numpy array) – current posterior mean. \(mn\in\mathbb{R}^P\)

  • Sn (numpy array) – current posterior covariance. \(Sn\in\mathbb{R}^{P\times P}\)

  • phi (numpy array) – bais function expansion of independent variables. \(phi\in\mathbb{R}^P\)

  • y (double) – dependent variable. \(y\in\mathbb{R}\)

  • alpha (double) – prior precision

  • beta (double) – likelihood precision

Returns:

updated mean and covariance

Return type:

mean: numpy array of size P; covariance: numpy array of size PxP

bayesianLinearRegression.bayesianLinearRegression.predict(phi, mn, Sn, beta)[source]

Predicts the mean and variance of the dependent variable for a given new set of indepedent variables with basis function expansion in phi. It uses equations 3.58 and 3.59 of Bishop, 2006.

Parameters:
  • phi (numpy array) – bais function expansion of independent variables. \(phi\in\mathbb{R}^P\)

  • mn (numpy array) – current posterior mean. \(mn\in\mathbb{R}^P\)

  • Sn (numpy array) – current posterior covariance. \(Sn\in\mathbb{R}^{P\times P}\)

  • beta (double) – likelihood precision

Returns:

mean and variance of prediction

Return type:

mean: double; variance: double

2.1.3. Module contents