nystrom-ncut 0.0.7__py3-none-any.whl → 0.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import logging
2
- from typing import Literal, Tuple
2
+ from typing import Tuple
3
3
 
4
4
  import torch
5
5
  import torch.nn.functional as Fn
@@ -98,7 +98,11 @@ def distance_from_features(
98
98
  D = torch.cdist(features, features_B, p=2)
99
99
  elif distance == "rbf":
100
100
  D = torch.cdist(features, features_B, p=2) ** 2
101
- D = D / (2 * features.var(dim=0).sum())
101
+
102
+ # Outlier-robust scale invariance using quantiles to estimate standard deviation
103
+ stds = torch.quantile(features, q=torch.tensor((0.158655, 0.841345), device=features.device), dim=0)
104
+ stds = (stds[1] - stds[0]) / 2
105
+ D = D / (2 * torch.linalg.norm(stds) ** 2)
102
106
  else:
103
107
  raise ValueError("distance should be 'cosine' or 'euclidean', 'rbf'")
104
108
  return D
@@ -178,39 +182,17 @@ def extrapolate_knn(
178
182
  V_list = []
179
183
  for _v in torch.chunk(extrapolation_features, n_chunks, dim=0):
180
184
  _v = _v.to(device) # [_m x d]
185
+
181
186
  _A = affinity_from_features(anchor_features, _v, affinity_focal_gamma, distance).mT # [_m x n]
182
187
  if knn is not None:
183
188
  _A, indices = _A.topk(k=knn, dim=-1, largest=True) # [_m x k], [_m x k]
184
189
  _anchor_output = anchor_output[indices] # [_m x k x d]
185
190
  else:
186
191
  _anchor_output = anchor_output[None] # [1 x n x d]
187
- _A = Fn.normalize(_A, p=1, dim=-1)
188
-
189
- # if distance == 'cosine':
190
- # _A = _v @ subgraph_features.T
191
- # elif distance == 'euclidean':
192
- # _A = - torch.cdist(_v, subgraph_features, p=2)
193
- # elif distance == 'rbf':
194
- # _A = - torch.cdist(_v, subgraph_features, p=2) ** 2
195
- # else:
196
- # raise ValueError("distance should be 'cosine' or 'euclidean', 'rbf'")
197
- #
198
- # # keep topk KNN for each row
199
- # topk_sim, topk_idx = _A.topk(knn, dim=-1, largest=True)
200
- # row_id = torch.arange(topk_idx.shape[0], device=_A.device)[:, None].expand(
201
- # -1, topk_idx.shape[1]
202
- # )
203
- # _A = torch.sparse_coo_tensor(
204
- # torch.stack([row_id, topk_idx], dim=-1).reshape(-1, 2).T,
205
- # topk_sim.reshape(-1),
206
- # size=(_A.shape[0], _A.shape[1]),
207
- # device=_A.device,
208
- # )
209
- # _A = _A.to_dense().to(dtype=subgraph_output.dtype)
210
- # _D = _A.sum(-1)
211
- # _A /= _D[:, None]
212
-
213
- _V = (_A[:, None, :] @ _anchor_output).squeeze(1)
192
+
193
+ _A = Fn.normalize(_A, p=1, dim=-1) # [_m x k]
194
+ _V = (_A[:, None, :] @ _anchor_output).squeeze(1) # [_m x d]
195
+
214
196
  if move_output_to_cpu:
215
197
  _V = _V.cpu()
216
198
  V_list.append(_V)
@@ -38,14 +38,9 @@ def _rgb_with_dimensionality_reduction(
38
38
  ) -> Tuple[torch.Tensor, torch.Tensor]:
39
39
 
40
40
  if pre_smooth:
41
- _subgraph_indices = run_subgraph_sampling(
42
- features,
43
- num_sample,
44
- sample_method="farthest",
45
- )
46
41
  features = extrapolate_knn(
47
- features[_subgraph_indices],
48
- features[_subgraph_indices],
42
+ features,
43
+ features,
49
44
  features,
50
45
  distance="cosine",
51
46
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nystrom_ncut
3
- Version: 0.0.7
3
+ Version: 0.0.8
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/
@@ -0,0 +1,11 @@
1
+ nystrom_ncut/__init__.py,sha256=Vlc_iAlfvTNUiJXpZLWUOaL2Q-YqZqgr7WoG6cVnD0g,439
2
+ nystrom_ncut/common.py,sha256=G6w_8_BfBUMc6r8WFgA0NH4K6am7AzZCSdrQEVjra7U,671
3
+ nystrom_ncut/ncut_pytorch.py,sha256=-SKs9AdkafJSGkeYt4LwhbKZr8oq9JA5caAqjiVDAzU,11220
4
+ nystrom_ncut/nystrom.py,sha256=-l26oiJ0oPReSGlMlYV3gftszgFdAAHAi7OFtGPZ4Ic,8802
5
+ nystrom_ncut/propagation_utils.py,sha256=0d2VhT0JrLRurd44hZbnxBvBh-QscPKxtV7VrwYtTdo,11569
6
+ nystrom_ncut/visualize_utils.py,sha256=jDjuyZ9rdd25jqrPObJgK8zCLHc3Oms0fQnaIetHk-U,17112
7
+ nystrom_ncut-0.0.8.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
8
+ nystrom_ncut-0.0.8.dist-info/METADATA,sha256=zQpx3REOOckpJSuc7N6UNpXZoqgsM5UoFWV6__DuaRQ,6058
9
+ nystrom_ncut-0.0.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ nystrom_ncut-0.0.8.dist-info/top_level.txt,sha256=j7g_j0S048EvguFFnGgD5Ewd3r2H6klsxd5A4dd-wHw,13
11
+ nystrom_ncut-0.0.8.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- nystrom_ncut/__init__.py,sha256=Vlc_iAlfvTNUiJXpZLWUOaL2Q-YqZqgr7WoG6cVnD0g,439
2
- nystrom_ncut/common.py,sha256=G6w_8_BfBUMc6r8WFgA0NH4K6am7AzZCSdrQEVjra7U,671
3
- nystrom_ncut/ncut_pytorch.py,sha256=S_nrD3ecK9PX91ZRWu3AVHsXN3V5lse7oRs4P0rDT0Y,11229
4
- nystrom_ncut/nystrom.py,sha256=-l26oiJ0oPReSGlMlYV3gftszgFdAAHAi7OFtGPZ4Ic,8802
5
- nystrom_ncut/propagation_utils.py,sha256=t8pHp4VjqEeCNWl5jIu79WhQzINj982n-z2UAcxnEUY,12181
6
- nystrom_ncut/visualize_utils.py,sha256=17z3kTUHWb9ZKF_UfNIMGESI7YrjxaHYIq-0xJ02bng,17295
7
- nystrom_ncut-0.0.7.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
8
- nystrom_ncut-0.0.7.dist-info/METADATA,sha256=q7lIa-_S1iEbNoV2ml_0TbOuCGOSAuq-0ryJc1HAf0k,6058
9
- nystrom_ncut-0.0.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- nystrom_ncut-0.0.7.dist-info/top_level.txt,sha256=j7g_j0S048EvguFFnGgD5Ewd3r2H6klsxd5A4dd-wHw,13
11
- nystrom_ncut-0.0.7.dist-info/RECORD,,