Skip to content

Commit

Permalink
Merge branch 'dev_landmark' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jul 27, 2018
2 parents d0d9191 + 6b9fa26 commit 887e252
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
27 changes: 18 additions & 9 deletions graphtools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,20 @@ def transitions(self):
self.build_landmark_op()
return self._transitions

def _landmarks_to_data(self):
landmarks = np.unique(self._clusters)
if sparse.issparse(self.kernel):
pmn = sparse.vstack(
[sparse.csr_matrix(self.kernel[self._clusters == i, :].sum(
axis=0)) for i in landmarks])
else:
pmn = np.array([np.sum(self.kernel[self._clusters == i, :], axis=0)
for i in landmarks])
return pmn

def _data_transitions(self):
return normalize(self._landmarks_to_data(), 'l1', axis=1)

def build_landmark_op(self):
"""Build the landmark operator
Expand All @@ -469,17 +483,11 @@ def build_landmark_op(self):
self._clusters = kmeans.fit_predict(
self.diff_op.dot(VT.T))
# some clusters are not assigned
landmarks = np.unique(self._clusters)
tasklogger.log_complete("KMeans")

# transition matrices
if is_sparse:
pmn = sparse.vstack(
[sparse.csr_matrix(self.kernel[self._clusters == i, :].sum(
axis=0)) for i in landmarks])
else:
pmn = np.array([np.sum(self.kernel[self._clusters == i, :], axis=0)
for i in landmarks])
pmn = self._landmarks_to_data()

# row normalize
pnm = pmn.transpose()
pmn = normalize(pmn, norm='l1', axis=1)
Expand Down Expand Up @@ -594,7 +602,8 @@ class TraditionalGraph(DataGraph):
All affinities below `thresh` will be set to zero in order to save
on time and memory constraints.
precomputed : {'distance', 'affinity', 'adjacency', `None`}, optional (default: `None`)
precomputed : {'distance', 'affinity', 'adjacency', `None`},
optional (default: `None`)
If the graph is precomputed, this variable denotes which graph
matrix is provided as `data`.
Only one of `precomputed` and `n_pca` can be set.
Expand Down
23 changes: 20 additions & 3 deletions test/load_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@

import nose2
from nose.tools import raises, assert_raises, make_decorator
warnings.filterwarnings("error")


def reset_warnings():
warnings.resetwarnings()
warnings.simplefilter("error")
ignore_numpy_warning()


def ignore_numpy_warning():
warnings.filterwarnings(
"ignore", category=PendingDeprecationWarning,
message="the matrix subclass is not the recommended way to represent "
"matrices or deal with linear algebra ")


reset_warnings()

global digits
global data
Expand Down Expand Up @@ -65,9 +80,11 @@ def decorate(func):

def newfunc(*arg, **kw):
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings("always")
warnings.resetwarnings()
warnings.simplefilter("always")
ignore_numpy_warning()
func(*arg, **kw)
warnings.filterwarnings("error")
reset_warnings()
try:
for warn in w:
raise warn.category
Expand Down

0 comments on commit 887e252

Please sign in to comment.