Part 2 & 3 - Bayesian Linear Regression

Introduction

In this part, we will explore Bayesian linear regression, a probabilistic approach to linear regression that incorporates uncertainty in the model parameters. Firstly, we will recap supervised machine learning, inference, and the problem setting for linear regression.

Supervised Machine Learning

Definition 1 (Supervised Machine Learning)

Given a training set D={(xi,yi)}i=1N\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^{N}, where xi\mathbf{x}_i are free variables (features, covariates, domain points, explanatory variables, etc.) and yiy_i are the target variables, dependant on xi\mathbf{x}_i (dependent variables, labels, responses, etc.), the goal of supervised machine learning is to identify an algorithm to predict the label yy for a new (yet unseen) input x\mathbf{x}. In other words, learning a model from label data and predicting outputs of new data based on the learned model.w

However, this task is impossible if there is no information about the mechanism relating x\mathbf{x} and yy. Thus, we may assume that x\mathbf{x} and yy are related via a function y=f~(x)y = \tilde{f}(\mathbf{x}).

Thus, the goal is to find the best possible approximation of f~(x)\tilde{f}(\mathbf{x}), f(x)f(\mathbf{x}) (prediction model), and predict the outcome yy for x\mathbf{x} as y^=f(x)\hat{y} = f(\mathbf{x}).

Again, in more general temrs, we want to identify a predictive algorithm that minimizes the error in the prediction of a new label yy for an unobserved input x\mathbf{x} (generalization loss).

As we discussed last time, we have two main approaches, the frequentist and the Bayesian approach. We will rephrase the supervised machine learning problem as a Bayesian inference problem.

The Inference Problem

Definition 2 (The Inference Problem)

From learning, we know that we need to treat x\mathbf{x} and yy as random variables. Thus, our objective is predict yy given the (random) observation of x\mathbf{x} under the assumption that the joint distribution p(x,y)p(\mathbf{x}, y) is known.

We define the loss function (y,y^)\ell(y, \hat{y}) as the cost (loss or risk) incurred when the correct value is yy while the estimated value is y^\hat{y}. For example, the quadratic loss function is defined as,

(y,y^)(yy^)2.\ell(y, \hat{y}) \coloneqq (y - \hat{y})^2.

We say there is a optimal prediction y^(x)\hat{y}^{\star}(\mathbf{x}) that minimizes the generalization loss (or, generalization error),

Lp(y^)Ex,yp(x,y)[(y,y^(x))].L_p(\hat{y}) \coloneqq \mathbb{E}_{\mathsf{\mathbf{x}}, \mathsf{y} \sim p(\mathbf{x}, y)}[\ell(\mathsf{y}, \hat{y}(\mathsf{\mathbf{x}}))].

The solution is “simply”,

y^(x)=argminy^ Lp(y^)=argminy^ Ex,yp(x,y)[(y,y^(x))]=argminy^ Exp(x)[Eyp(yx)[(y,y^(x))]]=argminy^ Eyp(yx)[(y,y^(x))]\begin{align*} \hat{y}^{\star}(\mathbf{x}) & = \underset{\hat{y}}{\arg\min} \ L_p(\hat{y}) \newline & = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{x}, \mathsf{y} \sim p(\mathbf{x}, y)}[\ell(\mathsf{y}, \hat{y}(\mathsf{\mathbf{x}}))] \newline & = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{x} \sim p(\mathbf{x})} \left[ \mathbb{E}_{\mathsf{y} \sim p(y \mid \mathsf{\mathbf{x}})}[\ell(\mathsf{y}, \hat{y}(\mathsf{\mathbf{x}}))] \right] \newline & = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \sim p(y \mid \mathbf{x})}[\ell(\mathsf{y}, \hat{y}(\mathbf{x}))] \end{align*}

Thus, the optimal prediction is a function of p(yx)p(y \mid \mathbf{x}) and the loss function (y,y^)\ell(y, \hat{y}).

For the loss function, (y,y^)=(yy^)2\ell(y, \hat{y}) = (y - \hat{y})^2,

y^(x)=Eyx[yx]\hat{y}^{\star}(\mathbf{x}) = \mathbb{E}_{\mathsf{y} \sim \mathbf{x}}[\mathsf{y} \mid \mathbf{x}]

i.e., the optimal prediction is the conditional mean of yy given x\mathbf{x}.

However, in most scenarios, the joint distribution p(x,y)p(\mathbf{x}, y) is unknown.

Finally, let’s restate the supervised machine learning problem as an inference problem.

The goal is to obtain a predictor y^(x)\hat{y}(\mathbf{x}) that performs close to optimal predictor y^(x)\hat{y}^{\star}(\mathbf{x}) based only on the training set D\mathcal{D} (without knowledge of p(x,y)p(\mathbf{x}, y)). Where closeness is measured as,

