gluonts.model.tpp.distribution package

class gluonts.model.tpp.distribution.TPPDistribution[source]

Bases: gluonts.mx.distribution.distribution.Distribution

Distribution used in temporal point processes.

This class must implement new methods log_intensity, log_survival that are necessary for computing log-likelihood of TPP realizations. Also, sample_conditional is necessary for sampling TPPs.

arg_names = None
cdf(y: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Returns the value of the cumulative distribution function evaluated at x

log_intensity(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the intensity (a.k.a. hazard) function.

The intensity is defined as \(\lambda(x) = p(x) / S(x)\).

log_prob(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the log-density of the distribution at x.

Parameters

x – Tensor of shape (*batch_shape, *event_shape).

Returns

Tensor of shape batch_shape containing the log-density of the distribution for each event in x.

Return type

Tensor

log_survival(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the survival function log S(x) = log(1 - CDF(x)).

sample(num_samples=None, dtype=<class 'numpy.float32'>, lower_bound: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the distribution.

If num_samples is given the first dimension of the output will be num_samples.

Parameters
  • num_samples – Number of samples to to be drawn.

  • dtype – Data-type of the samples.

Returns

A tensor containing samples. This has shape (*batch_shape, *eval_shape) if num_samples = None and (num_samples, *batch_shape, *eval_shape) otherwise.

Return type

Tensor

class gluonts.model.tpp.distribution.TPPDistributionOutput[source]

Bases: gluonts.mx.distribution.distribution_output.DistributionOutput

Class to construct a distribution given the output of a network.

Two differences compared to the base class DistributionOutput: 1. Location param cannot be specified (all distributions must start at 0). 2. The return type is either TPPDistribution or TPPTransformedDistribution.

distr_cls: type = None
distribution(distr_args, loc=None, scale: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → Union[gluonts.model.tpp.distribution.base.TPPDistribution, gluonts.model.tpp.distribution.base.TPPTransformedDistribution][source]

Construct the associated distribution, given the collection of constructor arguments and, optionally, a scale tensor.

Parameters
  • distr_args – Constructor arguments for the underlying TPPDistribution type.

  • loc – Location parameter, specified here for compatibility with the superclass. Should never be specified.

  • scale – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.

class gluonts.model.tpp.distribution.TPPTransformedDistribution(base_distribution: gluonts.model.tpp.distribution.base.TPPDistribution, transforms: List[gluonts.mx.distribution.bijection.Bijection])[source]

Bases: gluonts.mx.distribution.transformed_distribution.TransformedDistribution

TransformedDistribution used in temporal point processes.

This class must implement new methods log_intensity, log_survival that are necessary for computing log-likelihood of TPP realizations. Also, sample_conditional is necessary for sampling TPPs.

Additionally, the sequence of transformations passed to the constructor must be increasing.

base_distribution: TPPDistribution = None
cdf(y: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Returns the value of the cumulative distribution function evaluated at x

log_intensity(y: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the intensity (a.k.a. hazard) function.

The intensity is defined as \(\lambda(y) = p(y) / S(y)\).

log_survival(y: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the survival function \(\log S(y) = \log(1 - CDF(y))\).

sample(num_samples=None, dtype=<class 'numpy.float32'>, lower_bound: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the distribution.

Parameters
  • num_samples – Number of samples to generate.

  • dtype – Data type of the generated samples.

  • lower_bound – If None, generate samples as usual. If lower_bound is provided, all generated samples will be larger than the specified values. That is, we sample from p(x | x > lower_bound). Shape: (*batch_size)

Returns

Transformed samples drawn from the base distribution. Shape: (num_samples, *batch_size)

Return type

x

class gluonts.model.tpp.distribution.Loglogistic(mu: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], sigma: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol])[source]

Bases: gluonts.model.tpp.distribution.base.TPPDistribution

Log-logistic distribution.

A very heavy-tailed distribution over positive real numbers. https://en.wikipedia.org/wiki/Log-logistic_distribution

Drawing \(x \sim \operatorname{Loglogistic}(\mu, \sigma)\) is equivalent to:

\[\begin{split}y &\sim \operatorname{Logistic}(\mu, \sigma)\\ x &= \exp(y)\end{split}\]
arg_names = None
property batch_shape

Layout of the set of events contemplated by the distribution.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape, and computing log_prob (or loss more in general) on such sample will yield a tensor of shape batch_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

property event_dim

Number of event dimensions, i.e., length of the event_shape tuple.

This is 0 for distributions over scalars, 1 over vectors, 2 over matrices, and so on.

property event_shape

Shape of each individual event contemplated by the distribution.

For example, distributions over scalars have event_shape = (), over vectors have event_shape = (d, ) where d is the length of the vectors, over matrices have event_shape = (d1, d2), and so on.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

is_reparametrizable = True
log_intensity(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the intensity (a.k.a. hazard) function.

The intensity is defined as \(\lambda(x) = p(x) / S(x)\).

We define \(z = (\log(x) - \mu) / \sigma\) and obtain the intensity as \(\lambda(x) = sigmoid(z) / (\sigma * \log(x))\), or equivalently \(\log \lambda(x) = z - \log(1 + \exp(z)) - \log(\sigma) - \log(x)\).

log_prob(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the log-density of the distribution at x.

Parameters

x – Tensor of shape (*batch_shape, *event_shape).

Returns

Tensor of shape batch_shape containing the log-density of the distribution for each event in x.

Return type

Tensor

log_survival(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the survival function \(\log S(x) = \log(1 - CDF(x))\).

We define \(z = (\log(x) - \mu) / \sigma\) and obtain the survival function as \(S(x) = sigmoid(-z)\), or equivalently \(\log S(x) = -\log(1 + \exp(z))\).

property mean

Tensor containing the mean of the distribution.

sample(num_samples=None, dtype=<class 'numpy.float32'>, lower_bound: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the distribution.

We generate samples as \(u \sim Uniform(0, 1), x = S^{-1}(u)\), where \(S^{-1}\) is the inverse of the survival function \(S(x) = 1 - CDF(x)\).

Parameters
  • num_samples – Number of samples to generate.

  • dtype – Data type of the generated samples.

  • lower_bound – If None, generate samples as usual. If lower_bound is provided, all generated samples will be larger than the specified values. That is, we sample from p(x | x > lower_bound). Shape: (*batch_size)

Returns

Sampled inter-event times. Shape: (num_samples, *batch_size)

Return type

x

class gluonts.model.tpp.distribution.LoglogisticOutput[source]

Bases: gluonts.model.tpp.distribution.base.TPPDistributionOutput

args_dim: Dict[str, int] = {'mu': 1, 'sigma': 1}
distr_cls

alias of Loglogistic

classmethod domain_map(F, mu, sigma)[source]

Maps raw tensors to valid arguments for constructing a log-logistic distribution.

Parameters
  • F – MXNet backend.

  • mu – Mean of the underlying logistic distribution. Shape (*batch_shape, 1)

  • sigma – Scale of the underlying logistic distribution. Shape (*batch_shape, 1)

Returns

Two squeezed tensors of shape (*batch_shape). The sigma parameter is strictly positive.

Return type

Tuple[Tensor, Tensor]

property event_shape

Shape of each individual event contemplated by the distributions that this object constructs.

class gluonts.model.tpp.distribution.Weibull(rate: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], shape: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol])[source]

Bases: gluonts.model.tpp.distribution.base.TPPDistribution

Weibull distribution.

We use the parametrization of the Weibull distribution using the rate parameter \(b > 0\) and the shape parameter \(k > 0\). The PDF is \(p(x) = b * k * x^{(k - 1)} * \exp(-b * x^k)\). An alternative parametrization is often used (e.g. on Wikipedia), where we use the scale parameter \(\lambda > 0\) and the shape parameter \(k > 0\), and \(\lambda = b^{-1/k}\).

arg_names = None
property batch_shape

Layout of the set of events contemplated by the distribution.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape, and computing log_prob (or loss more in general) on such sample will yield a tensor of shape batch_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

property event_dim

Number of event dimensions, i.e., length of the event_shape tuple.

This is 0 for distributions over scalars, 1 over vectors, 2 over matrices, and so on.

property event_shape

Shape of each individual event contemplated by the distribution.

For example, distributions over scalars have event_shape = (), over vectors have event_shape = (d, ) where d is the length of the vectors, over matrices have event_shape = (d1, d2), and so on.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

is_reparametrizable = True
log_intensity(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the intensity (a.k.a. hazard) function.

The intensity is defined as \(\lambda(x) = p(x) / S(x)\).

The intensity of the Weibull distribution is \(\lambda(x) = b * k * x^{k - 1}\).

log_prob(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the log-density of the distribution at x.

Parameters

x – Tensor of shape (*batch_shape, *event_shape).

Returns

Tensor of shape batch_shape containing the log-density of the distribution for each event in x.

Return type

Tensor

log_survival(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Logarithm of the survival function \(\log S(x) = \log(1 - CDF(x))\).

The survival function of the Weibull distribution is \(S(x) = \exp(-b * x^k)\).

property mean

Tensor containing the mean of the distribution.

sample(num_samples=None, dtype=<class 'numpy.float32'>, lower_bound: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the distribution.

We generate samples as \(u \sim Uniform(0, 1), x = S^{-1}(u)\), where \(S^{-1}\) is the inverse of the survival function \(S(x) = 1 - CDF(x)\).

Parameters
  • num_samples – Number of samples to generate.

  • dtype – Data type of the generated samples.

  • lower_bound – If None, generate samples as usual. If lower_bound is provided, all generated samples will be larger than the specified values. That is, we sample from p(x | x > lower_bound). Shape: (*batch_size)

Returns

Sampled inter-event times. Shape: (num_samples, *batch_size)

Return type

x

class gluonts.model.tpp.distribution.WeibullOutput[source]

Bases: gluonts.model.tpp.distribution.base.TPPDistributionOutput

args_dim: Dict[str, int] = {'rate': 1, 'shape': 1}
distr_cls

alias of Weibull

classmethod domain_map(F, rate, shape)[source]

Maps raw tensors to valid arguments for constructing a Weibull distribution.

Parameters
  • F – MXNet backend.

  • rate – Rate (inverse scale) parameter of the Weibull distribution. Shape (*batch_shape, 1)

  • shape – Shape parameter of the Weibull distribution. Shape (*batch_shape, 1)

Returns

Two squeezed tensors of shape (*batch_shape). Both tensors are strictly positive.

Return type

Tuple[Tensor, Tensor]

property event_shape

Shape of each individual event contemplated by the distributions that this object constructs.

Submodules