Exemple #1
0
    def test_sparse_2d(self):
        p_x = torch.FloatTensor([0.0, 1.0])
        H_x = torch.FloatTensor([0.0])

        H_x_hat = categorical_entropy(p_x)

        self.assertTrue(torch.equal(H_x_hat, H_x))
Exemple #2
0
    def test_uniform_2_dists(self):
        p_x = torch.FloatTensor([[0.5, 0.5], [0.0, 1.0]])
        H_x = torch.FloatTensor([1.0, 0.0])

        H_x_hat = categorical_entropy(p_x)

        self.assertTrue(torch.equal(H_x_hat, H_x))
Exemple #3
0
def bows_to_ent(bows):
    uni_ps = bows_to_ps(bows)
    entropies = analysis.categorical_entropy(uni_ps)

    avg_entropy = entropies @ bows.sum(dim=1) / bows.sum()
    return avg_entropy
Exemple #4
0
    def test_nonuniform_3d(self):
        p_x = torch.FloatTensor([0.5, 0.25, 0.25])
        H_x = torch.FloatTensor([1.5])

        self.assertTrue(torch.equal(categorical_entropy(p_x), H_x))