def test_log_beta_stirling(tol): x = torch.logspace(-5, 5, 200) y = x.unsqueeze(-1) expected = log_beta(x, y) actual = log_beta(x, y, tol=tol) assert (actual <= expected).all() assert (expected < actual + tol).all()
def log_prob(self, value): if self._validate_args: self._validate_sample(value) n = self.total_count k = value a = self.concentration1 b = self.concentration0 tol = self.approx_log_prob_tol return (log_binomial(n, k, tol) + log_beta(k + a, n - k + b, tol) - log_beta(a, b, tol))
def log_prob(self, value): if self._validate_args: self._validate_sample(value) post_value = self.concentration + value return (-log_beta(self.concentration, value + 1) - post_value.log() + self.concentration * self.rate.log() - post_value * (1 + self.rate).log())