[docs]classGamma(ExponentialFamily):r""" Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`. Example:: >>> # xdoctest: +IGNORE_WANT("non-deterinistic") >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0])) >>> m.sample() # Gamma distributed with concentration=1 and rate=1 tensor([ 0.1046]) Args: concentration (float or Tensor): shape parameter of the distribution (often referred to as alpha) rate (float or Tensor): rate = 1 / scale of the distribution (often referred to as beta) """arg_constraints={"concentration":constraints.positive,"rate":constraints.positive,}support=constraints.nonnegativehas_rsample=True_mean_carrier_measure=0@propertydefmean(self):returnself.concentration/self.rate@propertydefmode(self):return((self.concentration-1)/self.rate).clamp(min=0)@propertydefvariance(self):returnself.concentration/self.rate.pow(2)def__init__(self,concentration,rate,validate_args=None):self.concentration,self.rate=broadcast_all(concentration,rate)ifisinstance(concentration,Number)andisinstance(rate,Number):batch_shape=torch.Size()else:batch_shape=self.concentration.size()super().__init__(batch_shape,validate_args=validate_args)
[docs]defrsample(self,sample_shape=torch.Size()):shape=self._extended_shape(sample_shape)value=_standard_gamma(self.concentration.expand(shape))/self.rate.expand(shape)value.detach().clamp_(min=torch.finfo(value.dtype).tiny)# do not record in autograd graphreturnvalue
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.