def _log_pdf(self, x): return ( self.shape * log(self.rate) + (self.shape - 1) * log(x) - self.rate * x - log(gamma(self.shape)) )
def _log_pdf(self, x): return ( log(gamma(self.alpha.sum(axis=self.axis))) + sum( (self.alpha - 1) * log(x) - log(gamma(self.alpha)), axis=self.axis ) )
def __init__(self, mean=None, logit=None, use_gumbel_softmax=True, tau=0.1): super().__init__() if mean is not None: self.mean = asarray(mean) assert ((self.mean.value >= 0).all() and np.allclose(self.mean.value.sum(axis=-1), 1)) self.logit = log(self.mean) self._log_pdf = self._log_pdf_mean elif logit is not None: self.mean = softmax(logit) self.logit = asarray(logit) self._log_pdf = self._log_pdf_logit else: raise ValueError self.n_category = self.mean.shape[-1] if use_gumbel_softmax: self.forward = self._forward_gumbel_softmax else: self.forward = self._forward self.tau = tau self.eye = np.eye(self.n_category)
def _log_pdf(self, x): assert x.shape[-1] == self.mu.size if x.ndim == 1: squeeze = True x = broadcast_to(x, (1, self.mu.size)) else: squeeze = False assert x.ndim == 2 d = x - self.mu d = d.transpose() logp = (-0.5 * (solve(self.cov, d) * d).sum(axis=0) - (self.mu.size * 0.5) * log(2 * np.pi) - 0.5 * logdet(self.cov)) if squeeze: logp = logp.sum() return logp
def _log_pdf(self, x): return (-np.log(np.pi) - log(self.scale) - log(1 + square((x - self.loc) / self.scale)))
def _log_pdf(self, x): return (self.shape * log(self.rate) + (self.shape - 1) * log(x) - self.rate * x - log(gamma(self.shape)))
def _log_pdf_mu(self, x): return x * log(self.mean) + (1 - x) * log(1 - self.mean)
def _log_pdf(self, x): return ((self.ndim - 1) * log(x) - 0.5 * square(x / self.std) - self.ndim * log(self.std) - np.log(sp.gamma(0.5 * self.ndim)))
def _log_pdf(self, x): try: return -SigmoidCrossEntropy().forward(self.logit, x) except AttributeError: return x * log(self.mu) + (1 - x) * log(1 - self.mu)
def _log_pdf(self, x): try: return -SoftmaxCrossEntropy(axis=self.axis).forward(self.logit, x) except (KeyError, AttributeError): return (x * log(self.mu)).sum(axis=self.axis)
def _log_pdf_mean(self, x): return x * log(self.mean)
def _log_pdf(self, x): return log(self.pdf(x))
def _log_pdf(self, x): return ( -np.log(np.pi) - log(self.scale) - log(1 + square((x - self.loc) / self.scale)) )
def _log_pdf(self, x): return -self.rate * x + log(self.rate)
def _log_pdf(self, x): return np.log(0.5) - abs(x - self.loc) / self.scale - log(self.scale)
def kl_gaussian(q, p): qvar = square(q.std) pvar = square(p.std) return log(p.std) - log(q.std) + 0.5 * (qvar + square(p.mean - q.mean)) / pvar - 0.5
def _log_pdf(self, x): return (log(gamma(self.alpha.sum(axis=self.axis))) + sum( (self.alpha - 1) * log(x) - log(gamma(self.alpha)), axis=self.axis))