Lp(y^)Lp(y^).L_p(\hat{y}) - L_p(\hat{y}^{\star}).

where Lp(y^)L_p(\hat{y}) is the generalization loss of the trained predictor y^(x)\hat{y}(\mathbf{x}) and Lp(y^)L_p(\hat{y}^{\star}) is the minimum generalization loss (optimal predictor).

Frequentist Approach

Intuition (Frequentist Approach)

Our training data points (xi,yi)D(\mathbf{x}_i, \mathsf{y}_i) \in \mathcal{D} are i.i.d random variables drawn from a true (but unknown) distribution p(x,y)p(\mathbf{x}, y),

(xi,yi)i.i.dp(x,y),i=1,,N.(\mathbf{x}_i, \mathsf{y}_i) \sim_{\text{i.i.d}} p(\mathbf{x}, y), \quad i = 1, \ldots, N.

Since p(x,y)p(\mathbf{x}, y) is unknown, we cannot find the optimal predictor via,

y^(x)=argminy^ Eyx[(y,y^)x].\hat{y}^{\star}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \mid \mathbf{x}}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].

The solution however, is to separate learning inference. If we can learn an approximation of p(yx)p(y \mid \mathbf{x}) based on D(pD(yx))\mathcal{D}(p_{\mathcal{D}}(y \mid \mathbf{x})), and use it in,

y^(x)=argminy^ Eyx[(y,y^)x].\hat{y}^{\star}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \mid \mathbf{x}}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].

we can obtain,

y^D(x)=argminy^ EypD(yx)[(y,y^)x].\hat{y}_{\mathcal{D}}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \sim p_{\mathcal{D}}(y \mid \mathbf{x})}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].

Further, we can perform direct inference via empirical risk minimization (ERM). If we directly learn an approximation of the optimal decision rule (y^D()\hat{y}_{\mathcal{D}}(\cdot)) by minimizing an empirical estimate of the generalization loss,

y^Dargminy^ LD(y^)=argminy^ 1Ni=1N(yi,y^(xi)).\hat{y}_{\mathcal{D}} \coloneqq \underset{\hat{y}}{\arg\min} \ L_{\mathcal{D}}(\hat{y}) = \underset{\hat{y}}{\arg\min} \ \frac{1}{N} \sum_{i=1}^{N} \ell(\mathsf{y}_i, \hat{y}(\mathbf{x}_i)).

But, how do we learn an approximation of pD(yx)p_{\mathcal{D}}(y \mid \mathbf{x}) of p(yx)p(\mathsf{y} \mid \mathbf{x}) based on D\mathcal{D}? If we can select a family of parametric probabilistic models (i.e., hypothesis classes), we can learn the model parameters to fit D\mathcal{D}.

Linear Regression: Problem Setting

Definition 3 (Linear Regression Problem Setting)

In linear regression, we are interested in values of a fucntion y(x):RdRy(\mathbf{x}): \mathbb{R}^d \to \mathbb{R}, where x=(x1,,xd)T\mathbf{x} = (x_1, \ldots, x_d)^T. We have some observations of this mapping, precisely D={(xi,yi)}i=1N\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^{N}.

Thus, the goal is to predict yy for a new input x\mathbf{x}, i.e., learn an accurate prediction function y^(x)\hat{y}(\mathbf{x}) (also called regression function) from D\mathcal{D}. Further, in linear regression, we assume that the relationship between x\mathbf{x} and yy is linear,

t(x)=w0+w1x1++wdxd=μ(x,w)\begin{align*} t(\mathbf{x}) & = w_0 + w_1 x_1 + \ldots + w_d x_d \newline & = \mu(\mathbf{x}, \mathbf{w}) \end{align*}

We can extend this to a setting where we allow linear combinations of fixed nonlinear functions of the input variables,

μ(x,w)=w0+j=1M1wjϕj(x)\mu(\mathbf{x}, \mathbf{w}) = w_0 + \sum_{j=1}^{M-1} w_j \phi_j(\mathbf{x})

where ϕj(x)\phi_j(\mathbf{x}) are basis functions, w0w_0 is called the bias (allows for any fixed offset). Further, conveniently, we define the dummy basis function ϕ0(x)1\phi_0(\mathbf{x}) \coloneqq 1 so that,

μ(x,w)=j=0M1wjϕj(x)=wTϕ(x)\mu(\mathbf{x}, \mathbf{w}) = \sum_{j=0}^{M-1} w_j \phi_j(\mathbf{x}) = \mathbf{w}^T \boldsymbol{\phi}(\mathbf{x})

