[docs]classNormal(ExponentialFamily):r""" Creates a normal (also called Gaussian) distribution parameterized by :attr:`loc` and :attr:`scale`. Example:: >>> # xdoctest: +IGNORE_WANT("non-deterinistic") >>> m = Normal(torch.tensor([0.0]), torch.tensor([1.0])) >>> m.sample() # normally distributed with loc=0 and scale=1 tensor([ 0.1046]) Args: loc (float or Tensor): mean of the distribution (often referred to as mu) scale (float or Tensor): standard deviation of the distribution (often referred to as sigma) """arg_constraints={"loc":constraints.real,"scale":constraints.positive}support=constraints.realhas_rsample=True_mean_carrier_measure=0@propertydefmean(self):returnself.loc@propertydefmode(self):returnself.loc@propertydefstddev(self):returnself.scale@propertydefvariance(self):returnself.stddev.pow(2)def__init__(self,loc,scale,validate_args=None):self.loc,self.scale=broadcast_all(loc,scale)ifisinstance(loc,Number)andisinstance(scale,Number):batch_shape=torch.Size()else:batch_shape=self.loc.size()super().__init__(batch_shape,validate_args=validate_args)
[docs]deflog_prob(self,value):ifself._validate_args:self._validate_sample(value)# compute the variancevar=self.scale**2log_scale=(math.log(self.scale)ifisinstance(self.scale,Real)elseself.scale.log())return(-((value-self.loc)**2)/(2*var)-log_scale-math.log(math.sqrt(2*math.pi)))
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.