-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_uncertainty_metrics.py
38 lines (31 loc) · 1.11 KB
/
test_uncertainty_metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import unittest
import numpy as np
from scipy.sparse import csr_matrix
import ce.uncertainty_metrics as um
class TestUncertaintyMetrics(unittest.TestCase):
def test_um_var_equal(self):
arr = np.array([[[0.5, 0.5, 0.5]], [[0.75, 0.75, 0.75]]])
var = um.calcVar(arr)
assert var[0] == 0
assert var[1] == 0
def test_um_var_spread(self):
arr = np.array([[[0, 0.5, 0.5, 1]], [[0, 0, 1, 1]]])
var = um.calcVar(arr)
assert np.allclose(var[0], np.var(arr[0, :]))
assert np.allclose(var[1], np.var(arr[1, :]))
def test_um_ig_equal(self):
arr = np.array([[[0.5, 0.5, 0.5]], [[0.75, 0.75, 0.75]]])
ig = um.calcVar(arr)
assert ig[0] == 0
assert ig[1] == 0
def test_um_ig_spread(self):
arr = np.array([[[0, 0.5, 0.5, 1]], [[0, 0, 1, 1]]])
ig = um.calcIG(arr)
assert ig[0] == 0.5
assert ig[1] == 1
def test_um_ent_key(self):
arr = np.array([0, 0.5, 1])[:,None]
ent = um.calcEntropy(arr)
assert ent[0][0] == 0
assert ent[1][0] == 1
assert ent[2][0] == 0