LostTech.TensorFlow : API Documentation

Type Dirichlet

Namespace tensorflow.distributions

Parent Distribution

Interfaces IDirichlet

Dirichlet distribution.

The Dirichlet distribution is defined over the [`(k-1)`-simplex](https://en.wikipedia.org/wiki/Simplex) using a positive, length-`k` vector `concentration` (`k > 1`). The Dirichlet is identically the Beta distribution when `k = 2`.

#### Mathematical Details

The Dirichlet is a distribution over the open `(k-1)`-simplex, i.e.,

```none S^{k-1} = { (x_0,..., x_{k-1}) in R^k : sum_j x_j = 1 and all_j x_j > 0 }. ```

The probability density function (pdf) is,

```none pdf(x; alpha) = prod_j x_j**(alpha_j - 1) / Z Z = prod_j Gamma(alpha_j) / Gamma(sum_j alpha_j) ```

where:

* `x in S^{k-1}`, i.e., the `(k-1)`-simplex, * `concentration = alpha = [alpha_0,..., alpha_{k-1}]`, `alpha_j > 0`, * `Z` is the normalization constant aka the [multivariate beta function]( https://en.wikipedia.org/wiki/Beta_function#Multivariate_beta_function), and, * `Gamma` is the [gamma function]( https://en.wikipedia.org/wiki/Gamma_function).

The `concentration` represents mean total counts of class occurrence, i.e.,

```none concentration = alpha = mean * total_concentration ```

where `mean` in `S^{k-1}` and `total_concentration` is a positive real number representing a mean total count.

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

Warning: Some components of 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 single trivariate Dirichlet, with the 3rd class being three times # more frequent than the first. I.e., batch_shape=[], event_shape=[3]. alpha = [1., 2, 3] dist = tfd.Dirichlet(alpha)

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

# x has one sample, one batch, three classes: x = [.2,.3,.5] # shape: [3] dist.prob(x) # shape: []

# x has two samples from one batch: x = [[.1,.4,.5], [.2,.3,.5]] dist.prob(x) # shape: [2]

# alpha will be broadcast to shape [5, 7, 3] to match x. x = [[...]] # shape: [5, 7, 3] dist.prob(x) # shape: [5, 7]

Properties

Public properties

object allow_nan_stats get;

object allow_nan_stats_dyn get;

TensorShape batch_shape get;

object batch_shape_dyn get;

object concentration get;

Concentration parameter; expected counts for that coordinate.

object concentration_dyn get;

Concentration parameter; expected counts for that coordinate.

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 last dim of concentration parameter.

object total_concentration_dyn get;

Sum of last dim of concentration parameter.

object validate_args get;

object validate_args_dyn get;