where w=(w0,w1,,wM1)T\mathbf{w} = (w_0, w_1, \ldots, w_{M-1})^T and ϕ(x)=(ϕ0(x),ϕ1(x),,ϕM1(x))T\boldsymbol{\phi}(\mathbf{x}) = (\phi_0(\mathbf{x}), \phi_1(\mathbf{x}), \ldots, \phi_{M-1}(\mathbf{x}))^T.

Example 1 (Basis Functions)

Some common basis functions are,

  • Polynomial Linear Regression,
μ(x,w)=j=0Mwjxj=wTϕ(x),\mu(x, \mathbf{w}) = \sum_{j=0}^{M} w_j x^j = \mathbf{w}^T \boldsymbol{\phi}(x),

where w=(w0,w1,,wM1)T\mathbf{w} = (w_0, w_1, \ldots, w_{M-1})^T and ϕ(x)=(1,x,x2,,xM)T\boldsymbol{\phi}(x) = (1, x, x^2, \ldots, x^M)^T.

  • Gaussian Basis Functions,
ϕj(x)=exp((xαj)22s2).\phi_j(x) = \exp \left( -\frac{(x - \alpha_j)^2}{2 s^2} \right).
  • Sigmoidal Basis Functions,
ϕj(x)=σ(xαjs),\phi_j(x) = \sigma \left( \frac{x - \alpha_j}{s} \right),

where,

σ(a)=11+exp(a).\sigma(a) = \frac{1}{1 + \exp(-a)}.

Probabilistic Modeling

Intuition (Probabilistic Modeling)

We can (again) further extend our framework by expressing our uncertainty over the value of μ(x,w)\mu(\mathbf{x}, \mathbf{w}) as,

y(x,w)=wTϕ(x)+ϵ=μ(x,w)+ϵ,ϵN(0,β1).y(\mathbf{x}, \mathbf{w}) = \mathbf{w}^T \boldsymbol{\phi}(\mathbf{x}) + \epsilon = \mu(\mathbf{x}, \mathbf{w}) + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \beta^{-1}).

Thus, given x\mathbf{x}, yy can be modeled by a probabilistic model,

yx=xN(μ(x,w),β1),\mathsf{y} \mid \mathbf{x} = \mathbf{x} \sim \mathcal{N}(\mu(\mathbf{x}, \mathbf{w}), \beta^{-1}),

or, equivalently,

p(yx,w,β)=p(yx,θ)=N(yμ(x,w),β1),p(\mathsf{y} \mid \mathbf{x}, \mathbf{w}, \beta) = p(\mathsf{y} \mid \mathbf{x}, \boldsymbol{\theta}) = \mathcal{N}(\mathsf{y} \mid \mu(\mathbf{x}, \mathbf{w}), \beta^{-1}),

where θ=(w,β)\boldsymbol{\theta} = (\mathbf{w}, \beta).

Discriminative VS. Generative Probabilistic Models

In machine learning, there is a concept of discriminative and generative models 1 2.

Definition 4 (Discriminative Models)

In discriminative models, our posterior (predictive) distribution p(yx)p(y \mid \mathbf{x}) is assumed to belong to a hypothesis class parameterized by θ\boldsymbol{\theta}, i.e., p(yx,θ)p(y \mid \mathbf{x}, \boldsymbol{\theta}). We learn the parameters θ\boldsymbol{\theta} directly from the training data D\mathcal{D}.

Thus, once the model is learned, we can compute,

y^D(x)=argminy^ EypD(yx)[(y,y^)x].\hat{y}_{\mathcal{D}}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \sim p_{\mathcal{D}}(y \mid \mathbf{x})}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].
Example 2 (Linear Regression)

We first learn θ=(w,β)\boldsymbol{\theta} = (\mathbf{w}, \beta) based on D\mathcal{D}. Then, we can find the optimal prediction for a new input x\mathbf{x} as (under a quadratic loss function),

y^D(x)=Eyp(yx,θD)[yx]\hat{y}_{\mathcal{D}}(\mathbf{x}) = \mathbb{E}_{\mathsf{y} \sim p(y \mid \mathbf{x}, \boldsymbol{\theta}^{\star}_{\mathcal{D}})}[\mathsf{y} \mid \mathbf{x}]

i.e.,

y^D(x)=μ(x,wD)\hat{y}_{\mathcal{D}}(\mathbf{x}) = \mu(\mathbf{x}, \mathbf{w}^{\star}_{\mathcal{D}})
Definition 5 (Generative Models)

In generative models, we see the models p(x,y)p(\mathbf{x}, y) as being part of a parametric family p(x,yθ)p(\mathbf{x}, y \mid \boldsymbol{\theta}). This means we from these models, can find p(x)p(\mathbf{x}).

