LostTech.TensorFlow : API Documentation

Type Distribution

Namespace tensorflow.distributions

Parent PythonObjectContainer

Interfaces _BaseDistribution, IDistribution

A generic probability distribution base class.

`Distribution` is a base class for constructing and organizing properties (e.g., mean, variance) of random variables (e.g, Bernoulli, Gaussian).

#### Subclassing

Subclasses are expected to implement a leading-underscore version of the same-named function. The argument signature should be identical except for the omission of `name="..."`. For example, to enable `log_prob(value, name="log_prob")` a subclass should implement `_log_prob(value)`.

Subclasses can append to public-level docstrings by providing docstrings for their method specializations. would add the string "Some other details." to the `log_prob` function docstring. This is implemented as a simple decorator to avoid python linter complaining about missing Args/Returns/Raises sections in the partial docstrings.

#### Broadcasting, batching, and shapes

All distributions support batches of independent distributions of that type. The batch shape is determined by broadcasting together the parameters.

The shape of arguments to `__init__`, `cdf`, `log_cdf`, `prob`, and `log_prob` reflect this broadcasting, as does the return value of `sample` and `sample_n`.

`sample_n_shape = [n] + batch_shape + event_shape`, where `sample_n_shape` is the shape of the `Tensor` returned from `sample_n`, `n` is the number of samples, `batch_shape` defines how many independent distributions there are, and `event_shape` defines the shape of samples from each of those independent distributions. Samples are independent along the `batch_shape` dimensions, but not necessarily so along the `event_shape` dimensions (depending on the particulars of the underlying distribution).

Using the `Uniform` distribution as an example: #### Shapes

There are three important concepts associated with TensorFlow Distributions shapes: - Event shape describes the shape of a single draw from the distribution; it may be dependent across dimensions. For scalar distributions, the event shape is `[]`. For a 5-dimensional MultivariateNormal, the event shape is `[5]`. - Batch shape describes independent, not identically distributed draws, aka a "collection" or "bunch" of distributions. - Sample shape describes independent, identically distributed draws of batches from the distribution family.

The event shape and the batch shape are properties of a Distribution object, whereas the sample shape is associated with a specific call to `sample` or `log_prob`.

For detailed usage examples of TensorFlow Distributions shapes, see [this tutorial]( https://github.com/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Understanding_TensorFlow_Distributions_Shapes.ipynb)

#### Parameter values leading to undefined statistics or distributions.

Some distributions do not have well-defined statistics for all initialization parameter values. For example, the beta distribution is parameterized by positive real numbers `concentration1` and `concentration0`, and does not have well-defined mode if `concentration1 < 1` or `concentration0 < 1`.

The user is given the option of raising an exception or returning `NaN`. In all cases, an exception is raised if *invalid* parameters are passed, e.g.
Show Example
@util.AppendDocstring("Some other details.")
            def _log_prob(self, value):
             ... 

Methods

Properties

Public static methods

object param_shapes_dyn<TClass>(object sample_shape, ImplicitContainer<T> name)

Shapes of parameters given the desired shape of a call to `sample()`.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`.

Subclasses should override class method `_param_shapes`.
Parameters
object sample_shape
`Tensor` or python list/tuple. Desired shape of a call to `sample()`.
ImplicitContainer<T> name
name to prepend ops with.
Returns
object
`dict` of parameter name to `Tensor` shapes.

TClass param_shapes<TClass>(IEnumerable<Nullable<int>> sample_shape, string name)

Shapes of parameters given the desired shape of a call to `sample()`.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`.

Subclasses should override class method `_param_shapes`.
Parameters
IEnumerable<Nullable<int>> sample_shape
`Tensor` or python list/tuple. Desired shape of a call to `sample()`.
string name
name to prepend ops with.
Returns
TClass
`dict` of parameter name to `Tensor` shapes.

TClass param_shapes<TClass>(ValueTuple sample_shape, string name)

Shapes of parameters given the desired shape of a call to `sample()`.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`.

Subclasses should override class method `_param_shapes`.
Parameters
ValueTuple sample_shape
`Tensor` or python list/tuple. Desired shape of a call to `sample()`.
string name
name to prepend ops with.
Returns
TClass
`dict` of parameter name to `Tensor` shapes.

TClass param_shapes<TClass>(TensorShape sample_shape, string name)

Shapes of parameters given the desired shape of a call to `sample()`.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`.

Subclasses should override class method `_param_shapes`.
Parameters
TensorShape sample_shape
`Tensor` or python list/tuple. Desired shape of a call to `sample()`.
string name
name to prepend ops with.
Returns
TClass
`dict` of parameter name to `Tensor` shapes.

object param_static_shapes_dyn<TClass>(object sample_shape)

param_shapes with static (i.e. `TensorShape`) shapes.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`. Assumes that the sample's shape is known statically.

Subclasses should override class method `_param_shapes` to return constant-valued tensors when constant values are fed.
Parameters
object sample_shape
`TensorShape` or python list/tuple. Desired shape of a call to `sample()`.
Returns
object
`dict` of parameter name to `TensorShape`.

TClass param_static_shapes<TClass>(IEnumerable<int> sample_shape)

param_shapes with static (i.e. `TensorShape`) shapes.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`. Assumes that the sample's shape is known statically.

Subclasses should override class method `_param_shapes` to return constant-valued tensors when constant values are fed.
Parameters
IEnumerable<int> sample_shape
`TensorShape` or python list/tuple. Desired shape of a call to `sample()`.
Returns
TClass
`dict` of parameter name to `TensorShape`.

TClass param_static_shapes<TClass>(TensorShape sample_shape)

param_shapes with static (i.e. `TensorShape`) shapes.

This is a class method that describes what key/value arguments are required to instantiate the given `Distribution` so that a particular shape is returned for that instance's call to `sample()`. Assumes that the sample's shape is known statically.

Subclasses should override class method `_param_shapes` to return constant-valued tensors when constant values are fed.
Parameters
TensorShape sample_shape
`TensorShape` or python list/tuple. Desired shape of a call to `sample()`.
Returns
TClass
`dict` of parameter name to `TensorShape`.

Public properties

object allow_nan_stats get;

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.

object allow_nan_stats_dyn get;

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.

TensorShape batch_shape get;

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.

object batch_shape_dyn get;

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.

object dtype get;

The `DType` of `Tensor`s handled by this `Distribution`.

object dtype_dyn get;

The `DType` of `Tensor`s handled by this `Distribution`.

TensorShape event_shape get;

Shape of a single sample from a single batch as a `TensorShape`.

May be partially defined or unknown.

object event_shape_dyn get;

Shape of a single sample from a single batch as a `TensorShape`.

May be partially defined or unknown.

string name get;

Name prepended to all ops created by this `Distribution`.

object name_dyn get;

Name prepended to all ops created by this `Distribution`.

IDictionary<object, object> parameters get;

Dictionary of parameters used to instantiate this `Distribution`.

object parameters_dyn get;

Dictionary of parameters used to instantiate this `Distribution`.

object PythonObject get;

object reparameterization_type get;

Describes how samples from the distribution are reparameterized.

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

object reparameterization_type_dyn get;

Describes how samples from the distribution are reparameterized.

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

object validate_args get;

Python `bool` indicating possibly expensive checks are enabled.

object validate_args_dyn get;

Python `bool` indicating possibly expensive checks are enabled.