Caffe2 - Python API
A deep learning, cross platform ML framework
chi2.py
1 import torch
2 from torch.distributions import constraints
3 from torch.distributions.gamma import Gamma
4 
5 
6 class Chi2(Gamma):
7  r"""
8  Creates a Chi2 distribution parameterized by shape parameter :attr:`df`.
9  This is exactly equivalent to ``Gamma(alpha=0.5*df, beta=0.5)``
10 
11  Example::
12 
13  >>> m = Chi2(torch.tensor([1.0]))
14  >>> m.sample() # Chi2 distributed with shape df=1
15  tensor([ 0.1046])
16 
17  Args:
18  df (float or Tensor): shape parameter of the distribution
19  """
20  arg_constraints = {'df': constraints.positive}
21 
22  def __init__(self, df, validate_args=None):
23  super(Chi2, self).__init__(0.5 * df, 0.5, validate_args=validate_args)
24 
25  def expand(self, batch_shape, _instance=None):
26  new = self._get_checked_instance(Chi2, _instance)
27  return super(Chi2, self).expand(batch_shape, new)
28 
29  @property
30  def df(self):
31  return self.concentration * 2
def _get_checked_instance(self, cls, _instance=None)