queens.distributions package#

Distributions.

Modules for probability distributions.

Submodules#

queens.distributions.bernoulli module#

Bernoulli distribution.

class Bernoulli(success_probability)[source]#

Bases: Particle

Bernoulli distribution.

queens.distributions.beta module#

Beta Distribution.

class Beta(lower_bound, upper_bound, a, b)[source]#

Bases: Continuous

Beta 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.

Type:

np.ndarray

upper_bound#

Upper bound of the beta distribution.

Type:

np.ndarray

a#

Shape parameter of the beta distribution, must be greater than 0.

Type:

float

b#

Shape parameter of the beta distribution, must be greater than 0.

Type:

float

scipy_beta#

Scipy beta distribution object.

Type:

scipy.stats.beta

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – CDF at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – drawn samples from the distribution

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – log pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – Pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

ppf (np.ndarray) – Positions which correspond to given quantiles

queens.distributions.categorical module#

General categorical distribution.

Disclaimer: Most of our iterators are not able to handle categorical distributions.

class Categorical(probabilities, categories)[source]#

Bases: Distribution

General categorical distribution.

probabilities#

Probabilities associated with the categories

Type:

np.ndarray

categories#

Categories

Type:

np.ndarray

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

np.ndarray – Samples of the categorical distribution

logpdf(x)[source]#

Log of the probability mass function.

Parameters:

x (np.ndarray) – Positions at which the log pmf is evaluated

Returns:

np.ndarray – log pmf

pdf(x)[source]#

Probability mass function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

np.ndarray – pmf

queens.distributions.exponential module#

Exponential distribution.

class Exponential(rate)[source]#

Bases: Continuous

Exponential distribution class.

For a multivariate distribution the components are assumed to be independent.

rate#

Rate parameter(s) of the distribution.

Type:

np.ndarray

scale#

Scale parameters(s) of the distribution (\(scale = \frac{1}{rate}\)) .

Type:

np.ndarray

pdf_const#

Constant for the evaluation of the pdf.

Type:

float

logpdf_const#

Constant for the evaluation of the log pdf.

Type:

float

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – cdf at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – Drawn samples from the distribution

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf (np.ndarray) – Gradient of the log pdf evaluated at positions

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – log pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – Pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

ppf (np.ndarray) – Positions which correspond to given quantiles

queens.distributions.free_variable module#

Free Variable.

class FreeVariable(dimension)[source]#

Bases: Continuous

Free variable class.

This is not a proper distribution class. It is used for variables with no underlying distribution.

cdf(_)[source]#

Cumulative distribution function.

draw(_=1)[source]#

Draw samples.

grad_logpdf(_)[source]#

Gradient of the log pdf with respect to x.

logpdf(_)[source]#

Log of the probability density function.

pdf(_)[source]#

Probability density function.

ppf(_)[source]#

Percent point function (inverse of cdf — quantiles).

queens.distributions.lognormal module#

LogNormal Distribution.

class LogNormal(normal_mean, normal_covariance)[source]#

Bases: Continuous

LogNormal distribution.

Support in (0, +inf).

normal_distribution#

Underlying normal distribution.

Type:

Normal

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – cdf at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – Drawn samples from the distribution

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf (np.ndarray) – Gradient of the log pdf evaluated at positions

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

ppf (np.ndarray) – Positions which correspond to given quantiles

queens.distributions.mean_field_normal module#

Mean-field normal distribution.

class MeanFieldNormal(mean, variance, dimension)[source]#

Bases: Continuous

Mean-field normal distribution.

standard_deviation#

standard deviation vector

Type:

np.ndarray

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – cdf at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – Drawn samples from the distribution

static get_check_array_dimension_and_reshape(input_array, dimension)[source]#

Check dimensions and potentially reshape array.

Parameters:
  • input_array (np.ndarray) – Input array

  • dimension (int) – Dimension of the array

Returns:

input_array (np.ndarray) – Input array with correct dimension

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf (np.ndarray) – Gradient of the log pdf evaluated at positions

grad_logpdf_var(x)[source]#

Gradient of the log pdf with respect to the variance vector.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf_var (np.ndarray) – Gradient of the log pdf w.r.t. the variance at given variance vector and position x

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – log pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

update_mean(mean)[source]#

Update the mean of the mean field distribution.

Parameters:

mean (np.array) – New mean vector

update_variance(variance)[source]#

Update the variance of the mean field distribution.

Parameters:

variance (np.array) – New variance vector

queens.distributions.mixture module#

Mixture distribution.

class Mixture(weights, component_distributions)[source]#

Bases: Continuous

Mixture models.

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

np.ndarray – CDF of the mixture model

draw(num_draws=1)[source]#

Draw num_draw samples from the variational distribution.