This is the generative ascpet of these models. We have the capacity to generate a realization of x\mathbf{x} by using the marginal p(xθ)p(\mathbf{x} \mid \boldsymbol{\theta}). Thus, once the model is learned, we can obtain p(yx,θ)p(y \mid \mathbf{x}, \boldsymbol{\theta}) via Bayes’ theorem and computing,

y^D(x)=argminy^ EypD(yx)[(y,y^)x].\hat{y}_{\mathcal{D}}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \sim p_{\mathcal{D}}(y \mid \mathbf{x})}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].
Note

By making stronger assumptions, it (might) lead to more (significant) biases. However, in this setting we also have the ability to deal with missing data or latent variables (semi-supervised learning).

Learning the Model Parameters

We have clearly defined our problem setting and the overall goal. However, we have not stated how we actually learn/estimate the model parameters. As we discussed in the last part, we have two main approaches, the frequentist and the Bayesian approach.

Maximum Likelihood Estimation

Intuition (Maximum Likelihood Estimation)

From what we have seen so far, we have stated that our models can be from a hypothesis class p(yx,θ)=N(μ(x,w),β1)p(y \mid \mathbf{x}, \boldsymbol{\theta}) = \mathcal{N}(\mu(\mathbf{x}, \mathbf{w}), \beta^{-1}). For example, this can define the polynomial degree MM (i.e., edfines the capacity of the class).

While a specific model p(yx,θ)p(y \mid \mathbf{x}, \boldsymbol{\theta}) is defined by the selection of the parameters θ=(w,β)\boldsymbol{\theta} = (\mathbf{w}, \beta) (learned from D\mathcal{D}).

As we discussed in the last part, one approach is Maximum Likelihood (ML) learning. Select θ\boldsymbol{\theta} such that D\mathcal{D} has maximum probability of being observed,

p(yDxD,w,β)=i=1Np(yixi,w,β)=i=1NN(yiμ(xi,w),β1)\begin{align*} p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) & = \prod_{i=1}^{N} p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) \newline & = \prod_{i=1}^{N} \mathcal{N}(y_i \mid \mu(\mathbf{x}_i, \mathbf{w}), \beta^{-1}) \end{align*}

We know that maximizing the likelihood is equivalent to maximizing the log-likelihood 1since log()\log(\cdot) is a monotonic function and does not change the location of the maximum,

logp(yDxD,w,β)=i=1Nlog p(yixi,w,β)=β2i=1N(yiμ(xi,w))2+N2logβ2π\begin{align*} \log p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) & = \sum_{i=1}^{N} \log \ p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) \newline & = -\frac{\beta}{2} \sum_{i=1}^{N} (y_i - \mu(\mathbf{x}_i, \mathbf{w}))^2 + \frac{N}{2} \log \frac{\beta}{2 \pi} \end{align*}

The ML criterion (cross-entropy or log-loss) is then,

(wML,βML)=argmaxw,β p(yDxD,w,β)=argmaxw,β 1Nlogp(yDxD,w,β)=argminw,β 1Nlogp(yDxD,w,β)=argminw,β β2Ni=1N(yiμ(xi,w))212logβ2π\begin{align*} (\mathbf{w}_{\text{ML}}, \beta_{\text{ML}}) & = \underset{\mathbf{w}, \beta}{\arg\max} \ p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) \newline & = \underset{\mathbf{w}, \beta}{\arg\max} \ \frac{1}{N} \log p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) \newline & = \underset{\mathbf{w}, \beta}{\arg\min} \ -\frac{1}{N} \log p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) \newline & = \underset{\mathbf{w}, \beta}{\arg\min} \ \frac{\beta}{2N} \sum_{i=1}^{N} (y_i - \mu(\mathbf{x}_i, \mathbf{w}))^2 - \frac{1}{2} \log \frac{\beta}{2 \pi} \end{align*}
Note

If we are only interested in learning the mean,

wML=argminw β2Ni=1N(yiμ(xi,w))2=argminw 1Ni=1N(yiμ(xi,w))2=argminw LD(w)\begin{align*} \mathbf{w}_{\text{ML}} & = \underset{\mathbf{w}}{\arg\min} \ \frac{\beta}{2N} \sum_{i=1}^{N} (y_i - \mu(\mathbf{x}_i, \mathbf{w}))^2 \newline & = \underset{\mathbf{w}}{\arg\min} \ \frac{1}{N} \sum_{i=1}^{N} (y_i - \mu(\mathbf{x}_i, \mathbf{w}))^2 \newline & = \underset{\mathbf{w}}{\arg\min} \ L_{\mathcal{D}}(\mathbf{w}) \end{align*}

