[docs]classBernoulli(ExponentialFamily):r""" Creates a Bernoulli distribution parameterized by :attr:`probs` or :attr:`logits` (but not both). Samples are binary (0 or 1). They take the value `1` with probability `p` and `0` with probability `1 - p`. Example:: >>> # xdoctest: +IGNORE_WANT("non-deterinistic") >>> m = Bernoulli(torch.tensor([0.3])) >>> m.sample() # 30% chance 1; 70% chance 0 tensor([ 0.]) Args: probs (Number, Tensor): the probability of sampling `1` logits (Number, Tensor): the log-odds of sampling `1` """arg_constraints={"probs":constraints.unit_interval,"logits":constraints.real}support=constraints.booleanhas_enumerate_support=True_mean_carrier_measure=0def__init__(self,probs=None,logits=None,validate_args=None):if(probsisNone)==(logitsisNone):raiseValueError("Either `probs` or `logits` must be specified, but not both.")ifprobsisnotNone:is_scalar=isinstance(probs,Number)(self.probs,)=broadcast_all(probs)else:is_scalar=isinstance(logits,Number)(self.logits,)=broadcast_all(logits)self._param=self.probsifprobsisnotNoneelseself.logitsifis_scalar:batch_shape=torch.Size()else:batch_shape=self._param.size()super().__init__(batch_shape,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.