summaryrefslogtreecommitdiff
path: root/src/python/gudhi/clustering/tomato.py
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2020-05-25 18:30:56 +0200
committerMarc Glisse <marc.glisse@inria.fr>2020-05-25 18:30:56 +0200
commitfc7da6849c40cc0caef0e86e452f6d1e2c8320d0 (patch)
treeee1a5334370a3eaa41f0c53318879a30306536f5 /src/python/gudhi/clustering/tomato.py
parentc6bc508fe2f101f37fb7e1a940f3869122f7da71 (diff)
handle n<k
Diffstat (limited to 'src/python/gudhi/clustering/tomato.py')
-rw-r--r--src/python/gudhi/clustering/tomato.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/python/gudhi/clustering/tomato.py b/src/python/gudhi/clustering/tomato.py
index 7e67c7fd..fcb4b234 100644
--- a/src/python/gudhi/clustering/tomato.py
+++ b/src/python/gudhi/clustering/tomato.py
@@ -109,12 +109,18 @@ class Tomato:
need_knn_ngb = False
need_knn_dist = False
if self.graph_type_ == "knn":
- k_graph = self.params_.get("k", 10) # FIXME: What if X has fewer than 10 points?
+ k_graph = self.params_.get("k", 10)
+ # If X has fewer than k points...
+ if k_graph > len(X):
+ k_graph = len(X)
need_knn = k_graph
need_knn_ngb = True
if self.density_type_ in ["DTM", "logDTM"]:
- k = self.params_.get("k", 10) # FIXME: What if X has fewer than 10 points?
+ k = self.params_.get("k", 10)
k_DTM = self.params_.get("k_DTM", k)
+ # If X has fewer than k points...
+ if k_DTM > len(X):
+ k_DTM = len(X)
need_knn = max(need_knn, k_DTM)
need_knn_dist = True
# if we ask for more neighbors for the graph than the DTM, getting the distances is a slight waste,