class: middle, center, title-slide
Lecture 4: Latent variable models
Prof. Gilles Louppe
g.louppe@uliege.be
???
XXX: Give a few more examples of latent variable models (from scientific domains, engineering, social sciences, etc.)
class: middle
In Lecture 2, our exploratory data analysis revealed that penguins are clustered by species, with distinctive physical traits.
.question[What if we had not been given the species labels? What underlying factors might explain the observed variations in physical traits?]
class: middle
class: middle
Data are recorded observations about the world. Mathematically, we can think of data as resulting from a function
-
$\Omega$ is the sample space (the set of all possible entities, accounting for all sources of variability), -
$\mathcal{X}$ is the measurement space.
Entities
class: middle
If the sample space
We call
class: middle
A .bold[parametric probabilistic model] encodes assumptions about how data are generated. It is specified by a parametric family
class: middle
.alert[$p(x \mid \theta)$ is not the data distribution
class: middle
Example: Body masses of penguins could be modeled as
This would assume
- body masses cluster around a central value
$\mu$ , - variability is symmetric and controlled by
$\sigma^2$ , - extreme values are rare (body masses are normally distributed).
class: middle
class: middle
In the Frequentist framework,
Fitting the model to data consists in finding a point estimate
class: middle
In the Bayesian framework,
A .bold[Bayesian model] therefore specifies a joint distribution over data and parameters,
-
$p(x \mid \theta)$ is the likelihood, -
$p(\theta)$ is the prior over parameters.
class: middle
Fitting a Bayesian model to observed data
Depending on the structure of the model, this computation may be easy, difficult, or even intractable.
class: middle
Often, the forward model
The consequences of prior choices in the context of the generative model can be assessed through .bold[prior predictive checks], which involve simulating data from the model using only the prior distributions, without conditioning on any observed data.
class: middle
The prior predictive distribution is given by
This distribution defines the data that we expect to observe under the model assumptions encoded in the prior. It should be examined to ensure that it aligns with domain knowledge and expectations about the data.
class: middle
class: middle
class: middle
A .bold[latent variable model] is a probabilistic model that assumes unobserved (latent) variables
It specifies a joint distribution over observed variables, latent variables, and parameters,
class: middle
More generally, for a dataset of
The factorization assumes that each observation
class: middle
Latent variable models can be represented using graphical models, where nodes represent variables (observed, latent, or parameters) and edges represent (possible) dependencies between them.
The graphical model illustrates the structure of the factorization of the joint distribution and the flow of the generative process.
class: middle
Shaded nodes represent observed variables, unshaded nodes represent latent variables or parameters.
class: middle
.center[Plate notation can be used to compactly represent
repeated structures in the graphical model.]
???
Here, the plate around
class: middle
Conditional distributions in a latent variable model may depend on additional parameters called .bold[hyperparameters], denoted
For instance, the prior distribution of parameters may depend on hyperparameters,
.footnote[1: Estimating hyperparameters from data is possible and will be discussed later in the course.]
class: middle
.center[Small squares denote fixed hyperparameters.]
class: middle
Fitting a latent variable model to observed data
The posterior distribution is used to examine the particular hidden structure that is manifested in the observed data. It can also be used to make predictions about new, unseen data, through the posterior predictive distribution,
class: middle
In probabilistic PCA, each observation
class: middle
The joint distribution
-
$p(z) = \mathcal{N}(z | 0, I)$ assumes latent variables are standard Gaussian, -
$p(x | z, B, \mu, \sigma^2) = \mathcal{N}(x | Bz + \mu, \sigma^2 I)$ assumes a linear Gaussian observation model, with$B \in \mathbb{R}^{d \times m}$ the loading matrix,$\mu \in \mathbb{R}^d$ the mean vector, and$\sigma^2$ the noise variance.
Therefore, using Gaussian identities, the joint distribution is Gaussian and can be written as $$p(z, x | B, \mu, \sigma^2) = \mathcal{N}\left(\begin{bmatrix} z \\ x \end{bmatrix} | \begin{bmatrix} 0 \\ \mu \end{bmatrix}, \begin{bmatrix} I & B^T \\ B & BB^T + \sigma^2 I \end{bmatrix}\right).$$
class: middle
The posterior distribution
-
$m = B^T (BB^T + \sigma^2 I)^{-1} (x - \mu)$ is the posterior mean, -
$C = I - B^T (BB^T + \sigma^2 I)^{-1} B$ is the posterior covariance.
class: middle
When
-
$m = B^T (BB^T + \sigma^2 I)^{-1} (x - \mu) \to B^T (B B^T)^{-1} (x - \mu)$ . If the columns of$B$ are orthonormal, then$B^T (B B^T)^{-1} = B^T$ , so$m \to B^T (x - \mu)$ , which corresponds to the PCA projection of$x$ onto the subspace spanned by the columns of$B$ . -
$C = I - B^T (BB^T + \sigma^2 I)^{-1} B \to I - B^T (B B^T)^{-1} B$ . If the columns of$B$ are orthonormal, then$B^T B = I$ , so$C \to 0$ , indicating that the posterior distribution collapses to a point mass at the PCA projection.
.alert[Probabilistic PCA recovers classical PCA in the limit of vanishing noise!]
class: middle
The hyperparameters
Since the joint distribution is Gaussian, the marginal likelihood is also Gaussian,
class: middle
Therefore, writing
The solution can be derived in closed form, yielding
-
$\hat{\mu} = \frac{1}{N} \sum_{i=1}^N x_i$ (the sample mean), -
$\hat{B} = U_m (\Lambda_m - \hat{\sigma}^2 I)^{1/2} R$ , where$U_m$ are the top$m$ eigenvectors of$S$ ,$\Lambda_m$ are the corresponding eigenvalues, and$R$ is an arbitrary rotation matrix, -
$\hat{\sigma}^2 = \frac{1}{d - m} \sum_{j=m+1}^d \lambda_j$ , where$\lambda_j$ are the eigenvalues of$S$ .
???
Intuitive explanation for the solution:
-
$\hat{\mu}$ is the sample mean because it minimizes the squared deviations from the mean. This appears in the log-likelihood as the term$(x_i - \mu)^T \Sigma^{-1} (x_i - \mu)$ . -
$\hat{B}$ is related to the top$m$ eigenvectors of$S$ because these directions capture the most variance in the data. The term$\text{tr}(\Sigma^{-1} S)$ in the log-likelihood encourages$\Sigma$ to align with the directions of high variance in$S$ . -
$\hat{\sigma}^2$ is the average of the remaining eigenvalues because it represents the isotropic noise variance that accounts for the variance not captured by the top$m$ components. The term$\log |\Sigma|$ in the log-likelihood penalizes overly complex models, leading to a balance between fitting the data and maintaining a reasonable noise level.
class: middle
class: middle
Deriving PCA from a latent variable model provides a .bold[probabilistic interpretation of PCA projections as the most likely latent variables that could have generated the observed data].
It also enables direct extensions such as
- Independent Component Analysis (ICA), which assumes non-Gaussian latent variables,
- Factor Analysis, which assumes a more general noise covariance structure,
- Bayesian PCA, which places a prior distribution over the hyperparameters.
class: middle
Mixture models assume that data are generated from a mixture of several underlying distributions, each corresponding to a different cluster or component.
class: middle
For a Gaussian mixture model with
The joint distribution
-
$p(\theta | \alpha) = \text{Dirichlet}(\alpha)$ is the prior over mixture weights, -
$p(\mu_k | \sigma^2_\mu) = \mathcal{N}(0, \sigma^2_\mu I)$ is the prior over component means, -
$p(\sigma^2_k | \sigma^2_\sigma) = \text{Lognormal}(0, \sigma^2_\sigma)$ is the prior over component variances, -
$p(z_i | \theta) = \text{Categorical}(\theta)$ is the categorical distribution over components, -
$p(x_i | z_i, \mu_{z_i}, \sigma^2_{z_i}) = \mathcal{N}(\mu_{z_i}, \sigma^2_{z_i} I)$ is the Gaussian observation model.
class: middle
Computing the posterior distribution
The posterior is typically intractable, requiring approximate inference methods such as Expectation-Maximization (EM) or Variational Inference (VI).
???
Again, deriving clustering from a latent variable model provides a probabilistic interpretation of cluster assignments as the most likely latent variables that could have generated the observed data. Its provides a principled narrative with explicit assumptions rather than a mere algorithmic recipe.
class: middle
class: middle
Nested sets of latent variables can also be used to model more complex generative structures.
class: middle
For instance, in mixed membership models of text documents (.bold[latent dirichlet allocation]), each document is assumed to be generated from a mixture of topics, where each topic is characterized by a distribution over words.
???
- K is the number of topics,
- M is the number of documents,
- N is the number of words in a document,
-
$\theta_m$ are the topic proportions for document$m$ , -
$z_{m,n}$ is the topic assignment for word$n$ in document$m$ , -
$x_{m,n}$ is the observed word.
class: middle
Posterior inference in mixed membership models can be used to discover the underlying topics in a corpus of documents and to infer the topic proportions for each document.
???
Again, deriving topic modeling from a latent variable model provides a probabilistic interpretation of topics and document-topic proportions as the most likely latent variables that could have generated the observed data.
class: middle
.footnote[Credits: Blei, 2011.]
class: middle
.footnote[Credits: Blei, 2011.]
class: end-slide, center count: false
The end.
class: middle
If
class: middle
If the random variables








