Skip to content

Commit

Permalink
fix anchor device, fix spectral bugs (cvxgrp#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayka authored Mar 28, 2022
1 parent e8b1b4b commit 0e9ab9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pymde/quadratic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _spectral(
L,
m,
cg=False,
max_iter=40,
max_iter=400,
edges=None,
weights=None,
warm_start=False,
Expand All @@ -91,6 +91,7 @@ def _spectral(
v0=np.ones(L.shape[0]),
maxiter=L.shape[0] * 5,
)
order = np.argsort(eigenvalues)[1:k]
else:
if warm_start:
mde = problem.MDE(
Expand All @@ -114,7 +115,7 @@ def _spectral(
largest=False,
niter=max_iter,
)
order = np.argsort(eigenvalues)[1:k]
order = torch.argsort(eigenvalues)[1:k]
return eigenvectors[:, order]


Expand Down
16 changes: 11 additions & 5 deletions pymde/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _remove_anchor_anchor_edges(edges, data, anchors, opt=None, blk=1e8):
estep = int(blk / na)
assert estep > 0

msk0 = torch.zeros(ne, dtype=torch.bool, device=edges.get_device())
msk1 = torch.zeros(ne, dtype=torch.bool, device=edges.get_device())
msk0 = torch.zeros(ne, dtype=torch.bool, device=edges.device)
msk1 = torch.zeros(ne, dtype=torch.bool, device=edges.device)
e = 0
while e < ne:
ehi = e + estep if e + estep < ne else ne
Expand All @@ -79,8 +79,8 @@ def _remove_anchor_anchor_edges(edges, data, anchors, opt=None, blk=1e8):
assert astep > 0
assert estep > 0

msk0 = torch.zeros(ne, dtype=torch.bool, device=edges.get_device())
msk1 = torch.zeros(ne, dtype=torch.bool, device=edges.get_device())
msk0 = torch.zeros(ne, dtype=torch.bool, device=edges.device)
msk1 = torch.zeros(ne, dtype=torch.bool, device=edges.device)
e = 0
while e < ne:
ehi = e + estep if e + estep < ne else ne
Expand Down Expand Up @@ -365,7 +365,13 @@ def preserve_neighbors(
# use cg + torch when using GPU
cg = device == "cuda"
X_init = quadratic.spectral(
n, embedding_dim, edges, weights, device=device, cg=cg
n,
embedding_dim,
edges,
weights,
max_iter=1000,
device=device,
cg=cg,
)
if not isinstance(
constraint, (constraints._Centered, constraints._Standardized)
Expand Down

0 comments on commit 0e9ab9d

Please sign in to comment.