# pymc.ZeroSumNormal#

class pymc.ZeroSumNormal(*args, zerosum_axes=None, support_shape=None, dims=None, **kwargs)[source]#

ZeroSumNormal distribution, i.e Normal distribution where one or several axes are constrained to sum to zero. By default, the last axis is constrained to sum to zero. See zerosum_axes kwarg for more details.

\begin{split}\begin{align*} ZSN(\sigma) = N \Big( 0, \sigma^2 (I - \tfrac{1}{n}J) \Big) \\ \text{where} \ ~ J_{ij} = 1 \ ~ \text{and} \\ n = \text{nbr of zero-sum axes} \end{align*}\end{split}
Parameters
sigma

Scale parameter (sigma > 0). It’s actually the standard deviation of the underlying, unconstrained Normal distribution. Defaults to 1 if not specified. For now, sigma has to be a scalar, to ensure the zero-sum constraint.

zerosum_axes: int, defaults to 1

Number of axes along which the zero-sum constraint is enforced, starting from the rightmost position. Defaults to 1, i.e the rightmost axis.

dims: sequence of strings, optional

Dimension names of the distribution. Works the same as for other PyMC distributions. Necessary if shape is not passed.

shape: tuple of integers, optional

Shape of the distribution. Works the same as for other PyMC distributions. Necessary if dims or observed is not passed.

Warning

sigma has to be a scalar, to ensure the zero-sum constraint. The ability to specify a vector of sigma may be added in future versions.

zerosum_axes has to be > 0. If you want the behavior of zerosum_axes = 0, just use pm.Normal.

Examples

Define a ZeroSumNormal variable, with sigma=1 and zerosum_axes=1 by default:

COORDS = {
"regions": ["a", "b", "c"],
"answers": ["yes", "no", "whatever", "don't understand question"],
}
with pm.Model(coords=COORDS) as m:
# the zero sum axis will be 'answers'

 ZeroSumNormal.__init__(*args, **kwargs) ZeroSumNormal.check_zerosum_axes(zerosum_axes) ZeroSumNormal.dist([sigma, zerosum_axes, ...]) Creates a tensor variable corresponding to the cls distribution. ZeroSumNormal.rv_op(sigma, zerosum_axes, ...)