Utility Functions

Function Reference

qinfer.utils.binomial_pdf(N, n, p)[source]

Returns the PDF of the binomial distribution \(\operatorname{Bin}(N, p)\) evaluated at \(n\).

qinfer.utils.outer_product(vec)[source]

Returns the outer product of a vector \(v\) with itself, \(v v^\T\).

qinfer.utils.particle_meanfn(weights, locations, fn=None)[source]

Returns the mean of a function \(f\) over model parameters.

Parameters:
  • weights (numpy.ndarray) – Weights of each particle.
  • locations (numpy.ndarray) – Locations of each particle.
  • fn (callable) – Function of model parameters to take the mean of. If None, the identity function is assumed.
qinfer.utils.particle_covariance_mtx(weights, locations)[source]

Returns an estimate of the covariance of a distribution represented by a given set of SMC particle.

Parameters:
  • weights – An array containing the weights of each particle.
  • location – An array containing the locations of each particle.
Return type:

numpy.ndarray, shape (n_modelparams, n_modelparams).

Returns:

An array containing the estimated covariance matrix.

qinfer.utils.in_ellipsoid(x, A, c)[source]

Determines which of the points x are in the closed ellipsoid with shape matrix A centered at c. For a single point x, this is computed as

\[(c-x)^T\cdot A^{-1}\cdot (c-x) \leq 1 \]
Parameters:
  • x (np.ndarray) – Shape (n_points, dim) or n_points.
  • A (np.ndarray) – Shape (dim, dim), positive definite
  • c (np.ndarray) – Shape (dim)
Returns:

bool or array of bools of length n_points

qinfer.utils.ellipsoid_volume(A=None, invA=None)[source]

Returns the volume of an ellipsoid given either its matrix or the inverse of its matrix.

qinfer.utils.mvee(points, tol=0.001)[source]

Returns the minimum-volume enclosing ellipse (MVEE) of a set of points, using the Khachiyan algorithm.

qinfer.utils.uniquify(seq)[source]

Returns the unique elements of a sequence seq.

qinfer.utils.format_uncertainty(value, uncertianty, scinotn_break=4)[source]

Given a value and its uncertianty, format as a LaTeX string for pretty-printing.

Parameters:scinotn_break (int) – How many decimal points to print before breaking into scientific notation.