diff options
author | wreise <wojciech.reise@epfl.ch> | 2022-08-10 10:28:26 +0200 |
---|---|---|
committer | wreise <wojciech.reise@epfl.ch> | 2022-08-10 10:28:26 +0200 |
commit | b9a31fed2b90ee69a5c23047fd2ff1c264ad9605 (patch) | |
tree | c7a6e319c5cc6ba9c7963b08f7a4cdf3c776c922 /src/python/test/test_representations.py | |
parent | 60e57f9c86a7aae67c2931200066aba059ec2721 (diff) | |
parent | 4f83706aa1263c04cb5e8763e1e8eb6c580bed3c (diff) |
Merge branch 'master' into optimize_silhouettes
Diffstat (limited to 'src/python/test/test_representations.py')
-rwxr-xr-x | src/python/test/test_representations.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/python/test/test_representations.py b/src/python/test/test_representations.py index 5f29740f..2ca72d07 100755 --- a/src/python/test/test_representations.py +++ b/src/python/test/test_representations.py @@ -152,7 +152,26 @@ def test_vectorization_empty_diagrams(): scv = Entropy(mode="vector", normalized=False, resolution=random_resolution)(empty_diag) assert not np.any(scv) assert scv.shape[0] == random_resolution - + +def test_entropy_miscalculation(): + diag_ex = np.array([[0.0,1.0], [0.0,1.0], [0.0,2.0]]) + def pe(pd): + l = pd[:,1] - pd[:,0] + l = l/sum(l) + return -np.dot(l, np.log(l)) + sce = Entropy(mode="scalar") + assert [[pe(diag_ex)]] == sce.fit_transform([diag_ex]) + sce = Entropy(mode="vector", resolution=4, normalized=False) + pef = [-1/4*np.log(1/4)-1/4*np.log(1/4)-1/2*np.log(1/2), + -1/4*np.log(1/4)-1/4*np.log(1/4)-1/2*np.log(1/2), + -1/2*np.log(1/2), + 0.0] + assert all(([pef] == sce.fit_transform([diag_ex]))[0]) + sce = Entropy(mode="vector", resolution=4, normalized=True) + pefN = (sce.fit_transform([diag_ex]))[0] + area = np.linalg.norm(pefN, ord=1) + assert area==1 + def test_kernel_empty_diagrams(): empty_diag = np.empty(shape = [0, 2]) assert SlicedWassersteinDistance(num_directions=100)(empty_diag, empty_diag) == 0. |