Attend the Women in ML Symposium on December 7 Register now

tfp.substrates.numpy.distributions.JohnsonSU

Stay organized with collections Save and categorize content based on your preferences.

Johnson's SU-distribution.

Inherits From: TransformedDistribution, Distribution

This distribution has parameters: shape parameters skewness and tailweight, location loc, and scale.

Mathematical details

The probability density function (pdf) is,

pdf(x; s, t, xi, sigma) = exp(-0.5 (s + t arcsinh(y))**2) / Z
where,
s = skewness
t = tailweight
y = (x - xi) / sigma
Z = sigma sqrt(2 pi) sqrt(1 + y**2) / t

where:

  • loc = xi,
  • scale = sigma, and,
  • Z is the normalization constant.

The JohnsonSU distribution is a member of the location-scale family, i.e., it can be constructed as,

X ~ JohnsonSU(skewness, tailweight, loc=0, scale=1)
Y = loc + scale * X

Examples

Examples of initialization of one or a batch of distributions.

import tensorflow_probability as tfp; tfp = tfp.substrates.numpy
tfd = tfp.distributions

# Define a single scalar Johnson's SU-distribution.
single_dist = tfd.JohnsonSU(skewness=-2., tailweight=2., loc=1.1, scale=1.5)

# Evaluate the pdf at 1, returning a scalar Tensor.
single_dist.prob(1.)

# Define a batch of two scalar valued Johnson SU's.
# The first has shape parameters 1 and 2, mean 3, and scale 11.
# The second 4, 5, 6 and 22.
multi_dist = tfd.JohnsonSU(skewness=[1, 4], tailweight=[2, 5],
                           loc=[3, 6], scale=[11, 22.])

# Evaluate the pdf of the first distribution on 0, and the second on 1.5,
# returning a length two tensor.
multi_dist.prob([0, 1.5])

# Get 3 samples, returning a 3 x 2 tensor.
multi_dist.sample(3)

Arguments are broadcast when possible.

# Define a batch of two Johnson's SU distributions.
# Both have skewness 2, tailweight 3 and mean 1, but different scales.
dist = tfd.JohnsonSU(skewness=2, tailweight=3, loc=1, scale=[11, 22.])

# Evaluate the pdf of both distributions on the same point, 3.0,
# returning a length 2 tensor.
dist.prob(3.0)

Compute the gradients of samples w.r.t. the parameters:

skewness = tf.Variable(2.0)
tailweight = tf.Variable(3.0)
loc = tf.Variable(2.0)
scale = tf.Variable(11.0)
dist = tfd.JohnsonSU(skewness=skewness, tailweight=tailweight, loc=loc,
                     scale=scale)
with tf.GradientTape() as tape:
  samples = dist.sample(5)  # Shape [5]
  loss = tf.reduce_mean(tf.square(samples))  # Arbitrary loss function
# Unbiased stochastic gradients of the loss function
grads = tape.gradient(loss, dist.variables)

skewness Floating-point Tensor. Skewness of the distribution(s).
tailweight Floating-point Tensor. Tail weight of the distribution(s). tailweight must contain only positive values.
loc Floating-point Tensor. The mean(s) of the distribution(s).
scale Floating-point Tensor. The scaling factor(s) for the distribution(s). Note that scale is not technically the standard deviation of this distribution but has semantics more similar to standard deviation than variance.
validate_args Python bool, default False. When True distribution parameters are checked for validity despite possibly degrading runtime performance. When False invalid inputs may silently render incorrect outputs.
allow_nan_stats Python bool, default True. When True, statistics (e.g., mean, mode, variance) use the value 'NaN' to indicate the result is undefined. When False, an exception is raised if one or more of the statistic's batch members are undefined.
name Python str name prefixed to Ops created by this class.

TypeError if any of skewness, tailweight, loc and scale are different dtypes.

allow_nan_stats Python bool describing behavior when a stat is undefined.