Thus, the criterion coincides with the direct inference via the empirical risk minimization if we parametrize the predictor as y^(x)=μ(x,w)\hat{y}(\mathbf{x}) = \mu(\mathbf{x}, \mathbf{w}). Further, minimizing LD(w)L_{\mathcal{D}}(\mathbf{w}) can be solved in closed form wML=(ΦTΦ)1ΦTy\mathbf{w}_{\text{ML}} = (\boldsymbol{\Phi}^T \boldsymbol{\Phi})^{-1} \boldsymbol{\Phi}^T \mathbf{y}, where Φ=(ϕ(x1),,ϕ(xN))T\boldsymbol{\Phi} = (\phi(\mathbf{x}_1), \ldots, \phi(\mathbf{x}_N))^T.

ML Learning Example
ML Learning Example

Training, Generalization Loss, Bias, and Estimation Error

As the number of data points increases, overfitting is avoided. When D\mathcal{D} is big compared to the number of parameters in θ\boldsymbol{\theta},

LD(w)Lp(w).L_{\mathcal{D}}(\mathbf{w}) \simeq L_p(\mathbf{w}).

Thus, for large NN,

wMLw=argminw Lp(w).\mathbf{w}_{\text{ML}} \Rightarrow \mathbf{w}^{\star} = \underset{\mathbf{w}}{\arg\min} \ L_p(\mathbf{w}).
Definition 6 (Estimation Error and Bias)Lp(wML)=Lp(y^)+(Lp(w)Lp(y^))Bias+(Lp(wML)Lp(w))Estimation Error.L_p(\mathbf{w}_{\text{ML}}) = L_p(\hat{y}^{\star}) + \underbrace{(L_p(\mathbf{w}^{\star}) - L_p(\hat{y}^{\star}))}_{\text{Bias}} + \underbrace{(L_p(\mathbf{w}_{\text{ML}}) - L_p(\mathbf{w}^{\star}))}_{\text{Estimation Error}}.

where Lp(y^)L_p(\hat{y}^{\star}) is generalization loss of the optimal predictor (minimum loss achievable), Lp(w)L_p(\mathbf{w}^{\star}) is the generalization loss for optimal w\mathbf{w} for the given hypothesis class (e.g., fixing MM).

The bias (approximation error) is caused by our choice of the hypothesis class (model misspecification) and the estimation error (generalization gap) is caused byt the fact that NN is not large enough.

Learning and Validation

So, we would like to choose a model (hyperparameters and parameters) such that the generalization error Lp(y^)=Ex,yp(x,y)[(y,y^(x))]L_p(\hat{y}) = \mathbb{E}_{\mathbf{x}, \mathsf{y} \sim p(\mathbf{x}, y)}[\ell(\mathsf{y}, \hat{y}(\mathbf{x}))] is minimized. However, it depends on p(x,y)p(\mathbf{x}, y), which is unknown.

Intuition (Validation)

We can divide our available data into three sets.

  • Training set D\mathcal{D} to fit the model parameters.

  • Validation set V\mathcal{V} to choose hypothesis class via evaluation of approximation of the generalization error,

Lp(w)1NVi=1NV(yi,μ(xi,w)),L_p(\mathbf{w}) \approx \frac{1}{N_{\mathcal{V}}} \sum_{i=1}^{N_{\mathcal{V}}} \ell(\mathsf{y}_i, \mu(\mathbf{x}_i, \mathbf{w})),

for the selected hypothesis class, retrain w\mathbf{w} based on DV\mathcal{D} \cup \mathcal{V}.

  • Test set T\mathcal{T} to produce the estimate generalization error obtained with the final model.

However, there is a pitfall with this approach, parts of the available data are not used for training! Validation is suitable when we have plently of data. However, when data is scarce, we can use cross-validation (CV) techniques.

Algorithm (kk-Fold Cross-Validation)
  1. Randomly partition data points into kk partitions (folds)

  2. For each κ{1,,k}\kappa \in \{1, \ldots, k\}, train model over all other k1k -1 partitions.

  3. Compute generalization error on the κ\kappa-th partition,

  4. Generalization error estimated as average over all partitions.

  5. Choose hypothesis class that minimizes the estimate of the generalization error in Step 4.

Maximum A Posteriori Learning

Intuition (Maximum A Posteriori Learning)

In the Bayesian approach, we instead treat the parameters w\mathbf{w} as unknown random variables (instead of unknown but deterministic quantities). MAP enables a finer control of the bias and estimation error.

The key idea is to leverage prior information available on the behavior of parameters in the absence, or presence, of overfitting.

Note

A large value of w1\Vert \mathbf{w} \Vert_1 a manifestation of overfitting \Rightarrow introduce a prior on w\mathbf{w} that gives lower probability to larger values,

