The Gaussian regression observation model explains a observed collection of input/ouptut data pairs \(\{x_n, y_n\}_{n=1}^N\). Each input observation \(x_n\) is a vector of length D, while each output observation \(y_n\) is a scalar.
In this document, we assume that the observed input data \(x\) are fixed and focus on a generative model for the output data \(y\) which depends on \(x\). Various generative models, such as the diagonal-covariance Gaussian, are possible for the observed data \(x\). These can be straight-forwardly combined with the model here to produce a joint model for both \(x\) and \(y\).
Each cluster k produces the output values according to the following standard Bayesian linear regression model:
Here, the cluster-specific parameters are a weight vector \(w_k\), an intercept weight \(b_k\), and a precision scalar \(\delta_k\). These are the global random variables of this observation model.
Alternatively, if we define an expanded input data vector \(\tilde{x}_n = [x_{n1} x_{n2} \ldots x_{nD} ~ 1]\), we can write the generative model more simply as:
The global random variables are the cluster-specific weights and precisions. For each cluster k, we have
For convenience, let \(E\) denote the size of this expanded representation, where \(E = D+1\).
Each dataset observation at index n has its own cluster assignment:
The generative model and approximate posterior for \(z_n\) is determined by an allocation model. For all computations needed by our current observation model, we’ll assume either a point estimate or an approximate posterior for \(z_n\) is known.
We assume that the weights \(w_k\) and the precision \(\delta_k\) have a joint Normal-Wishart prior with hyperparameters:
count parameter of the Wishart prior on precision
location parameter of the Wishart prior on precision
mean value of the Normal prior on cluster weights
precision matrix for the Normal prior on cluster weights
Mathematically, we have:
Under this prior, here are some useful expectations for the precision random variable:
Likewise, here are some useful prior expectations for the weight vector random variable:
And some useful joint expectations:
In our Python implementation of the GaussRegressYFromFixedXObsModel
class, these quantities are represented by the following numpy array attributes of the Prior
parameter bag:
pnu
floatvalue of \(\bar{\nu}\)
ptau
floatvalue of \(\bar{\tau}\)
w_E
1D array, size Evalue of \(\bar{w}\)
P_EE
2D array, size E x Evalue of \(\bar{P}\)
Several keyword arguments can be used to determine the values of the prior hyperparameters when calling bnpy.run
--pnu
floatSets value of \(\bar{\nu}\). Defaults to 1.
--ptau
floatSets value of \(\bar{\tau}\). Defaults to 1.
--w_E
float or 1D arraySets value of the vector \(\bar{w}\). If float is provided, the whole vector is filled with that value. Defaults to 0.
--P_diag_val
float or 1D arraySets \(\bar{P}\) to diagonal matrix with specified values. Defaults to 1e-6.
We assume the following factorized approximate posterior family for variational optimization:
The specific forms of the global and local factors are given below.
For each observation vector at index n, we assume an independent approximate posterior over the assigned cluster indicator \(z_n \in \{1, 2, \ldots K \}\).
Thus, for this observation model the only local variational parameter is the assignment responsibility array \(\hat{r} = \{ \{ \hat{r}_{nk} \}_{k=1}^K \}_{n=1}^N\).
Inside the LP dict, this is represented by the resp numpy array:
resp
2D array, size N x KParameters of approximate posterior q(z) over cluster assignments. resp[n,k] = probability observation n is assigned to component k.
Remember, all computations required by our observation model assume that the resp
array is given. The actual values of resp
are updated by an allocation model.
The goal of variational optimization is to find the best approximate posterior distribution for the mean and precision parameters of each cluster k:
Within our Python implementation in the class GaussRegressYFromFixedXObsModel
, this approximate posterior is represented within the Post attribute. This attribute is a ParamBag object containing the following numpy arrays:
K
intnumber of active clusters
pnu_K
1D array, size KDefines \(\hat{\nu}_k\) for each cluster
ptau_K
1D array, size KDefines \(\hat{\tau}_{k}\) for each cluster
w_KE
2D array, size K x EDefines \(\hat{w}_{ke}\) for each cluster and expanded dimension
P_KEE
2D array, size K x E x EDefines precision matrix \(\hat{P}_{k}\) for each cluster
Variational optimization will find the approximate posterior parameters that maximize the following objective function, given a fixed observed dataset \(x = \{x_1, \ldots x_N \}\) and fixed prior hyparparameters \(\bar{\nu}, \bar{\tau}, \bar{w}, \bar{P}\).
This objective function is computed by calling the Python function calc_evidence
.
We can directly interpret this function as a lower bound on the marginal evidence:
The sufficient statistics of this observation model are functions of the local parameters \(\hat{r}\), the observed input data \(x\), and the observed output data \(y\).
These fields are stored within the sufficient statistics parameter bag SS
as the following fields:
SS.N
1D array, size KSS.N[k] = \(N_k\)
SS.yy_K
1D array, size KSS.yy[k] = \(S^{y^2}_{k}(y, \hat{r})\)
SS.yx
2D array, size K x ESS.yx[k] = \(S^{yx}_{k}(x, y, \hat{r})\)
SS.xxT
3D array, size K x E x ESS.xxT[k] = \(S^{xx^T}_{k}(x, \hat{r})\)
The cumulant function of the Normal-Wishart produces a scalar output from 4 input arguments:
where \(\Gamma(\cdot)\) is the gamma function, and \(\log |P|\) is the log determinant of the E x E matrix \(P\).
As with all observation models, the local step computes the expected log conditional probability of assigning each observation to each cluster:
where the elementary expectations required are:
The above operations can be efficiently computed via smart vectorized calculations on modern cpus.
In our implementation, this is done via the function calc_local_params
, which computes the following arrays and places them inside the local parameter dict LP
.
E_log_soft_ev
2D array, N x Klog probability of assigning each observation n to each cluster k
The global step update produces an updated approximate posterior over the global random variables. Concretely, this means updated values for each of the four parameters which define each cluster-specific Normal-Wishart:
Our implementation performs this update when calling the function update_global_params
.
Initialization creates valid values of the parameters which define the approximate posterior over the global random variables. Concretely, this means it creates a valid setting of the Post
attribute of the GaussRegressYFromFixedXObsModel
object.
TODO