Skip to content

Commit

Permalink
Merge pull request #21 from KrishnaswamyLab/dev
Browse files Browse the repository at this point in the history
Fix issue #20
  • Loading branch information
dburkhardt authored May 4, 2018
2 parents 2c553d0 + c2b7407 commit 9804d9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
10 changes: 6 additions & 4 deletions Python/phate/mds.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def embed_MDS(X, ndim=2, how='metric', distance_metric='euclidean', n_jobs=1, se
Y_cmds = cmdscale_fast(X_dist, ndim)
# Then compute Metric MDS
Y_mmds = MDS(n_components=ndim, metric=True, max_iter=3000, eps=1e-12,
dissimilarity="precomputed", random_state=seed, n_jobs=n_jobs,
n_init=1).fit_transform(X_dist, init=Y_cmds)
dissimilarity="precomputed", random_state=seed,
n_jobs=n_jobs, n_init=1).fit_transform(X_dist,
init=Y_cmds)
# Nonmetric MDS from sklearn using metric MDS as an initialization
Y = MDS(n_components=ndim, metric=False, max_iter=3000, eps=1e-12,
dissimilarity="precomputed", random_state=seed, n_jobs=n_jobs,
n_init=1).fit_transform(X_dist, init=Y_mmds)
else:
raise ValueError(
"Allowable 'how' values for MDS: 'classic', 'metric', or 'nonmetric'. '%s' was passed." % (how))
raise ValueError("Allowable 'how' values for MDS: 'classic', "
"'metric', or 'nonmetric'. "
"'{}' was passed.".format(how))
return Y
22 changes: 11 additions & 11 deletions Python/phate/phate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def calculate_kernel(data, k=15, a=10, alpha_decay=True, knn_dist='euclidean',
random_state=random_state)
data = pca.fit_transform(data)
if verbose:
print("PCA complete in {:.2d} seconds".format(
print("PCA complete in {:.2f} seconds".format(
time.time() - start))
if verbose:
start = time.time()
Expand Down Expand Up @@ -132,7 +132,7 @@ def calculate_kernel(data, k=15, a=10, alpha_decay=True, knn_dist='euclidean',
kernel = knn.kneighbors_graph(data, mode='connectivity')

if verbose:
print("KNN complete in {:.2d} seconds".format(time.time() - start))
print("KNN complete in {:.2f} seconds".format(time.time() - start))
kernel = kernel + kernel.T # symmetrization
return kernel

Expand Down Expand Up @@ -184,7 +184,7 @@ def calculate_landmark_operator(kernel, n_landmark=2000,
n_components=n_svd,
random_state=random_state)
if verbose:
print("SVD complete in {:.2d} seconds".format(time.time() - start))
print("SVD complete in {:.2f} seconds".format(time.time() - start))
start = time.time()
print("Calculating Kmeans...")
kmeans = MiniBatchKMeans(n_landmark,
Expand Down Expand Up @@ -306,8 +306,8 @@ def calculate_operator(data, k=15, a=10, alpha_decay=True, n_landmark=2000,
kernel, n_landmark=n_landmark,
random_state=random_state, verbose=verbose)
if verbose:
print("Built graph and diffusion operator in %.2f seconds." %
(time.time() - tic))
print("Built graph and diffusion operator in "
"{:.2f} seconds.".format(time.time() - tic))
else:
if verbose:
print("Using precomputed diffusion operator...")
Expand Down Expand Up @@ -395,8 +395,8 @@ def embed_mds(diff_op, t=30, n_components=2, diff_potential=None,
"'sqrt'. '%s' was passed." % (potential_method))

if verbose:
print("Calculated diffusion potential in %.2f seconds." %
(time.time() - tic))
print("Calculated diffusion potential in "
"{:.2f} seconds.".format(time.time() - tic))
# if diffusion potential is precomputed (i.e. 'mds' or 'mds_dist' has
# changed on PHATE object)
else:
Expand All @@ -405,7 +405,7 @@ def embed_mds(diff_op, t=30, n_components=2, diff_potential=None,

tic = time.time()
if verbose:
print("Embedding data using %s MDS..." % (mds))
print("Embedding data using {} MDS...".format(mds))
if embedding is None:
embedding = embed_MDS(diff_potential, ndim=n_components, how=mds,
distance_metric=mds_dist, n_jobs=n_jobs,
Expand All @@ -414,7 +414,7 @@ def embed_mds(diff_op, t=30, n_components=2, diff_potential=None,
# return to ambient space
embedding = landmark_transitions.dot(embedding)
if verbose:
print("Embedded data in %.2f seconds." % (time.time() - tic))
print("Embedded data in {:.2f} seconds.".format(time.time() - tic))
else:
if verbose:
print("Using precomputed embedding...")
Expand Down Expand Up @@ -747,8 +747,8 @@ def fit_transform(self, X, **kwargs):
self.fit(X)
self.transform(**kwargs)
if self.verbose:
print("Finished PHATE embedding in %.2f seconds.\n" %
(time.time() - start))
print("Finished PHATE embedding in {:.2f} seconds.\n".format(
time.time() - start))
return self.embedding

def von_neumann_entropy(self, t_max=100):
Expand Down
2 changes: 1 addition & 1 deletion Python/phate/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2"
__version__ = "0.2.3"
1 change: 1 addition & 0 deletions Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'big-data',
'dimensionality-reduction',
'embedding',
'manifold-learning',
'computational-biology'],
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit 9804d9d

Please sign in to comment.