Example #1
0
 def test_theil_multiple_vectors(self):
     sample = torch.Tensor(np.array([[0, 0, 0, 0], [1, 1, 1, 1]]))
     self.assertTrue(torch.all(torch.eq(theil(sample), torch.Tensor([0., 0.]))))
Example #2
0
 def test_theil(self):
     sample = torch.Tensor(np.array([[0, 0, 0, 0, 0, 1]]))
     self.assertTrue(abs(theil(sample).item() - (1/2) * ((5/3) * np.log(5/3) + (1/3) * np.log(1/3))) < 1e-7)
Example #3
0
 def test_random_theil(self):
     num_classes = 5
     sample_size = 10
     sample = torch.Tensor([np.random.choice(np.arange(num_classes), size=sample_size)])
     self.assertGreaterEqual(theil(sample), 0.)
     self.assertLessEqual(theil(sample), 1.)
Example #4
0
 def test_equal_mix_theil(self):
     sample = torch.Tensor(np.array([[0, 0, 0, 1, 1, 1]]))
     self.assertEqual(theil(sample), 0.)
Example #5
0
 def test_ones_theil(self):
     sample = torch.Tensor(np.array([[1, 1, 1, 1, 1]]))
     self.assertEqual(theil(sample), 0.)
Example #6
0
 def test_zeros_theil(self):
     sample = torch.Tensor(np.array([[0, 0, 0, 0, 0]]))
     self.assertEqual(theil(sample), 0.)