nystrom-ncut 0.0.7__tar.gz → 0.0.8__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nystrom_ncut"
7
- version = "0.0.7"
7
+ version = "0.0.8"
8
8
  authors = [
9
9
  { name = "Huzheng Yang", email = "huze.yann@gmail.com" },
10
10
  { name = "Wentinn Liao", email = "wentinn.liao@gmail.com" },
@@ -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/
File without changes
File without changes
File without changes
File without changes
File without changes