Transformations of a random variable from one space to another.¶
Note that for convenience these entities can be addressed as
pm.transforms.X for any name X, although they are actually
implemented as pm.distributions.transforms.*X*.
Contents
Transform Instances¶
Transform instances are the entities that should be used in the
transform parameter to a random variable constructor. These are
initialized instances of the Transform Classes, which are described
below.
stick_breakingInstantiation of
StickBreakingTransformclass for use in thetransformargument of a random variable.logoddsInstantiation of
LogOddsTransformclass for use in thetransformargument of a random variable.intervalAlias of
IntervalTransformclass for use in thetransformargument of a random variable.log_exp_m1Instantiation of
LogExpM1Transformclass for use in thetransformargument of a random variable.lowerboundAlias of
LowerBoundTransformclass for use in thetransformargument of a random variable.upperboundAlias of
UpperBoundTransformclass for use in thetransformargument of a random variable.orderedInstantiation of
OrderedTransformclass for use in thetransformargument of a random variable.logInstantiation of
LogTransformclass for use in thetransformargument of a random variable.sum_to_1Instantiation of
SumTo1Transformclass for use in thetransformargument of a random variable.circularInstantiation of
CircularTransformclass for use in thetransformargument of a random variable.
Transform Base Classes¶
Typically the programmer will not use these directly.
-
class
pymc3.distributions.transforms.Transform¶ A transformation of a random variable from one space into another.
- Attributes
- name: str
-
backward(z)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
pymc3.distributions.transforms.transform¶
-
class
pymc3.distributions.transforms.TransformedDistribution(name, *args, **kwargs)¶ A distribution that has been transformed from one space into another.
- Parameters
- dist: Distribution
- transform: Transform
- args, kwargs
arguments to Distribution
-
logp(x)¶ Calculate log-probability of Transformed distribution at specified value.
- Parameters
- x: numeric
Value for which log-probability is calculated.
- Returns
- TensorVariable
-
logp_nojac(x)¶ Calculate log-probability of Transformed distribution at specified value without jacobian term for transforms.
- Parameters
- x: numeric
Value for which log-probability is calculated.
- Returns
- TensorVariable
Transform Composition Classes¶
-
class
pymc3.distributions.transforms.Chain(transform_list)¶ -
backward(y)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(y)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.CholeskyCovPacked(n)¶ -
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(y)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(y, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(y)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
Specific Transform Classes¶
-
class
pymc3.distributions.transforms.Log¶ -
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.LogExpM1¶ -
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Inverse operation of softplus.
- y = Log(Exp(x) - 1)
= Log(1 - Exp(-x)) + x
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.LogOdds¶ -
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
-
class
pymc3.distributions.transforms.Interval(a, b)¶ Transform from real line interval [a,b] to whole real line.
-
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.LowerBound(a)¶ Transform from real line interval [a,inf] to whole real line.
-
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.UpperBound(b)¶ Transform from real line interval [-inf,b] to whole real line.
-
backward(x)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.Ordered¶ -
backward(y)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(y)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.SumTo1¶ Transforms K - 1 dimensional simplex space (k values in [0,1] and that sum to 1) to a K - 1 vector of values in [0,1] This Transformation operates on the last dimension of the input tensor.
-
backward(y)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.StickBreaking(eps=None)¶ Transforms K - 1 dimensional simplex space (k values in [0,1] and that sum to 1) to a K - 1 vector of real values. This is a variant of the isometric logration transformation
Egozcue, J.J., Pawlowsky-Glahn, V., Mateu-Figueras, G. et al. Isometric Logratio Transformations for Compositional Data Analysis. Mathematical Geology 35, 279–300 (2003). https://doi.org/10.1023/A:1023818214614
-
backward(y_)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x_)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x_, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(y_)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-
-
class
pymc3.distributions.transforms.Circular¶ Transforms a linear space into a circular one.
-
backward(y)¶ Applies inverse of transformation to input variable z. When transform is used on some distribution p, which has observed values z, it is used to transform the values of z correctly to the support of p.
- Parameters
- z: tensor
Input tensor to be inverse transformed.
- Returns
- tensor
Inverse transformed tensor.
-
forward(x)¶ Applies transformation forward to input variable x. When transform is used on some distribution p, it will transform the random variable x after sampling from p.
- Parameters
- x: tensor
Input tensor to be transformed.
- Returns
- tensor
Transformed tensor.
-
forward_val(x, point=None)¶ Applies transformation forward to input array x. Similar to forward but for constant data.
- Parameters
- x: array_like
Input array to be transformed.
- point: array_like, optional
Test value used to draw (fix) bounds-like transformations
- Returns
- array_like
Transformed array.
-
jacobian_det(x)¶ Calculates logarithm of the absolute value of the Jacobian determinant of the backward transformation for input x.
- Parameters
- x: tensor
Input to calculate Jacobian determinant of.
- Returns
- tensor
The log abs Jacobian determinant of x w.r.t. this transform.
-