# Probability Distributions¶

## Distribution - Abstract Base Class for Probability Distributions¶

class qinfer.Distribution[source]

Bases: object

Abstract base class for probability distributions on one or more random variables.

n_rvs

The number of random variables that this distribution is over.

Return type: int
sample(n=1)[source]

Returns one or more samples from this probability distribution.

Parameters: Return numpy.ndarray: n (int) – Number of samples to return. An array containing samples from the distribution of shape (n, d), where d is the number of random variables.

## Specific Distributions¶

class qinfer.UniformDistribution(ranges=array([[0, 1]]))[source]

Bases: qinfer.distributions.Distribution

Uniform distribution on a given rectangular region.

Parameters: ranges (numpy.ndarray) – Array of shape (n_rvs, 2), where n_rvs is the number of random variables, specifying the upper and lower limits for each variable.
n_rvs
sample(n=1)[source]
grad_log_pdf(var)[source]
class qinfer.NormalDistribution(mean, var, trunc=None)[source]

Bases: qinfer.distributions.Distribution

Parameters: trunc (tuple) – Limits at which the PDF of this distribution should be truncated, or None if the distribution is to have infinite support.
n_rvs
sample(n=1)[source]
grad_log_pdf(x)[source]
class qinfer.MultivariateNormalDistribution(mean, cov)[source]

Bases: qinfer.distributions.Distribution

n_rvs
sample(n=1)[source]
grad_log_pdf(x)[source]
class qinfer.ConstantDistribution(values)[source]

Bases: qinfer.distributions.Distribution

Represents a determinstic variable; useful for combining with other distributions, marginalizing, etc.

Parameters: values – Shape (n,) array or list of values $$X_0$$ such that $$\Pr(X) = \delta(X - X_0)$$.
n_rvs
sample(n=1)[source]
class qinfer.HilbertSchmidtUniform(dim=2)[source]

Bases: qinfer.distributions.SingleSampleMixin, qinfer.distributions.Distribution

Creates a new Hilber-Schmidt uniform prior on state space of dimension dim. See e.g. [Mez06] and [Mis12].

Parameters: dim (int) – Dimension of the state space.
n_rvs
sample()[source]
make_Paulis(paulis, d)[source]
class qinfer.HaarUniform(dim=2)[source]

Bases: qinfer.distributions.SingleSampleMixin, qinfer.distributions.Distribution

Creates a new Haar uniform prior on state space of dimension dim.

Parameters: dim (int) – Dimension of the state space.
n_rvs
sample()[source]
class qinfer.GinibreUniform(dim=2, k=2)[source]

Bases: qinfer.distributions.SingleSampleMixin, qinfer.distributions.Distribution

Creates a prior on state space of dimension dim according to the Ginibre ensemble with parameter k. See e.g. [Mis12].

Parameters: dim (int) – Dimension of the state space.
n_rvs
sample()[source]

## Combining Distributions¶

QInfer also offers classes for combining distributions together to produce new ones.

class qinfer.ProductDistribution(*factors)[source]

Bases: qinfer.distributions.Distribution

Takes a non-zero number of QInfer distributions $$D_k$$ as input and returns their Cartesian product.

In other words, the returned distribution is $$\Pr(\prod_k D_k) = \prod_k \Pr(D_k)$$.

Parameters: *factors – Distribution objects representing $$D_k$$. Alternatively, one iterable argument can be given, in which case the factors are the values drawn from that iterator.
n_rvs
sample(n=1)[source]
class qinfer.PostselectedDistribution(distribution, model, maxiters=100)[source]

Bases: qinfer.distributions.Distribution

Postselects a distribution based on validity within a given model.

n_rvs
sample(n=1)[source]

Returns one or more samples from this probability distribution.

Parameters: Return numpy.ndarray: n (int) – Number of samples to return. An array containing samples from the distribution of shape (n, d), where d is the number of random variables.
grad_log_pdf(x)[source]