StudentT

class paddle.distribution. StudentT ( df: float | Tensor, loc: float | Tensor, scale: float | Tensor, name: str | None = None ) [source]

The StudentT distribution with parameters: df, loc, scale.

In probability theory and statistics, the StudentT distribution is one of the basic continuous probability distributions defined on the real number set.

The probability density function (pdf) is

\[pdf(x; \nu, \mu, \sigma) = \frac{\Gamma[(\nu+1)/2]}{\sigma\sqrt{\nu\pi}\Gamma(\nu/2)[1+(\frac{x-\mu}{\sigma})^2/\nu]^{(1+\nu)/2}}\]

In the above equation:

  • \(df = \nu\): is the degree of freedom.

  • \(loc = \mu\): is the center parameter.

  • \(scale = \sigma\): is the scale parameter.

  • \(\Gamma(\cdot)\): is the gamma function.

Parameters
  • df (float|Tensor) – The degree of freedom of the distribution, which should be non-negative. If the input data type is float, the data type of df will be converted to a 1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.

  • loc (float|Tensor) – The center of the distribution. If the input data type is float, the data type of loc will be converted to a 1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.

  • scale (float|Tensor) – The scale of the distribution, which should be non-negative. If the input data type is float, the data type of scale will be converted to a 1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Examples

>>> import paddle
>>> from paddle.distribution import StudentT
>>> paddle.set_device('cpu')
>>> paddle.seed(100)
>>> dist = StudentT(df=10.0, loc=0.0, scale=1.0)
>>> dist.sample([3])
Tensor(shape=[3, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-2.07709980],
 [ 0.27981189],
 [ 0.00881413]])

>>> dist2 = StudentT(df=paddle.to_tensor([10.0, 5.0]), loc=paddle.to_tensor([0.0, 0.0]), scale=paddle.to_tensor([1.0, 2.0]))
>>> value_tensor = paddle.to_tensor([0.8], dtype="float32")
>>> lp = dist2.log_prob(value_tensor)
>>> print(lp)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[-1.28509235, -1.75626254])

>>> p = dist2.prob(value_tensor)
>>> print(p)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.27662504, 0.17268908])

>>> entropy = dist2.entropy()
>>> print(entropy)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[1.52126312, 2.32064891])
property mean : Tensor

Mean of StudentT distribution.

Returns

mean value.

Return type

Tensor

property variance : Tensor

Variance of StudentT distribution.

Returns

variance value.

Return type

Tensor

property batch_shape : Sequence[int]

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

property event_shape : Sequence[int]

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

kl_divergence ( other: Distribution ) Tensor [source]

kl_divergence

The KL-divergence between self distributions and other.

probs ( value: Tensor ) Tensor

probs

Probability density/mass function.

Note

This method will be deprecated in the future, please use prob instead.

rsample ( shape: Sequence[int] = [] ) Tensor

rsample

reparameterized sample

sample ( shape: Sequence[int] = [] ) Tensor

sample

Generate StudentT samples of the specified shape. The final shape would be shape+batch_shape .

Parameters

shape (Sequence[int], optional) – Prepended shape of the generated samples.

Returns

Sampled data with shape sample_shape + batch_shape.

Return type

Tensor

entropy ( ) Tensor

entropy

Shannon entropy in nats.

The entropy is

\[H = \log(\frac{\Gamma(\nu/2)\Gamma(1/2) \sigma \sqrt{\nu}}{\Gamma[(1+\nu)/2]}) + \frac{(1+\nu)}{2} \cdot \{\psi[(1+\nu)/2] - \psi(\nu/2)\}\]

In the above equation:

  • \(\nu\): is the degree of freedom.

  • \(\Gamma()\): is the gamma function.

  • \(\psi()\): is the digamma function.

Returns

Shannon entropy of StudentT distribution. The data type is the same as df.

Return type

Tensor

log_prob ( value: Tensor ) Tensor

log_prob

Log probability density function.

Parameters

value (Tensor) – The input tensor.

Returns

log probability density. The data type is the same as df.

Return type

Tensor

prob ( value: Tensor ) Tensor

prob

Probability density function.

Parameters

value (Tensor) – The input tensor.

Returns

probability density. The data type is the same as df.

Return type

Tensor