natural_posterior_network¶
- probly.transformation.natural_posterior_network.natural_posterior_network(encoder: Predictor[In, Out], latent_dim: int, num_classes: int, num_flows: int = 8, certainty_budget: CertaintyBudget = 'normal', alpha_prior: float = 1.0) NaturalPosteriorNetworkPredictor[In, Out][source]¶
Create a Natural Posterior Network predictor based on [CBZugner+22].
Computes a Bayesian posterior update over a Dirichlet distribution per sample. The encoder is projected to a low-dim latent
z; a single shared normalizing flow yieldslog p(z); a small linear classifier on the latent yields class log-probabilitieslog chi(x). The Dirichlet parameters are returned asalpha = alpha_prior + n(x) * chi(x), wheren(x)is the budget-scaled, clamped exponential oflog p(z).- Parameters:
encoder – The base encoder predictor mapping inputs to a latent embedding of shape
(B, encoder_dim).latent_dim – Dimension
Hof the latent space produced by the encoder.num_classes – Number of output classes
K.num_flows – Number of radial flow layers in the shared normalizing flow.
certainty_budget – Named scheme for scaling
log p(z)before exponentiation. One of"constant","exp-half","exp", or"normal". Defaults to"normal".alpha_prior – Per-class Dirichlet prior concentration, uniform across classes. Defaults to
1.0.
- Returns:
A
NaturalPosteriorNetworkPredictorwrapping the encoder with a normalizing-flow density head and a Dirichlet evidence layer.