wN(0,α1I).\mathbf{w} \sim \mathcal{N}(0, \alpha^{-1} \mathbf{I}).

i.e., p(w)=N(w0,α1I)=(α2π)(M+1)/2exp(α2wTw)p(\mathbf{w}) = \mathcal{N}(\mathbf{w} \mid 0, \alpha^{-1} \mathbf{I}) = \left(\frac{\alpha}{2 \pi}\right)^{(M + 1) / 2} \exp \left(- \frac{\alpha}{2} \mathbf{w}^T \mathbf{w} \right)

How do we choose the prior distribution?

But, how do we choose the prior distribution? A common approach is to choose a conjugate prior (if present) to the likelihood function.

For example, exponential of a quadratic function of w\mathbf{w} \Rightarrow Conjugate given by a Gaussian distribution of the form,

p(w)=N(wm0,S0).p(\mathbf{w}) = \mathcal{N}(\mathbf{w} \mid \mathbf{m}_0, \mathbf{S}_0).

Maximum A Posteriori Learning: Continued

Definition 7 (MAP Criterion)(wMAP,β)=argmaxw,β p(yD,wxD,β)=argmaxw,β p(w)i=1Np(yixi,w,β)\begin{align*} (\mathbf{w}_{\text{MAP}}, \beta) & = \underset{\mathbf{w}, \beta}{\arg\max} \ p(y_{\mathcal{D}}, \mathbf{w} \mid x_{\mathcal{D}}, \beta) \newline & = \underset{\mathbf{w}, \beta}{\arg\max} \ p(\mathbf{w}) \prod_{i=1}^{N} p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) \newline \end{align*}

or, equivalently,

(wMAP,β)=argminw,βi=1Nlogp(yixi,w,β)logp(w).(\mathbf{w}_{\text{MAP}}, \beta) = \underset{\mathbf{w}, \beta}{\arg\min} -\sum_{i=1}^{N} \log p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) - \log p(\mathbf{w}).

If β\beta is a known constant,

wMAP=argminw i=1Nlogp(yixi,w,β)logp(w).\mathbf{w}_{\text{MAP}} = \underset{\mathbf{w}}{\arg\min} \ -\sum_{i=1}^{N} \log p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) - \log p(\mathbf{w}).
Note

MAP is equivalent to maximizing the posterior distribution of w\mathbf{w} given the available data.

Example 3 (MAP Learning with Gaussian Prior)

Assuming wN(0,α1I)\mathbf{w} \sim \mathcal{N}(0, \alpha^{-1} \mathbf{I}), i.e., p(w)=N(w0,α1I)=(α2π)(M+1)/2exp(α2wTw)p(\mathbf{w}) = \mathcal{N}(\mathbf{w} \mid 0, \alpha^{-1} \mathbf{I}) = \left(\frac{\alpha}{2 \pi}\right)^{(M + 1) / 2} \exp \left(- \frac{\alpha}{2} \mathbf{w}^T \mathbf{w} \right),

wMAP=argminw i=1Nlogp(yixi,w,β)logp(w)=argminw(β2i=1N(μ(xi,w)yi)2+N2logβ2π)logp(w)=argminw β2i=1N(μ(xi,w)yi)2logp(w)=argminw 1Ni=1N(μ(xi,w)yi)22Nβlogp(w)=argminw 1Ni=1N(μ(xi,w)yi)2+αβwTw=argminw LD(w)+λNw2wMAP=(λI+ΦTΦ)1ΦTyD\begin{align*} \mathbf{w}_{\text{MAP}} & = \underset{\mathbf{w}}{\arg\min} \ -\sum_{i=1}^{N} \log p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) - \log p(\mathbf{w}) \newline & = \underset{\mathbf{w}}{\arg\min} - \left( -\frac{\beta}{2} \sum_{i=1}^{N} \left(\mu(\mathbf{x}_i, \mathbf{w}) - y_i \right)^2 + \frac{N}{2} \log \frac{\beta}{2 \pi} \right) - \log p(\mathbf{w}) \newline & = \underset{\mathbf{w}}{\arg\min} \ \frac{\beta}{2} \sum_{i=1}^{N} \left(\mu(\mathbf{x}_i, \mathbf{w}) - y_i \right)^2 - \log p(\mathbf{w}) \newline & = \underset{\mathbf{w}}{\arg\min} \ \frac{1}{N} \sum_{i=1}^{N} \left(\mu(\mathbf{x}_i, \mathbf{w}) - y_i \right)^2 - \frac{2}{N \beta} \log p(\mathbf{w}) \newline & = \underset{\mathbf{w}}{\arg\min} \ \frac{1}{N} \sum_{i=1}^{N} \left(\mu(\mathbf{x}_i, \mathbf{w}) - y_i \right)^2 + \frac{\alpha}{\beta} \mathbf{w}^T \mathbf{w} \newline & = \underset{\mathbf{w}}{\arg\min} \ L_{\mathcal{D}}(\mathbf{w}) + \frac{\lambda}{N} \Vert \mathbf{w} \Vert^2 \Rightarrow \mathbf{w}_{\text{MAP}} = (\lambda \mathbf{I} + \boldsymbol{\Phi}^T \boldsymbol{\Phi})^{-1} \boldsymbol{\Phi}^T \mathbf{y}_{\mathcal{D}} \end{align*}
Note

