Пример #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))
Пример #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))
Пример #3
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))