Stats return +/- infinity when it makes sense. E.g., the variance of a Cauchy distribution is infinity. However, sometimes the statistic is undefined, e.g., if a distribution's pdf does not achieve a maximum within the support of the distribution, the mode is undefined. If the mean is undefined, then by definition the variance is undefined. E.g. the mean for Student's T for df = 1 is undefined (no clear way to say it is either + or - infinity), so the variance = E[(X - mean)**2] is also undefined.

batch_shape Shape of a single sample from a single event index as a TensorShape.

May be partially defined or unknown.

The batch dimensions are indexes into independent, non-identical parameterizations of this distribution.

bijector Function transforming x => y.
distribution Base distribution, p(x).
dtype The DType of Tensors handled by this Distribution.
event_shape Shape of a single sample from a single batch as a TensorShape.

May be partially defined or unknown.

experimental_shard_axis_names The list or structure of lists of active shard axis names.
loc Locations of these Johnson's SU distribution(s).
name Name prepended to all ops created by this Distribution.
parameters Dictionary of parameters used to instantiate this Distribution.
reparameterization_type Describes how samples from the distribution are reparameterized.

Currently this is one of the static instances tfd.FULLY_REPARAMETERIZED or tfd.NOT_REPARAMETERIZED.

scale Scaling factors of these Johnson's SU distribution(s).
skewness Skewness of these Johnson's SU distribution(s).
tailweight Tail weight of these Johnson's SU distribution(s).
trainable_variables

validate_args Python bool indicating possibly expensive checks are enabled.
variables

Methods

batch_shape_tensor

View source

Shape of a single sample from a single event index as a 1-D Tensor.

The batch dimensions are indexes into independent, non-identical parameterizations of this distribution.

Args
name name to give to the op

Returns
batch_shape Tensor.

cdf

View source

Cumulative distribution function.

Given random variable X, the cumulative distribution function cdf is:

cdf(x) := P[X <= x]

Args
value float or double Tensor.
name Python str prepended to names of ops created by this function.
**kwargs Named arguments forwarded to subclass implementation.

Returns
cdf a Tensor of shape sample_shape(x) + self.batch_shape with values of type self.dtype.

copy

View source

Creates a deep copy of the distribution.

Args
**override_parameters_kwargs String/value dictionary of initialization arguments to override with new values.

Returns
distribution A new instance of type(self) initialized from the union of self.parameters and override_parameters_kwargs, i.e., dict(self.parameters, **override_parameters_kwargs).

covariance

View source

Covariance.

Covariance is (possibly) defined only for non-scalar-event distributions.

For example, for a length-k, vector-valued distribution, it is calculated as,

Cov[i, j] = Covariance(X_i, X_j) = E[(X_i - E[X_i]) (X_j - E[X_j])]

where Cov is a (batch of) k x k matrix, 0 <= (i, j) < k, and E denotes expectation.

Alternatively, for non-vector, multivariate distributions (e.g., matrix-valued, Wishart), Covariance shall return a (batch of) matrices under some vectorization of the events, i.e.,

Cov[i, j] = Covariance(Vec(X)_i, Vec(X)_j) = [as above]

where Cov is a (batch of) k' x k' matrices, 0 <= (i, j) < k' = reduce_prod(event_shape), and Vec is some function mapping indices of this distribution's event dimensions to indices of a length-k' vector.

Args
name Python str prepended to names of ops created by this function.
**kwargs Named arguments forwarded to subclass implementation.

Returns
covariance Floating-point Tensor with shape [B1, ..., Bn, k', k'] where the first n dimensions are batch coordinates and k' = reduce_prod(self.event_shape).

cross_entropy

View source

Computes the (Shannon) cross entropy.

Denote this distribution (self) by P and the other distribution by Q. Assuming P, Q are absolutely continuous with respect to one another and permit densities p(x) dr(x) and q(x) dr(x), (Shannon) cross entropy is defined as:

H[P, Q] = E_p[-log q(X)] = -int_F p(x) log q(x) dr(x)

where F denotes the support of the random variable X ~ P.

other types with built-in registrations: Chi, ExpInverseGamma,