Note that, as NN \to \infty, the influence of the prior diminishes, and MAP converges to ML. The MAP criterion (also called ridge regression [^3]), modifies the ML criterion by adding the quadratic (or Tikhonov) regularization function R(w)=w2R(\mathbf{w}) = \Vert \mathbf{w} \Vert^2.

Thus, consider p(wy^D,xD,β)p(\mathbf{w} \mid \hat{y}_{\mathcal{D}}, x_{\mathcal{D}}, \beta). Due to conjugate Gaussian prior distribution, the posterior also Gaussian,

p(wyD,xD,β)=N(wmN,SN),p(\mathbf{w} \mid y_{\mathcal{D}}, x_{\mathcal{D}}, \beta) = \mathcal{N}(\mathbf{w} \mid \mathbf{m}_N, \mathbf{S}_N),

where,

mN=SN(S01m0+βΦTyD)SN1=S01+βΦTΦ\begin{align*} \mathbf{m}_N & = \mathbf{S}_N (\mathbf{S}_0^{-1} \mathbf{m}_0 + \beta \boldsymbol{\Phi}^T \mathbf{y}_{\mathcal{D}}) \newline \mathbf{S}_N^{-1} & = \mathbf{S}_0^{-1} + \beta \boldsymbol{\Phi}^T \boldsymbol{\Phi} \newline \end{align*}

We assume wN(0,α1I)\mathbf{w} \sim \mathcal{N}(0, \alpha^{-1} \mathbf{I}),

mN=βSNΦTyDSN1=αI+βΦTΦ\begin{align*} \mathbf{m}_N & = \beta \mathbf{S}_N \boldsymbol{\Phi}^T \mathbf{y}_{\mathcal{D}} \newline \mathbf{S}_N^{-1} & = \alpha \mathbf{I} + \beta \boldsymbol{\Phi}^T \boldsymbol{\Phi} \newline \end{align*}
Intuition (Bayes’ Theorem for Prediction)

Applying Bayes’,

p(wyD,xD,β)=p(yDxD,w,β)p(w)p(yDxD,β)p(yDxD,w,β)p(w)=p(w)i=1Np(yixi,w,β)\begin{align*} p(\mathbf{w} \mid y_{\mathcal{D}}, x_{\mathcal{D}}, \beta) & = \frac{p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) p(\mathbf{w})}{p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \beta)} \newline & \propto p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta) p(\mathbf{w}) \newline & = p(\mathbf{w}) \prod_{i=1}^{N} p(y_i \mid \mathbf{x}_i, \mathbf{w}, \beta) \end{align*}
  • p(w)p(\mathbf{w}) is our knowledge about w\mathbf{w} before observing any data.

  • p(yDw)p(y_{\mathcal{D}} \mid \mathbf{w}) is how likely the observed data is for a particular parameter value.

  • p(wyD)p(\mathbf{w} \mid y_{\mathcal{D}}) knowledge about w\mathbf{w} from the observed data and the model.

MAP Learning Example
MAP Learning Example
Summary (Bayesian Linear Regression)

In this part, we have seen that the frequentist approach, aims at identifying a specific value for θ\boldsymbol{\theta} of a probabilistic model to derive a predictor,

y^(x)=argminy^ Eyx[(y,y^)x].\hat{y}^{\star}(\mathbf{x}) = \underset{\hat{y}}{\arg\min} \ \mathbb{E}_{\mathsf{y} \mid \mathbf{x}}[\ell(\mathsf{y}, \hat{y}) \mid \mathbf{x}].
  • ML: Chooses θ\boldsymbol{\theta} that maximizes probability of training data.

  • MAP: Includes also prior information about parameter vector. In contrast, the Bayesian approach assumes that θ\boldsymbol{\theta} is jointly distributed with data \Rightarrow Does not commit to a single value of θ\boldsymbol{\theta} but considers explanations provided by all possible values of θ\boldsymbol{\theta}, each weighted according to data-dependent belief.

Bayesian Linear Regression Model,

