summaryrefslogtreecommitdiff
path: root/src/python/test/test_representations.py
diff options
context:
space:
mode:
authorVincent Rouvreau <vincent.rouvreau@inria.fr>2021-10-19 21:20:01 +0200
committerVincent Rouvreau <vincent.rouvreau@inria.fr>2021-10-19 21:20:01 +0200
commit0c8e1e2b69c7658c153df99931e3407ec18c1332 (patch)
tree281878cf4817d7618d3462b3a900d53caf94fbdc /src/python/test/test_representations.py
parentec06a9b9ae0a9ff1897249dcbc2b497764f54aaf (diff)
Add empty diags tests
Diffstat (limited to 'src/python/test/test_representations.py')
-rwxr-xr-xsrc/python/test/test_representations.py60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/python/test/test_representations.py b/src/python/test/test_representations.py
index c1f4df12..b888b7f1 100755
--- a/src/python/test/test_representations.py
+++ b/src/python/test/test_representations.py
@@ -6,9 +6,16 @@ import pytest
from sklearn.cluster import KMeans
-from gudhi.representations import (DiagramSelector, Clamping, Landscape, Silhouette, BettiCurve, ComplexPolynomial,\
- TopologicalVector, DiagramScaler, BirthPersistenceTransform,\
- PersistenceImage, PersistenceWeightedGaussianKernel, Entropy, \
+# Vectorization
+from gudhi.representations import (Landscape, Silhouette, BettiCurve, ComplexPolynomial,\
+ TopologicalVector, PersistenceImage, Entropy)
+
+# Preprocessing
+from gudhi.representations import (BirthPersistenceTransform, Clamping, DiagramScaler, Padding, ProminentPoints, \
+ DiagramSelector)
+
+# Kernel
+from gudhi.representations import (PersistenceWeightedGaussianKernel, \
PersistenceScaleSpaceKernel, SlicedWassersteinDistance,\
SlicedWassersteinKernel, PersistenceFisherKernel, WassersteinDistance)
@@ -105,33 +112,44 @@ def test_infinity():
assert c[7] == 3
assert c[9] == 2
+
+def test_preprocessing_empty_diagrams():
+ empty_diag = np.empty(shape = [0, 2])
+ assert not np.any(BirthPersistenceTransform()(empty_diag))
+ assert not np.any(Clamping().fit_transform(empty_diag))
+ assert not np.any(DiagramScaler()(empty_diag))
+ assert not np.any(Padding()(empty_diag))
+ assert not np.any(ProminentPoints()(empty_diag))
+ assert not np.any(DiagramSelector()(empty_diag))
+
def pow(n):
return lambda x: np.power(x[1]-x[0],n)
def test_vectorization_empty_diagrams():
empty_diag = np.empty(shape = [0, 2])
- Landscape(resolution=1000)(empty_diag)
- Silhouette(resolution=1000, weight=pow(2))(empty_diag)
- BettiCurve(resolution=1000)(empty_diag)
- ComplexPolynomial(threshold=-1, polynomial_type="T")(empty_diag)
- TopologicalVector(threshold=-1)(empty_diag)
- PersistenceImage(bandwidth=.1, weight=lambda x: x[1], im_range=[0,1,0,1], resolution=[100,100])(empty_diag)
- #Entropy(mode="scalar")(empty_diag)
- #Entropy(mode="vector", normalized=False)(empty_diag)
-
-#def arctan(C,p):
-# return lambda x: C*np.arctan(np.power(x[1], p))
+ assert not np.any(Landscape(resolution=1000)(empty_diag))
+ assert not np.any(Silhouette(resolution=1000, weight=pow(2))(empty_diag))
+ assert not np.any(BettiCurve(resolution=1000)(empty_diag))
+ assert not np.any(ComplexPolynomial(threshold=-1, polynomial_type="T")(empty_diag))
+ assert not np.any(TopologicalVector(threshold=-1)(empty_diag))
+ assert not np.any(PersistenceImage(bandwidth=.1, weight=lambda x: x[1], im_range=[0,1,0,1], resolution=[100,100])(empty_diag))
+ assert not np.any(Entropy(mode="scalar")(empty_diag))
+ assert not np.any(Entropy(mode="vector", normalized=False)(empty_diag))
+
+def arctan(C,p):
+ return lambda x: C*np.arctan(np.power(x[1], p))
#
-#def test_kernel_empty_diagrams():
-# empty_diag = np.empty(shape = [0, 2])
+def test_kernel_empty_diagrams():
+ empty_diag = np.empty(shape = [0, 2])
# PersistenceWeightedGaussianKernel(bandwidth=1., kernel_approx=None, weight=arctan(1.,1.))(empty_diag, empty_diag)
# PersistenceWeightedGaussianKernel(kernel_approx=RBFSampler(gamma=1./2, n_components=100000).fit(np.ones([1,2])), weight=arctan(1.,1.))(empty_diag, empty_diag)
# PersistenceScaleSpaceKernel(bandwidth=1.)(empty_diag, empty_diag)
# PersistenceScaleSpaceKernel(kernel_approx=RBFSampler(gamma=1./2, n_components=100000).fit(np.ones([1,2])))(empty_diag, empty_diag)
-# SlicedWassersteinDistance(num_directions=100)(empty_diag, empty_diag)
-# SlicedWassersteinKernel(num_directions=100, bandwidth=1.)(empty_diag, empty_diag)
-# WassersteinDistance(order=2, internal_p=2, mode="pot")(empty_diag, empty_diag)
-# WassersteinDistance(order=2, internal_p=2, mode="hera", delta=0.0001)(empty_diag, empty_diag)
-# BottleneckDistance(epsilon=.001)(empty_diag, empty_diag)
+ assert SlicedWassersteinDistance(num_directions=100)(empty_diag, empty_diag) == 0.
+ assert SlicedWassersteinKernel(num_directions=100, bandwidth=1.)(empty_diag, empty_diag) == 1.
+ assert WassersteinDistance(mode="hera", delta=0.0001)(empty_diag, empty_diag) == 0.
+ assert WassersteinDistance(mode="pot")(empty_diag, empty_diag) == 0.
+ assert BottleneckDistance(epsilon=.001)(empty_diag, empty_diag) == 0.
+ assert BottleneckDistance()(empty_diag, empty_diag) == 0.
# PersistenceFisherKernel(bandwidth_fisher=1., bandwidth=1.)(empty_diag, empty_diag)
# PersistenceFisherKernel(bandwidth_fisher=1., bandwidth=1., kernel_approx=RBFSampler(gamma=1./2, n_components=100000).fit(np.ones([1,2])))(empty_diag, empty_diag)