mixle.stats.bayes.normal_gamma moduleΒΆ
Normal-Gamma distribution over (mu, tau) for a Gaussian with unknown mean and precision.
tau ~ Gamma(a, b), mu | tau ~ Gaussian(mu0, 1/(lam*tau))
- Data type: (Tuple[float, float]): A pair (mu, tau) with tau > 0; the log-density is
log(f(mu, tau)) = a*log(b) + 0.5*log(lam/(2*pi)) - gammaln(a) + (a - 0.5)*log(tau) - b*tau - 0.5*lam*tau*(mu - mu0)^2.
This is the conjugate prior for the univariate GaussianDistribution
(see its prior= argument) and the d=1 special case of NormalWishart (nu = 2a, W = 1/(2b)).
It is a parameter prior: it is scored on (mu, tau) parameter pairs, not fit from data by EM.
- class NormalGammaDistribution(mu, lam, a, b, name=None, prior=None)[source]
Bases:
SequenceEncodableProbabilityDistributionNormal-Gamma distribution over (mu, tau); conjugate prior for the univariate Gaussian.
- Parameters:
- get_parameters()[source]
Returns the parameter tuple (mu, lam, a, b).
- set_parameters(params)[source]
Set the parameters from a tuple (mu, lam, a, b).
- cross_entropy(dist)[source]
Cross-entropy H(self, dist) = -E_self[log dist].
Closed form for a NormalGamma argument; numerical double integration otherwise.
- Parameters:
dist (NormalGammaDistribution)
- Return type:
- entropy()[source]
Returns the entropy of the Normal-Gamma distribution (in nats).
- Return type:
- density(x)[source]
Density at x = (mu, tau); see log_density().
- log_density(x)[source]
Log-density at x = (mu, tau) with tau > 0.
- seq_log_density(x)[source]
Vectorized log-density at sequence-encoded (n, 2) array of (mu, tau) rows.
- sampler(seed=None)[source]
Create a NormalGammaSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
NormalGammaSampler
- estimator(pseudo_count=None)[source]
NormalGamma is a parameter prior and is not fit from data by EM.
- Parameters:
pseudo_count (float | None)
- Return type:
ParameterEstimator
- dist_to_encoder()[source]
Returns a NormalGammaDataEncoder object for encoding (mu, tau) pairs.
- Return type:
NormalGammaDataEncoder