Skip to content

Commit

Permalink
add better logging for knn > n_samples
Browse files Browse the repository at this point in the history
checks for error occurring in #12
  • Loading branch information
scottgigante committed Jun 13, 2018
1 parent f6bba3e commit e9ece00
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion graphtools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __init__(self, data, knn=5, decay=None,
if decay is not None and thresh <= 0:
raise ValueError("Cannot instantiate a kNNGraph with `decay=None` "
"and `thresh=0`. Use a TraditionalGraph instead.")
if knn > data.shape[0]:
warnings.warn("Cannot set knn ({k}) to be greater than "
"data.shape[0] ({n}). Setting knn={n}".format(
k=knn, n=data.shape[0]))

super().__init__(data, **kwargs)

Expand Down Expand Up @@ -203,6 +207,11 @@ def build_kernel_to_data(self, Y, knn=None):
"""
if knn is None:
knn = self.knn
if knn > self.data.shape[0]:
warnings.warn("Cannot set knn ({k}) to be greater than "
"data.shape[0] ({n}). Setting knn={n}".format(
k=knn, n=self.data.shape[0]))

Y = self._check_extension_shape(Y)
log_start("KNN search")
if self.decay is None or self.thresh == 1:
Expand Down Expand Up @@ -949,7 +958,8 @@ def build_kernel(self):
from .api import Graph
# iterate through sample ids
for i, idx in enumerate(self.samples):
log_debug("subgraph {}: sample {}".format(i, idx))
log_debug("subgraph {}: sample {}, n = {}, knn = {}".format(
i, idx, np.sum(self.sample_idx == idx), self.weighted_knn[i]))
# select data for sample
data = self.data_nu[self.sample_idx == idx]
# build a kNN graph for cells within sample
Expand Down

0 comments on commit e9ece00

Please sign in to comment.