Пример #1
0
 def test_exp_llh_labels(self):
     for i, model in enumerate(self.hmms):
         with self.subTest(i=i):
             label_idxs = torch.zeros(self.data.size(0)).long()
             elabels = beer.onehot(label_idxs, len(model.modelset))
             mask = torch.log(elabels).numpy()
             elabels = elabels.numpy()
             stats = model.sufficient_statistics(self.data)
             pc_exp_llh = model.modelset(stats)
             pc_exp_llh = pc_exp_llh.numpy()
             pc_exp_llh += mask
             exp_llh1 = logsumexp(pc_exp_llh, axis=1)
             exp_llh2 = model(stats, label_idxs).numpy()
             self.assertArraysAlmostEqual(exp_llh1, exp_llh2)
Пример #2
0
 def test_exp_llh_labels(self):
     for i, model in enumerate(self.mixtures):
         with self.subTest(i=i):
             labels = torch.zeros(self.data.size(0)).long()
             elabels = beer.onehot(labels, len(model.modelset))
             mask = torch.log(elabels).numpy()
             elabels = elabels.numpy()
             stats = model.sufficient_statistics(self.data)
             pc_exp_llh = model.modelset(stats) + \
                 model.weights_param.expected_value().view(1, -1)
             pc_exp_llh = pc_exp_llh.numpy()
             pc_exp_llh += mask
             exp_llh1 = logsumexp(pc_exp_llh, axis=1)
             exp_llh2 = model(stats, labels).numpy()
             self.assertArraysAlmostEqual(exp_llh1, exp_llh2)
Пример #3
0
 def test_onehot(self):
     ref = torch.range(0, 2).long()
     labs1 = beer.onehot(ref, 3).long()
     labs2 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
     self.assertArraysAlmostEqual(labs1.numpy(), labs2)