nystrom-ncut 0.0.5__tar.gz → 0.0.6__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {nystrom_ncut-0.0.5/src/nystrom_ncut.egg-info → nystrom_ncut-0.0.6}/PKG-INFO +2 -2
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/pyproject.toml +1 -1
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/propagation_utils.py +30 -7
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6/src/nystrom_ncut.egg-info}/PKG-INFO +2 -2
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/tests/test.py +4 -3
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/LICENSE +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/MANIFEST.in +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/README.md +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/requirements.txt +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/setup.cfg +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/__init__.py +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/common.py +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/ncut_pytorch.py +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/nystrom.py +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut/visualize_utils.py +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut.egg-info/SOURCES.txt +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut.egg-info/dependency_links.txt +0 -0
- {nystrom_ncut-0.0.5 → nystrom_ncut-0.0.6}/src/nystrom_ncut.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.6
|
4
4
|
Summary: Normalized Cut and Nyström Approximation
|
5
5
|
Author-email: Huzheng Yang <huze.yann@gmail.com>, Wentinn Liao <wentinn.liao@gmail.com>
|
6
6
|
Project-URL: Documentation, https://github.com/JophiArcana/Nystrom-NCUT/
|
@@ -96,7 +96,6 @@ def distance_from_features(
|
|
96
96
|
D = D / (2 * features.var(dim=0).sum())
|
97
97
|
else:
|
98
98
|
raise ValueError("distance should be 'cosine' or 'euclidean', 'rbf'")
|
99
|
-
|
100
99
|
return D
|
101
100
|
|
102
101
|
|
@@ -184,13 +183,37 @@ def propagate_knn(
|
|
184
183
|
V_list = []
|
185
184
|
for _v in torch.chunk(inp_features, n_chunks, dim=0):
|
186
185
|
_v = _v.to(device)
|
187
|
-
_A = affinity_from_features(subgraph_features, _v, affinity_focal_gamma, distance).mT
|
188
186
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
_A =
|
187
|
+
# _A = affinity_from_features(subgraph_features, _v, affinity_focal_gamma, distance).mT
|
188
|
+
# if knn is not None:
|
189
|
+
# mask = torch.full_like(_A, True, dtype=torch.bool)
|
190
|
+
# mask[torch.arange(len(_v))[:, None], _A.topk(knn, dim=-1, largest=True).indices] = False
|
191
|
+
# _A[mask] = 0.0
|
192
|
+
# _A = F.normalize(_A, p=1, dim=-1)
|
193
|
+
|
194
|
+
if distance == 'cosine':
|
195
|
+
_A = _v @ subgraph_features.T
|
196
|
+
elif distance == 'euclidean':
|
197
|
+
_A = - torch.cdist(_v, subgraph_features, p=2)
|
198
|
+
elif distance == 'rbf':
|
199
|
+
_A = - torch.cdist(_v, subgraph_features, p=2) ** 2
|
200
|
+
else:
|
201
|
+
raise ValueError("distance should be 'cosine' or 'euclidean', 'rbf'")
|
202
|
+
|
203
|
+
# keep topk KNN for each row
|
204
|
+
topk_sim, topk_idx = _A.topk(knn, dim=-1, largest=True)
|
205
|
+
row_id = torch.arange(topk_idx.shape[0], device=_A.device)[:, None].expand(
|
206
|
+
-1, topk_idx.shape[1]
|
207
|
+
)
|
208
|
+
_A = torch.sparse_coo_tensor(
|
209
|
+
torch.stack([row_id, topk_idx], dim=-1).reshape(-1, 2).T,
|
210
|
+
topk_sim.reshape(-1),
|
211
|
+
size=(_A.shape[0], _A.shape[1]),
|
212
|
+
device=_A.device,
|
213
|
+
)
|
214
|
+
_A = _A.to_dense().to(dtype=subgraph_output.dtype)
|
215
|
+
_D = _A.sum(-1)
|
216
|
+
_A /= _D[:, None]
|
194
217
|
|
195
218
|
_V = _A @ subgraph_output
|
196
219
|
if move_output_to_cpu:
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.6
|
4
4
|
Summary: Normalized Cut and Nyström Approximation
|
5
5
|
Author-email: Huzheng Yang <huze.yann@gmail.com>, Wentinn Liao <wentinn.liao@gmail.com>
|
6
6
|
Project-URL: Documentation, https://github.com/JophiArcana/Nystrom-NCUT/
|
@@ -38,17 +38,18 @@ if __name__ == "__main__":
|
|
38
38
|
# raise Exception(
|
39
39
|
|
40
40
|
torch.set_printoptions(precision=8, sci_mode=False, linewidth=400)
|
41
|
-
torch.set_default_dtype(torch.
|
41
|
+
torch.set_default_dtype(torch.float32)
|
42
42
|
torch.manual_seed(1212)
|
43
43
|
np.random.seed(1212)
|
44
44
|
|
45
|
-
M = torch.rand((
|
46
|
-
NC = NCUT(n_components=
|
45
|
+
M = torch.rand((1200, 12))
|
46
|
+
NC = NCUT(n_components=30, num_sample=1000, sample_method="farthest", eig_solver="svd")
|
47
47
|
|
48
48
|
torch.manual_seed(1212)
|
49
49
|
np.random.seed(1212)
|
50
50
|
X, eigs = NC.fit_transform(M)
|
51
51
|
print(eigs)
|
52
|
+
# print(X.mT @ X)
|
52
53
|
|
53
54
|
normalized_M = Fn.normalize(M, p=2, dim=-1)
|
54
55
|
A = torch.exp(-(1 - normalized_M @ normalized_M.mT))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|