Distributions¶
The distributions module provides probability distributions used for shocks and initial conditions. Continuous distributions support both drawing random samples and discretization into point-mass approximations.
Note
Normal and Lognormal are parameterized by the distribution’s mean and
standard deviation in levels, not by the log-space parameters
\((\mu, \sigma)\) familiar from other libraries. A standard deviation of zero
produces a degenerate point mass at the mean argument.
Distribution classes that provide compatibility with scipy.stats and torch.distributions for better integration with neural network methods while maintaining API compatibility.
- class skagent.distributions.Bernoulli(p=0.5, backend='scipy', rng=None)¶
Bernoulli distribution compatible with skagent.distributions.Bernoulli
- discretize(**kwargs)¶
Bernoulli is already discrete
- Return type:
- icdf(u)¶
Bernoulli’s quantile function.
Neither backend supplies a usable one:
torch.distributions.BernoulliraisesNotImplementedError, and scipy’sppfmaps u = 0, whichrng.randomcan return, to -1.- Return type:
- class skagent.distributions.DiscreteDistribution(points, weights, var_names=None, rng=None)¶
A discrete distribution representation for labeled discrete distributions
- class skagent.distributions.DiscreteDistributionLabeled(points, weights, var_names=None, rng=None)¶
Labeled discrete distribution with variable names
- class skagent.distributions.Distribution(backend='scipy', rng=None)¶
Base class for all distributions, providing a common interface that works with both scipy and torch backends.
- abstractmethod discretize(**kwargs)¶
Discretize the distribution
- Return type:
- draw(n=1)¶
Draw n samples from the distribution.
Samples are taken by inverting the distribution at uniform draws from
self.rng, so that two distributions sharing a generator state and differing slightly in their parameters produce samples that differ slightly, rather than a different sample path.
- icdf(u)¶
Quantile function: the value below which a proportion u of the mass lies.
- Parameters:
u (array_like) – Probabilities in [0, 1].
- Return type:
- log_prob(x)¶
Log density (or log mass, for a discrete distribution) at x.
- Parameters:
x (array_like) – Points in the support of the distribution.
- Return type:
- class skagent.distributions.IndexDistribution(dist_class, params_dict, rng=None)¶
Distribution that varies by index (like age), compatible with skagent.distributions.IndexDistribution
- class skagent.distributions.Lognormal(mean=1.0, std=1.0, backend='scipy', rng=None)¶
Lognormal distribution compatible with skagent.distributions.Lognormal
- discretize(n_points=7, N=None, **kwargs)¶
Discretize using Gauss-Hermite quadrature on the log
- Parameters:
- Return type:
- icdf(u)¶
Quantile function: the value below which a proportion u of the mass lies.
- Parameters:
u (array_like) – Probabilities in [0, 1].
- Return type:
- class skagent.distributions.MeanOneLogNormal(sigma=1.0, backend='scipy', rng=None)¶
Lognormal distribution with mean normalized to 1.0
- class skagent.distributions.Normal(mu=0.0, sigma=1.0, backend='scipy', rng=None)¶
Normal distribution compatible with skagent.distributions.Normal
- discretize(n_points=7, sigma_range=3.0, N=None, **kwargs)¶
Discretize using Gauss-Hermite quadrature or uniform grid
- Parameters:
- Return type:
- icdf(u)¶
Quantile function: the value below which a proportion u of the mass lies.
- Parameters:
u (array_like) – Probabilities in [0, 1].
- Return type:
- class skagent.distributions.TimeVaryingDiscreteDistribution(distributions)¶
Time-varying discrete distribution for compatibility
- Parameters:
distributions (
list[DiscreteDistribution])
- class skagent.distributions.Uniform(low=0.0, high=1.0, backend='scipy', rng=None)¶
Uniform distribution
- discretize(n_points=7, N=None, **kwargs)¶
Discretize using Gauss-Hermite quadrature or uniform grid
- Parameters:
- Return type:
- icdf(u)¶
Quantile function: the value below which a proportion u of the mass lies.
- Parameters:
u (array_like) – Probabilities in [0, 1].
- Return type:
- skagent.distributions.combine_indep_dstns(*distributions)¶
Combine independent discrete distributions into a joint distribution Compatible with skagent.distributions.combine_indep_dstns
- Return type:
- skagent.distributions.expected(func, dist)¶
Compute expected value of a function over a discrete distribution Compatible with skagent.distributions.expected
- Parameters:
dist (
DiscreteDistribution)- Return type:
- skagent.distributions.set_rng(obj, rng)¶
Point obj and everything it draws through at rng.
A distribution that holds other distributions draws through the ones it holds, so its own generator is not the one that produces its values:
IndexDistributiondraws throughdistributions[condition]andAggregatethroughdist. Seeding such an object means seeding what it defers to, which is why this recurses rather than assigning one attribute.Every reachable distribution is pointed at the same generator, so one stream produces the whole draw and the sequence is reproducible from the seed that generator was built with.