Uses a two step process:
  1. From a multinomial distribution, based on the weights, select a component

  2. Sample from the selected component

Parameters:

num_draws (int) – Number of samples to draw

Returns:

samples (np.ndarray) – Row wise samples of the variational distribution

export_dict()[source]#

Create a dict of the distribution.

Returns:

export_dict (dict) – Dict containing distribution information

classmethod from_config_create_distribution(distribution_options)[source]#

Create mixture model from config.

Parameters:

distribution_options (dict) – description of the distribution

Returns:

Mixture – mixture model

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

ppf(_)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

q (np.ndarray) – Quantiles at which the ppf is evaluated

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)}

[1]: Bishop, C. M. (2006). Pattern recognition and machine learning. Springer.

Parameters:

x (np.ndarray) – Positions at which the responsibilities are evaluated

Returns:

np.ndarray – responsibilities (number of samples x number of component)

queens.distributions.multinomial module#

Multinomial distribution.

class Multinomial(n_trials, probabilities)[source]#

Bases: Discrete

Multinomial distribution.

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

logpdf(x)[source]#

Log of the probability mass function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

pdf(x)[source]#

Probability mass function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

ppf(quantiles)[source]#

Percent point function (inverse of cdf - quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

queens.distributions.normal module#

Normal distribution.

class Normal(mean, covariance)[source]#

Bases: Continuous

Normal distribution.

low_chol#

Lower-triangular Cholesky factor of covariance matrix.

Type:

np.ndarray

precision#

Precision matrix corresponding to covariance matrix.

Type:

np.ndarray

logpdf_const#

Constant for evaluation of log pdf.

Type:

float

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – cdf at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – Drawn samples from the distribution

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf (np.ndarray) – Gradient of the log pdf evaluated at positions

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – log pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

ppf (np.ndarray) – Positions which correspond to given quantiles

update_covariance(covariance)[source]#

Update covariance and dependent distribution parameters.

Parameters:

covariance (np.ndarray) – Covariance matrix

queens.distributions.particle module#

Discrete particle distribution.

class Particle(probabilities, sample_space, dimension=None)[source]#

Bases: Discrete

Discrete 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

Type:

np.ndarray

covariance#

Covariance of the distribution

Type:

np.ndarray

dimension#

Dimensionality of the distribution

Type:

int

probabilities#

Probabilities associated to all the events in the sample space

Type:

np.ndarray

sample_space#

Samples, i.e. possible outcomes of sampling the distribution

Type:

np.ndarray

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

np.ndarray – CDF value of the distribution

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

logpdf(x)[source]#

Log of the probability mass function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

pdf(x)[source]#

Probability mass function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

ppf(quantiles)[source]#

Percent point function (inverse of cdf-quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

np.ndarray – Event samples corresponding to the quantiles

queens.distributions.uniform module#

Uniform distribution.

class Uniform(lower_bound, upper_bound)[source]#

Bases: Continuous

Uniform distribution class.

lower_bound#

Lower bound(s) of the distribution.

Type:

np.ndarray

upper_bound#

Upper bound(s) of the distribution.

Type:

np.ndarray

width#

Width(s) of the distribution.

Type:

np.ndarray

pdf_const#

Constant for the evaluation of the pdf.

Type:

float

logpdf_const#

Constant for the evaluation of the log pdf.

Type:

float

cdf(x)[source]#

Cumulative distribution function.

Parameters:

x (np.ndarray) – Positions at which the cdf is evaluated

Returns:

cdf (np.ndarray) – Cdf at evaluated positions

draw(num_draws=1)[source]#

Draw samples.

Parameters:

num_draws (int, optional) – Number of draws

Returns:

samples (np.ndarray) – Drawn samples from the distribution

grad_logpdf(x)[source]#

Gradient of the log pdf with respect to x.

Parameters:

x (np.ndarray) – Positions at which the gradient of log pdf is evaluated

Returns:

grad_logpdf (np.ndarray) – Gradient of the log pdf evaluated at positions

logpdf(x)[source]#

Log of the probability density function.

Parameters:

x (np.ndarray) – Positions at which the log pdf is evaluated

Returns:

logpdf (np.ndarray) – log pdf at evaluated positions

pdf(x)[source]#

Probability density function.

Parameters:

x (np.ndarray) – Positions at which the pdf is evaluated

Returns:

pdf (np.ndarray) – pdf at evaluated positions

ppf(quantiles)[source]#

Percent point function (inverse of cdf — quantiles).

Parameters:

quantiles (np.ndarray) – Quantiles at which the ppf is evaluated

Returns:

ppf (np.ndarray) – Positions which correspond to given quantiles

queens.distributions.uniform_discrete module#

Discrete uniform distribution.

class UniformDiscrete(sample_space)[source]#

Bases: Particle

Discrete uniform distribution.