[docs]classGumbel(TransformedDistribution):r""" Samples from a Gumbel Distribution. Examples:: >>> # xdoctest: +IGNORE_WANT("non-deterministic") >>> m = Gumbel(torch.tensor([1.0]), torch.tensor([2.0])) >>> m.sample() # sample from Gumbel distribution with loc=1, scale=2 tensor([ 1.0124]) Args: loc (float or Tensor): Location parameter of the distribution scale (float or Tensor): Scale parameter of the distribution """arg_constraints={"loc":constraints.real,"scale":constraints.positive}support=constraints.realdef__init__(self,loc,scale,validate_args=None):self.loc,self.scale=broadcast_all(loc,scale)finfo=torch.finfo(self.loc.dtype)ifisinstance(loc,Number)andisinstance(scale,Number):base_dist=Uniform(finfo.tiny,1-finfo.eps,validate_args=validate_args)else:base_dist=Uniform(torch.full_like(self.loc,finfo.tiny),torch.full_like(self.loc,1-finfo.eps),validate_args=validate_args,)transforms=[ExpTransform().inv,AffineTransform(loc=0,scale=-torch.ones_like(self.scale)),ExpTransform().inv,AffineTransform(loc=loc,scale=-self.scale),]super().__init__(base_dist,transforms,validate_args=validate_args)
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.