queens.distributions package#
Distributions.
Modules for probability distributions.
Submodules#
queens.distributions.bernoulli module#
Bernoulli distribution.
queens.distributions.beta module#
Beta Distribution.
- class Beta[source]#
Bases:
ContinuousBeta distribution.
A generalized one-dimensional beta distribution based on scipy stats. The generalized beta distribution has a lower bound and an upper bound. The parameters a and b determine the shape of the distribution within these bounds.
- lower_bound#
Lower bound of the beta distribution.
- upper_bound#
Upper bound of the beta distribution.
- a#
Shape parameter of the beta distribution, must be greater than 0.
- b#
Shape parameter of the beta distribution, must be greater than 0.
- scipy_beta#
Scipy beta distribution object.
- __init__(lower_bound, upper_bound, a, b)[source]#
Initialize Beta distribution.
- Parameters:
lower_bound (float | ndarray) – Lower bound of the beta distribution.
upper_bound (float | ndarray) – Upper bound of the beta distribution.
a (float) – Shape parameter of the beta distribution, must be > 0.
b (float) – Shape parameter of the beta distribution, must be > 0.
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of the log-PDF is evaluated
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
queens.distributions.categorical module#
General categorical distribution.
Disclaimer: Most of our iterators are not able to handle categorical distributions.
- class Categorical[source]#
Bases:
DistributionGeneral categorical distribution.
- probabilities#
Probabilities associated with the categories
- categories#
Categories
- __init__(probabilities, categories)[source]#
Initialize categorical distribution.
- Parameters:
probabilities (ndarray) – Probabilities associated with the categories
categories (ndarray) – Categories
- Return type:
None
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Samples of the categorical distribution
- Return type:
ndarray
queens.distributions.exponential module#
Exponential distribution.
- class Exponential[source]#
Bases:
ContinuousExponential distribution class.
For a multivariate distribution the components are assumed to be independent.
- rate#
Rate parameter(s) of the distribution.
- scale#
Scale parameters(s) of the distribution (\(scale = \frac{1}{rate}\)) .
- pdf_const#
Constant for the evaluation of the PDF.
- logpdf_const#
Constant for the evaluation of the log-PDF.
- __init__(rate)[source]#
Initialize exponential distribution.
- Parameters:
rate (float | ndarray) – rate parameter(s) of the distribution
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of the log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
queens.distributions.free_variable module#
Free Variable.
- class FreeVariable[source]#
Bases:
ContinuousFree variable class.
This is not a proper distribution class. It is used for variables with no underlying distribution.
- __init__(dimension)[source]#
Initialize FreeVariable object.
- Parameters:
dimension (int) – Dimensionality of the variable
- Return type:
None
- grad_logpdf(_)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
_ (Any)
- Return type:
ndarray
queens.distributions.lognormal module#
LogNormal Distribution.
- class LogNormal[source]#
Bases:
ContinuousLogNormal distribution.
Support in (0, +inf).
- normal_distribution#
Underlying normal distribution.
- __init__(normal_mean, normal_covariance)[source]#
Initialize lognormal distribution.
- Parameters:
normal_mean (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – mean of the normal distribution
normal_covariance (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – covariance of the normal distribution
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
- pdf(x)[source]#
Probability density function.
- Parameters:
x (ndarray) – Positions at which the PDF is evaluated
- Returns:
PDF at positions
- Return type:
ndarray
- ppf(quantiles)[source]#
Percent point function (inverse of CDF — quantiles).
- Parameters:
quantiles (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Quantiles at which the PPF is evaluated
- Returns:
Positions which correspond to given quantiles
- Return type:
ndarray
queens.distributions.mean_field_normal module#
Mean-field normal distribution.
- class MeanFieldNormal[source]#
Bases:
ContinuousMean-field normal distribution.
- standard_deviation#
Standard deviation vector
- __init__(mean, variance, dimension)[source]#
Initialize mean-field normal distribution.
- Parameters:
mean (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Mean of the distribution
variance (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Variance of the distribution
dimension (int) – Dimensionality of the distribution
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- static get_check_array_dimension_and_reshape(input_array, dimension)[source]#
Check dimensions and potentially reshape array.
- Parameters:
input_array (ndarray) – Input array
dimension (int) – Dimension of the array
- Returns:
Input array with correct dimension
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
- grad_logpdf_var(x)[source]#
Gradient of the log-PDF with respect to the variance vector.
- Parameters:
x (ndarray) – Positions at which the gradient of the log-PDF is evaluated
- Returns:
Gradient of the log-PDF w.r.t. the variance at given variance vector and position x
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
- ppf(quantiles)[source]#
Percent point function (inverse of cdf — quantiles).
- Parameters:
quantiles (ndarray) – Quantiles at which the PPF is evaluated
- Return type:
ndarray
queens.distributions.mixture module#
Mixture distribution.
- class Mixture[source]#
Bases:
ContinuousMixture models.
- __init__(weights, component_distributions)[source]#
Initialize mixture model.
- Parameters:
weights (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Weights of the mixtures
component_distributions (Sequence[Continuous]) – Component distributions of the mixture
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF of the mixture model
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw num_draw samples from the variational distribution.
- Uses a two step process:
From a multinomial distribution, based on the weights, select a component
Sample from the selected component
- Parameters:
num_draws (int) – Number of samples to draw
- Returns:
Row-wise samples of the variational distribution
- Return type:
ndarray
- export_dict()[source]#
Create a dict of the distribution.
- Returns:
Dictionary containing distribution information
- Return type:
dict
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
- pdf(x)[source]#
Probability density function.
- Parameters:
x (ndarray) – Positions at which the PDF is evaluated
- Returns:
PDF at positions
- Return type:
ndarray
- ppf(quantiles)[source]#
Percent point function (inverse of CDF — quantiles).
- Parameters:
quantiles (ndarray) – Quantiles at which the PPF is evaluated
- Return type:
ndarray
- responsibilities(x)[source]#
Compute the responsibilities.
The responsibilities are defined as [1]:
- Math:
gamma_j(x)=frac{w_j p_j(x)}{sum_{i=0}^{n_{components}-1}w_i p_i(x)}
- Parameters:
x (ndarray)
- Return type:
ndarray
[1]: Bishop, C. M. (2006). Pattern recognition and machine learning. Springer.
- Parameters:
x (ndarray) – Positions at which the responsibilities are evaluated
- Returns:
Responsibilities (number of samples x number of component)
- Return type:
ndarray
queens.distributions.multinomial module#
Multinomial distribution.
- class Multinomial[source]#
Bases:
DiscreteMultinomial distribution.
- __init__(n_trials, probabilities)[source]#
Initialize discrete uniform distribution.
- Parameters:
n_trials (int) – Number of trials, i.e., the value to which every multivariate sample adds up to.
probabilities (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Probabilities associated with all the events in the sample space.
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Return type:
None
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability mass function.
- Parameters:
x (ndarray) – Positions at which the log-PMF is evaluated
- Returns:
Log-PMF at positions
- Return type:
ndarray
queens.distributions.normal module#
Normal distribution.
- class Normal[source]#
Bases:
ContinuousNormal distribution.
- low_chol#
Lower-triangular Cholesky factor of covariance matrix.
- precision#
Precision matrix corresponding to covariance matrix.
- logpdf_const#
Constant for evaluation of log-PDF.
- __init__(mean, covariance)[source]#
Initialize normal distribution.
- Parameters:
mean (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Mean of the distribution
covariance (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Covariance of the distribution
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
- ppf(quantiles)[source]#
Percent point function (inverse of CDF — quantiles).
- Parameters:
quantiles (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Quantiles at which the PPF is evaluated
- Returns:
Positions which correspond to given quantiles
- Return type:
ndarray
queens.distributions.particle module#
Discrete particle distribution.
- class Particle[source]#
Bases:
DiscreteDiscrete probability distributions.
Similar to particles in SMC, we use the approach where a distribution is approximated as particles:
The particles are the events of the sample space
The weights are denoted by the probabilities of the events
This class can be used directly, but is also used as parent class for other 1d discrete distributions as the computation of expectations is done in the same fashion.
- mean#
Mean of the distribution
- covariance#
Covariance of the distribution
- dimension#
Dimensionality of the distribution
- probabilities#
Probabilities associated with all the events in the sample space
- sample_space#
Samples, i.e. possible outcomes of sampling the distribution
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF value of the distribution
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability mass function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
queens.distributions.uniform module#
Uniform distribution.
- class Uniform[source]#
Bases:
ContinuousUniform distribution class.
- lower_bound#
Lower bound(s) of the distribution.
- upper_bound#
Upper bound(s) of the distribution.
- width#
Width(s) of the distribution.
- pdf_const#
Constant for the evaluation of the PDF.
- logpdf_const#
Constant for the evaluation of the log-PDF.
- __init__(lower_bound, upper_bound)[source]#
Initialize uniform distribution.
- Parameters:
lower_bound (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Lower bound(s) of the distribution
upper_bound (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Upper bound(s) of the distribution
- Return type:
None
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (ndarray) – Positions at which the CDF is evaluated
- Returns:
CDF at positions
- Return type:
ndarray
- draw(num_draws=1)[source]#
Draw samples.
- Parameters:
num_draws (int) – Number of draws
- Returns:
Drawn samples from the distribution
- Return type:
ndarray
- grad_logpdf(x)[source]#
Gradient of the log-PDF with respect to x.
- Parameters:
x (ndarray) – Positions at which the gradient of log-PDF is evaluated
- Returns:
Gradient of the log-PDF evaluated at positions
- Return type:
ndarray
- logpdf(x)[source]#
Log of the probability density function.
- Parameters:
x (ndarray) – Positions at which the log-PDF is evaluated
- Returns:
Log-PDF at positions
- Return type:
ndarray
queens.distributions.uniform_discrete module#
Discrete uniform distribution.