Skip to content

Commit

Permalink
fix precomputed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jun 21, 2018
1 parent d52327f commit 078c7f2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions graphtools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,12 @@ def build_kernel(self):
------
ValueError: if `precomputed` is not an acceptable value
"""
if self.precomputed is "affinity":
if self.precomputed == "affinity":
# already done
# TODO: should we check that precomputed matrices look okay?
# e.g. check the diagonal
K = self.data_nu
elif self.precomputed is "adjacency":
elif self.precomputed == "adjacency":
# need to set diagonal to one to make it an affinity matrix
K = self.data_nu
if sparse.issparse(K) and \
Expand All @@ -703,10 +703,15 @@ def build_kernel(self):
log_start("affinities")
if sparse.issparse(self.data_nu):
self.data_nu = self.data_nu.toarray()
if self.precomputed is "distance":
if self.precomputed == "distance":
pdx = self.data_nu
elif self.precomputed is None:
pdx = squareform(pdist(self.data_nu, metric=self.distance))
else:
raise ValueError(
"precomputed='{}' not recognized. "
"Choose from ['affinity', 'adjacency', 'distance', "
"None]".format(self.precomputed))
knn_dist = np.partition(pdx, self.knn, axis=1)[:, :self.knn]
epsilon = np.max(knn_dist, axis=1)
pdx = (pdx.T / epsilon).T
Expand Down

0 comments on commit 078c7f2

Please sign in to comment.