def log_bernoulli(x, p, eps=1e-5):
"""
Compute log pdf of a Bernoulli distribution with success probability p, at values x.
.. math:: \log p(x; p) = \log \mathcal{B}(x; p)
Parameters
----------
x : Theano tensor
Values at which to evaluate pdf.
p : Theano tensor
Success probability :math:`p(x=1)`, which is also the mean of the Bernoulli distribution.
eps : float
Small number used to avoid NaNs by clipping p in range [eps;1-eps].
Returns
-------
Theano tensor
Element-wise log probability, this has to be summed for multi-variate distributions.
"""
p = T.clip(p, eps, 1.0 - eps)
return -T.nnet.binary_crossentropy(p, x)
评论列表
文章目录