Beispiel #1
0
def test_bernoulli_logpdf(T=100, K=4, D=10):
    # Test single datapoint log pdf
    x = npr.rand(T, D) < 0.5
    logit_ps = npr.randn(K, D)
    ps = 1 / (1 + np.exp(-logit_ps))
    ll1 = bernoulli_logpdf(x[:, None, :], logit_ps)
    ll2 = np.sum(bernoulli.logpmf(x[:, None, :], ps[None, :, :]), axis=-1)
    assert np.allclose(ll1, ll2)
Beispiel #2
0
 def log_likelihoods(self, data, input, mask, tag, x):
     assert data.dtype == bool or (data.dtype == int and data.min() >= 0
                                   and data.max() <= 1)
     assert self.link_name == "logit", "Log likelihood is only implemented for logit link."
     logit_ps = self.forward(x, input, tag)
     mask = np.ones_like(data, dtype=bool) if mask is None else mask
     return bernoulli_logpdf(data[:, None, :],
                             logit_ps,
                             mask=mask[:, None, :])
Beispiel #3
0
 def log_likelihoods(self, data, input, mask, tag):
     mask = np.ones_like(data, dtype=bool) if mask is None else mask
     return stats.bernoulli_logpdf(data[:, None, :],
                                   self.logit_ps,
                                   mask=mask[:, None, :])