pytorch

Форк
0
33 строки · 974.0 Байт
1
from torch.distributions import constraints
2
from torch.distributions.gamma import Gamma
3

4
__all__ = ["Chi2"]
5

6

7
class Chi2(Gamma):
8
    r"""
9
    Creates a Chi-squared distribution parameterized by shape parameter :attr:`df`.
10
    This is exactly equivalent to ``Gamma(alpha=0.5*df, beta=0.5)``
11

12
    Example::
13

14
        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
15
        >>> m = Chi2(torch.tensor([1.0]))
16
        >>> m.sample()  # Chi2 distributed with shape df=1
17
        tensor([ 0.1046])
18

19
    Args:
20
        df (float or Tensor): shape parameter of the distribution
21
    """
22
    arg_constraints = {"df": constraints.positive}
23

24
    def __init__(self, df, validate_args=None):
25
        super().__init__(0.5 * df, 0.5, validate_args=validate_args)
26

27
    def expand(self, batch_shape, _instance=None):
28
        new = self._get_checked_instance(Chi2, _instance)
29
        return super().expand(batch_shape, new)
30

31
    @property
32
    def df(self):
33
        return self.concentration * 2
34

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.