y(x,w)=wTϕ(x)+ϵ=μ(x,w)+ϵ,ϵN(0,β1)y(\mathbf{x}, \mathbf{w}) = \mathbf{w}^T \boldsymbol{\phi}(\mathbf{x}) + \epsilon = \mu(\mathbf{x}, \mathbf{w}) + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \beta^{-1}) \newline

where wp(w)\mathbf{w} \sim p(\mathbf{w})

Probabilistic Model,

p(yx,w,β)=i=1NN(yμ(x,w),β1)likelihoodp(w)=N(w0,S0)prior\begin{align*} p(\mathsf{y} \mid \mathbf{x}, \mathbf{w}, \beta) & = \prod_{i=1}^{N} \mathcal{N}(\mathsf{y} \mid \mu(\mathbf{x}, \mathbf{w}), \beta^{-1}) \quad \text{likelihood} \newline p(\mathbf{w}) & = \mathcal{N}(\mathbf{w} \mid \mathbf{0}, \mathbf{S}_0) \quad \text{prior} \newline \end{align*}

Thus, the end goal is making predictions of yy for new values of x\mathbf{x} \Rightarrow We can directly evalute the posterior distribution p(yyD,xD,x,β)p(y \mid y_{\mathcal{D}}, x_{\mathcal{D}}, \mathbf{x}, \beta). A fully Bayesian solution returns the entire posterior p(yD,x,β)p(y \mid \mathcal{D}, \mathbf{x}, \beta) \Rightarrow which provides more information about unobserved label yy.

Finally, one last note on predictive distribution. We obtain,

p(yD,x,β)=p(wD,β)posterior dist. of wp(yx,w,β) dw.p(y \mid \mathcal{D}, \mathbf{x}, \beta) = \int \underbrace{p(\mathbf{w} \mid \mathcal{D}, \beta)}_{\text{posterior dist. of } \mathbf{w}} p(y \mid \mathbf{x}, \mathbf{w}, \beta) \ d\mathbf{w}.

With the Bayesian approach, p(yx,w,β)p(y \mid \mathbf{x}, \mathbf{w}, \beta) is associated with each value of w\mathbf{w} weighted by the posterior belief,

p(wD,β)=p(w)p(yDxD,w,β)p(yDxD,β).p(\mathbf{w} \mid \mathcal{D}, \beta) = \frac{p(\mathbf{w}) p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \mathbf{w}, \beta)}{p(y_{\mathcal{D}} \mid x_{\mathcal{D}}, \beta)}.

Computing p(wD,β)p(\mathbf{w} \mid \mathcal{D}, \beta) and p(yD,x,β)p(y \mid \mathcal{D}, \mathbf{x}, \beta) is difficult.

For our Bayesian linear regression problem with wN(0,α1I)\mathbf{w} \sim \mathcal{N}(0, \alpha^{-1} \mathbf{I}),

p(yx,w,β)=N(yμ(x,w),β1)p(wD,β)=N(wmN,SN)\begin{align*} p(y \mid \mathbf{x}, \mathbf{w}, \beta) & = \mathcal{N}(y \mid \mu(\mathbf{x}, \mathbf{w}), \beta^{-1}) \newline p(\mathbf{w} \mid \mathcal{D}, \beta) & = \mathcal{N}(\mathbf{w} \mid \mathbf{m}_N, \mathbf{S}_N) \newline \end{align*}

where mN\mathbf{m}_N and SN\mathbf{S}_N are defined as before.

Thus, we can obtain,

p(yx,D,β)=N(yμ(x,wMAP),σN2(x)),p(y \mid \mathcal{x}, \mathcal{D}, \beta) = \mathcal{N}(y \mid \mu(\mathbf{x}, \mathbf{w}_{\text{MAP}}), \sigma^2_N(\mathbf{x})),

where,

μ(x,wMAP)=wMAPTϕ(x)=mNTϕ(x)σN2(x)=1β+1β(ϕ(x)T(αI+ΦTΦ)1ϕ(x))\begin{align*} \mu(\mathbf{x}, \mathbf{w}_{\text{MAP}}) & = \mathbf{w}_{\text{MAP}}^T \boldsymbol{\phi}(\mathbf{x}) = \mathbf{m}_N^T \boldsymbol{\phi}(\mathbf{x}) \newline \sigma^2_N(\mathbf{x}) & = \frac{1}{\beta} + \frac{1}{\beta} \left( \boldsymbol{\phi}(\mathbf{x})^T \left( \alpha \mathbf{I} + \boldsymbol{\Phi}^T \boldsymbol{\Phi} \right)^{-1} \boldsymbol{\phi}(\mathbf{x}) \right) \newline \end{align*}

Footnotes

  1. Wikipedia: Discriminative model

  2. Wikipedia: Generative model