LostTech.TensorFlow : API Documentation

Type Beta

Namespace tensorflow.distributions

Parent Distribution

Interfaces IBeta

Beta distribution.

The Beta distribution is defined over the `(0, 1)` interval using parameters `concentration1` (aka "alpha") and `concentration0` (aka "beta").

#### Mathematical Details

The probability density function (pdf) is,

```none pdf(x; alpha, beta) = x**(alpha - 1) (1 - x)**(beta - 1) / Z Z = Gamma(alpha) Gamma(beta) / Gamma(alpha + beta) ```

where:

* `concentration1 = alpha`, * `concentration0 = beta`, * `Z` is the normalization constant, and, * `Gamma` is the [gamma function]( https://en.wikipedia.org/wiki/Gamma_function).

The concentration parameters represent mean total counts of a `1` or a `0`, i.e.,

```none concentration1 = alpha = mean * total_concentration concentration0 = beta = (1. - mean) * total_concentration ```

where `mean` in `(0, 1)` and `total_concentration` is a positive real number representing a mean `total_count = concentration1 + concentration0`.

Distribution parameters are automatically broadcast in all functions; see examples for details.

Warning: The samples can be zero due to finite precision. This happens more often when some of the concentrations are very small. Make sure to round the samples to `np.finfo(dtype).tiny` before computing the density.

Samples of this distribution are reparameterized (pathwise differentiable). The derivatives are computed using the approach described in the paper

[Michael Figurnov, Shakir Mohamed, Andriy Mnih. Implicit Reparameterization Gradients, 2018](https://arxiv.org/abs/1805.08498)

#### Examples

Compute the gradients of samples w.r.t. the parameters:
Show Example
import tensorflow_probability as tfp
            tfd = tfp.distributions 

# Create a batch of three Beta distributions. alpha = [1, 2, 3] beta = [1, 2, 3] dist = tfd.Beta(alpha, beta)

dist.sample([4, 5]) # Shape [4, 5, 3]

# `x` has three batch entries, each with two samples. x = [[.1,.4,.5], [.2,.3,.5]] # Calculate the probability of each pair of samples under the corresponding # distribution in `dist`. dist.prob(x) # Shape [2, 3]

Methods

Properties

Public instance methods

Tensor covariance(string name)

Covariance.

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

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

```none 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.,

```none 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.
Parameters
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor

object covariance_dyn(ImplicitContainer<T> name)

Covariance.

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

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

```none 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.,

```none 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.
Parameters
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

object cross_entropy(object other, string name)

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)`, (Shanon) cross entropy is defined as:

```none 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`.
Parameters
object other
`tfp.distributions.Distribution` instance.
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object cross_entropy_dyn(object other, ImplicitContainer<T> name)

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)`, (Shanon) cross entropy is defined as:

```none 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`.
Parameters
object other
`tfp.distributions.Distribution` instance.
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

object entropy(string name)

Shannon entropy in nats.

object entropy_dyn(ImplicitContainer<T> name)

Shannon entropy in nats.

object kl_divergence(object other, string name)

Computes the Kullback--Leibler divergence.

Denote this distribution (`self`) by `p` and the `other` distribution by `q`. Assuming `p, q` are absolutely continuous with respect to reference measure `r`, the KL divergence is defined as:

```none KL[p, q] = E_p[log(p(X)/q(X))] = -int_F p(x) log q(x) dr(x) + int_F p(x) log p(x) dr(x) = H[p, q] - H[p] ```

where `F` denotes the support of the random variable `X ~ p`, `H[.,.]` denotes (Shanon) cross entropy, and `H[.]` denotes (Shanon) entropy.
Parameters
object other
`tfp.distributions.Distribution` instance.
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object kl_divergence_dyn(object other, ImplicitContainer<T> name)

Computes the Kullback--Leibler divergence.

Denote this distribution (`self`) by `p` and the `other` distribution by `q`. Assuming `p, q` are absolutely continuous with respect to reference measure `r`, the KL divergence is defined as:

```none KL[p, q] = E_p[log(p(X)/q(X))] = -int_F p(x) log q(x) dr(x) + int_F p(x) log p(x) dr(x) = H[p, q] - H[p] ```

where `F` denotes the support of the random variable `X ~ p`, `H[.,.]` denotes (Shanon) cross entropy, and `H[.]` denotes (Shanon) entropy.
Parameters
object other
`tfp.distributions.Distribution` instance.
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

Tensor log_survival_function(IEnumerable<object> value, string name)

Log survival function.

Given random variable `X`, the survival function is defined:

```none log_survival_function(x) = Log[ P[X > x] ] = Log[ 1 - P[X <= x] ] = Log[ 1 - cdf(x) ] ```

Typically, different numerical approximations can be used for the log survival function, which are more accurate than `1 - cdf(x)` when `x >> 1`.
Parameters
IEnumerable<object> value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

Tensor log_survival_function(IGraphNodeBase value, string name)

Log survival function.

Given random variable `X`, the survival function is defined:

```none log_survival_function(x) = Log[ P[X > x] ] = Log[ 1 - P[X <= x] ] = Log[ 1 - cdf(x) ] ```

Typically, different numerical approximations can be used for the log survival function, which are more accurate than `1 - cdf(x)` when `x >> 1`.
Parameters
IGraphNodeBase value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

object log_survival_function_dyn(object value, ImplicitContainer<T> name)

Log survival function.

Given random variable `X`, the survival function is defined:

```none log_survival_function(x) = Log[ P[X > x] ] = Log[ 1 - P[X <= x] ] = Log[ 1 - cdf(x) ] ```

Typically, different numerical approximations can be used for the log survival function, which are more accurate than `1 - cdf(x)` when `x >> 1`.
Parameters
object value
`float` or `double` `Tensor`.
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

Tensor mean(string name)

Mean.

object mean_dyn(ImplicitContainer<T> name)

Mean.

object mode(string name)

Mode.

object mode_dyn(ImplicitContainer<T> name)

Mode.

object quantile(IGraphNodeBase value, string name)

Quantile function. Aka "inverse cdf" or "percent point function".

Given random variable `X` and `p in [0, 1]`, the `quantile` is:

```none quantile(p) := x such that P[X <= x] == p ```
Parameters
IGraphNodeBase value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object quantile(IEnumerable<double> value, string name)

Quantile function. Aka "inverse cdf" or "percent point function".

Given random variable `X` and `p in [0, 1]`, the `quantile` is:

```none quantile(p) := x such that P[X <= x] == p ```
Parameters
IEnumerable<double> value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object quantile(double value, string name)

Quantile function. Aka "inverse cdf" or "percent point function".

Given random variable `X` and `p in [0, 1]`, the `quantile` is:

```none quantile(p) := x such that P[X <= x] == p ```
Parameters
double value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object quantile_dyn(object value, ImplicitContainer<T> name)

Quantile function. Aka "inverse cdf" or "percent point function".

Given random variable `X` and `p in [0, 1]`, the `quantile` is:

```none quantile(p) := x such that P[X <= x] == p ```
Parameters
object value
`float` or `double` `Tensor`.
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

object stddev(string name)

Standard deviation.

Standard deviation is defined as,

```none stddev = E[(X - E[X])**2]**0.5 ```

where `X` is the random variable associated with this distribution, `E` denotes expectation, and `stddev.shape = batch_shape + event_shape`.
Parameters
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object stddev_dyn(ImplicitContainer<T> name)

Standard deviation.

Standard deviation is defined as,

```none stddev = E[(X - E[X])**2]**0.5 ```

where `X` is the random variable associated with this distribution, `E` denotes expectation, and `stddev.shape = batch_shape + event_shape`.
Parameters
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

Tensor survival_function(IEnumerable<object> value, string name)

Survival function.

Given random variable `X`, the survival function is defined:

```none survival_function(x) = P[X > x] = 1 - P[X <= x] = 1 - cdf(x). ```
Parameters
IEnumerable<object> value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

Tensor survival_function(ndarray value, string name)

Survival function.

Given random variable `X`, the survival function is defined:

```none survival_function(x) = P[X > x] = 1 - P[X <= x] = 1 - cdf(x). ```
Parameters
ndarray value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

Tensor survival_function(IGraphNodeBase value, string name)

Survival function.

Given random variable `X`, the survival function is defined:

```none survival_function(x) = P[X > x] = 1 - P[X <= x] = 1 - cdf(x). ```
Parameters
IGraphNodeBase value
`float` or `double` `Tensor`.
string name
Python `str` prepended to names of ops created by this function.
Returns
Tensor
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

object survival_function_dyn(object value, ImplicitContainer<T> name)

Survival function.

Given random variable `X`, the survival function is defined:

```none survival_function(x) = P[X > x] = 1 - P[X <= x] = 1 - cdf(x). ```
Parameters
object value
`float` or `double` `Tensor`.
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object
`Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.

object variance(string name)

Variance.

Variance is defined as,

```none Var = E[(X - E[X])**2] ```

where `X` is the random variable associated with this distribution, `E` denotes expectation, and `Var.shape = batch_shape + event_shape`.
Parameters
string name
Python `str` prepended to names of ops created by this function.
Returns
object

object variance_dyn(ImplicitContainer<T> name)

Variance.

Variance is defined as,

```none Var = E[(X - E[X])**2] ```

where `X` is the random variable associated with this distribution, `E` denotes expectation, and `Var.shape = batch_shape + event_shape`.
Parameters
ImplicitContainer<T> name
Python `str` prepended to names of ops created by this function.
Returns
object

Public properties

object allow_nan_stats get;

object allow_nan_stats_dyn get;

TensorShape batch_shape get;

object batch_shape_dyn get;

Tensor concentration0 get;

Concentration parameter associated with a `0` outcome.

object concentration0_dyn get;

Concentration parameter associated with a `0` outcome.

Tensor concentration1 get;

Concentration parameter associated with a `1` outcome.

object concentration1_dyn get;

Concentration parameter associated with a `1` outcome.

object dtype get;

object dtype_dyn get;

TensorShape event_shape get;

object event_shape_dyn get;

string name get;

object name_dyn get;

IDictionary<object, object> parameters get;

object parameters_dyn get;

object PythonObject get;

object reparameterization_type get;

object reparameterization_type_dyn get;

object total_concentration get;

Sum of concentration parameters.

object total_concentration_dyn get;

Sum of concentration parameters.

object validate_args get;

object validate_args_dyn get;