mindspore.nn.probability.distribution.StudentT

class mindspore.nn.probability.distribution.StudentT(df=None, mean=None, sd=None, seed=None, dtype=mstype.float32, name='StudentT')[source]

StudentT distribution. A StudentT distribution is a continuous distribution with the range \([-\inf, \inf)\) and the probability density function:

\[f(x, \nu, \mu, \sigma) = (1 + y^2 / \nu)^{(-0.5*(\nu + 1))} / Z\]
where \(y = (x-\mu)/\sigma\), \(Z = abs(\sigma)*\sqrt(\nu * \pi)*\Gamma(0.5 * \nu)/\Gamma(0.5*(\nu + 1))\),

\(\nu, \mu, \sigma\) are the degrees of freedom , mean and scale of the laplace distribution respectively.

Parameters

Note

  • df must be greater than zero.

  • sd must be greater than zero.

  • dist_spec_args are mean and sd.

  • dtype must be a float type because StudentT distributions are continuous.

Raises
Supported Platforms:

CPU

Examples

>>> import mindspore
>>> import mindspore.nn as nn
>>> import mindspore.nn.probability.distribution as msd
>>> from mindspore import Tensor
>>> # To initialize a StudentT distribution of the df 2.0, the mean 3.0 and the standard deviation 4.0.
>>> n1 = msd.StudentT(2.0, 3.0, 4.0, dtype=mindspore.float32)
>>> # A StudentT distribution can be initialized without arguments.
>>> # In this case, `df`, `mean` and `sd` must be passed in through arguments.
>>> n2 = msd.StudentT(dtype=mindspore.float32)
>>> # Here are some tensors used below for testing
>>> value = Tensor([1.0, 2.0, 3.0], dtype=mindspore.float32)
>>> df_a = Tensor([2.0], dtype=mindspore.float32)
>>> mean_a = Tensor([2.0], dtype=mindspore.float32)
>>> sd_a = Tensor([2.0, 2.0, 2.0], dtype=mindspore.float32)
>>> df_b = Tensor([1.0], dtype=mindspore.float32)
>>> mean_b = Tensor([1.0], dtype=mindspore.float32)
>>> sd_b = Tensor([1.0, 1.5, 2.0], dtype=mindspore.float32)
>>> ans = n1.log_prob(value)
>>> print(ans.shape)
(3,)
>>> # Evaluate with respect to the distribution b.
>>> ans = n1.log_prob(value, df_b, mean_b, sd_b)
>>> print(ans.shape)
(3,)
>>> # `mean` and `sd` must be passed in during function calls
>>> ans = n2.log_prob(value, df_a, mean_a, sd_a)
>>> print(ans.shape)
(3,)
log_prob(value, df=None, mean=None, sd=None)

the log value of the probability.

Parameters

  • value (Tensor) - the value to compute.

  • df (Tensor) - the degrees of freedom of the distribution. Default: None.

  • mean (Tensor) - the mean of the distribution. Default: None.

  • sd (Tensor) - the standard deviation of the distribution. Default: None.

Returns

Tensor, the log value of the probability.