vamp_prior
vamp_prior
¶
VampPrior: Variational Mixture of Posteriors Prior.
Implements the VampPrior from "VAE with a VampPrior" (Tomczak & Welling, 2018). The prior is a mixture of Gaussians where each component is defined by passing learnable pseudo-inputs through the posterior encoder.
This allows the prior to be more expressive than a standard Gaussian N(0,I) while maintaining the VAE framework.
VampPrior
¶
VampPrior(latent_dimension, num_components, action_space, prediction_horizon, device, min_logvar=None)
Bases: PriorLatentEncoder
Variational Mixture of Posteriors Prior.
The posterior encoder in this policy family is conditional,
q_phi(z | a, s). Therefore the VampPrior components are conditional
pseudo-action posteriors, q_phi(z | u_k, s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimension
|
int
|
Dimension of latent variable z |
required |
num_components
|
int
|
Number of mixture components K |
required |
action_space
|
ActionSpace
|
ActionSpace defining the action dimensions |
required |
prediction_horizon
|
int
|
Number of timesteps in action chunks |
required |
device
|
str
|
Device to place prior on |
required |
min_logvar
|
float | None
|
Optional minimum logvar clamp |
None
|
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
get_auxiliary_output_keys
¶
Return prediction keys produced by the mixture prior.
wire_posterior
¶
Wire shared state from the posterior encoder.
Extracts the encoder reference needed to compute mixture components from learnable pseudo-inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior
|
PosteriorLatentEncoder
|
Posterior encoder that maps inputs to (mu, logvar). |
required |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
__getstate__
¶
Return copy-safe state without the posterior encoder reference.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Module state with runtime wiring cleared. The owning |
dict[str, Any]
|
VariationalAlgorithm reconnects the copied prior to the copied |
dict[str, Any]
|
posterior after deepcopy or unpickling. |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
get_mixture_params
¶
Compute mixture component parameters by passing pseudo-inputs through encoder.
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
Tuple of conditional (means, logvars), each shaped (B, K, latent_dim). |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
build_training_target
¶
Use a differentiable posterior sample for the sample-based KL.
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
sample_prior
¶
Sample from the VampPrior mixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of samples to generate |
required |
observations
|
dict[str, Tensor] | None
|
Required conditioning features |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Sampled latents of shape (batch_size, latent_dim) |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
forward
¶
Compute prior log probability for training.
VampPrior is a mixture of Gaussians. Unlike single-Gaussian priors, we return log_prob directly since mu/logvar don't represent a mixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_latents
|
Tensor | None
|
Target latents from posterior (B, latent_dim) |
required |
observations
|
dict[str, Tensor]
|
Conditioning features |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary with LatentKey.PRIOR_LOG_PROB |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
log_prob
¶
Compute log probability of z under the VampPrior mixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Latent samples of shape (B, latent_dim) |
required |
observations
|
dict[str, Tensor] | None
|
Required conditioning features |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Log probability of shape (B,) - summed over latent dimensions |
Source code in src/versatil/models/decoding/latent/prior/vamp_prior.py
log_normal_diag
¶
Compute log probability of z under diagonal Gaussian N(mu, exp(logvar)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Samples, shape (..., latent_dim) |
required |
mu
|
Tensor
|
Mean, shape (..., latent_dim) |
required |
logvar
|
Tensor
|
Log variance, shape (..., latent_dim) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Log probability, shape (..., latent_dim) - per-dimension log probs |