nystrom-ncut 0.1.2__py3-none-any.whl → 0.1.3__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.
- nystrom_ncut/__init__.py +1 -0
- nystrom_ncut/distance_utils.py +3 -1
- nystrom_ncut/nystrom/nystrom_utils.py +2 -2
- nystrom_ncut/sampling_utils.py +4 -15
- nystrom_ncut/visualize_utils.py +4 -4
- {nystrom_ncut-0.1.2.dist-info → nystrom_ncut-0.1.3.dist-info}/METADATA +1 -1
- nystrom_ncut-0.1.3.dist-info/RECORD +15 -0
- nystrom_ncut-0.1.2.dist-info/RECORD +0 -15
- {nystrom_ncut-0.1.2.dist-info → nystrom_ncut-0.1.3.dist-info}/LICENSE +0 -0
- {nystrom_ncut-0.1.2.dist-info → nystrom_ncut-0.1.3.dist-info}/WHEEL +0 -0
- {nystrom_ncut-0.1.2.dist-info → nystrom_ncut-0.1.3.dist-info}/top_level.txt +0 -0
nystrom_ncut/__init__.py
CHANGED
nystrom_ncut/distance_utils.py
CHANGED
@@ -41,7 +41,9 @@ def distance_from_features(
|
|
41
41
|
D = torch.cdist(features, features_B, p=2) ** 2
|
42
42
|
|
43
43
|
# Outlier-robust scale invariance using quantiles to estimate standard deviation
|
44
|
-
|
44
|
+
c = 2.0
|
45
|
+
p = torch.erf(torch.tensor((-c, c), device=features.device) * (2 ** -0.5))
|
46
|
+
stds = torch.quantile(features, q=(p + 1) / 2, dim=0)
|
45
47
|
stds = (stds[1] - stds[0]) / 2
|
46
48
|
D = D / (2 * torch.linalg.norm(stds) ** 2)
|
47
49
|
else:
|
@@ -12,7 +12,7 @@ from ..distance_utils import (
|
|
12
12
|
)
|
13
13
|
from ..sampling_utils import (
|
14
14
|
SampleConfig,
|
15
|
-
|
15
|
+
subsample_features,
|
16
16
|
)
|
17
17
|
|
18
18
|
|
@@ -180,7 +180,7 @@ class OnlineNystromSubsampleFit(OnlineNystrom):
|
|
180
180
|
if precomputed_sampled_indices is not None:
|
181
181
|
self.anchor_indices = precomputed_sampled_indices
|
182
182
|
else:
|
183
|
-
self.anchor_indices =
|
183
|
+
self.anchor_indices = subsample_features(
|
184
184
|
features=features,
|
185
185
|
disttype=self.distance,
|
186
186
|
config=self.sample_config,
|
nystrom_ncut/sampling_utils.py
CHANGED
@@ -3,11 +3,10 @@ from dataclasses import dataclass
|
|
3
3
|
from typing import Literal
|
4
4
|
|
5
5
|
import torch
|
6
|
-
from
|
6
|
+
from pytorch3d.ops import sample_farthest_points
|
7
7
|
|
8
8
|
from .distance_utils import (
|
9
9
|
DistanceOptions,
|
10
|
-
affinity_from_features,
|
11
10
|
to_euclidean,
|
12
11
|
)
|
13
12
|
|
@@ -25,7 +24,7 @@ class SampleConfig:
|
|
25
24
|
|
26
25
|
|
27
26
|
@torch.no_grad()
|
28
|
-
def
|
27
|
+
def subsample_features(
|
29
28
|
features: torch.Tensor,
|
30
29
|
disttype: DistanceOptions,
|
31
30
|
config: SampleConfig,
|
@@ -57,25 +56,15 @@ def run_subgraph_sampling(
|
|
57
56
|
|
58
57
|
elif config.method == "fps_recursive":
|
59
58
|
features = to_euclidean(features, disttype)
|
60
|
-
sampled_indices =
|
59
|
+
sampled_indices = subsample_features(
|
61
60
|
features=features,
|
62
61
|
disttype=disttype,
|
63
62
|
config=SampleConfig(method="fps", num_sample=config.num_sample, fps_dim=config.fps_dim)
|
64
63
|
)
|
65
|
-
|
66
64
|
nc = config._ncut_obj
|
67
|
-
|
68
|
-
A = affinity_from_features(features, affinity_focal_gamma=nc.kernel.affinity_focal_gamma, distance=nc.kernel.distance)
|
69
|
-
R = torch.diag(torch.sum(A, dim=-1) ** -0.5)
|
70
|
-
L = R @ A @ R
|
71
|
-
|
72
65
|
for _ in range(config.n_iter):
|
73
66
|
fps_features, eigenvalues = nc.fit_transform(features, precomputed_sampled_indices=sampled_indices)
|
74
67
|
|
75
|
-
_L = fps_features @ torch.diag(eigenvalues) @ fps_features.mT
|
76
|
-
RE = torch.abs(_L / L - 1)
|
77
|
-
|
78
|
-
print(f"Iteration {_} --- max: {RE.max().item()}, mean: {RE.mean().item()}, min: {RE.min().item()}")
|
79
68
|
fps_features = to_euclidean(fps_features[:, :config.fps_dim], "cosine")
|
80
69
|
sampled_indices = torch.sort(fpsample(fps_features, config)).values
|
81
70
|
else:
|
@@ -93,4 +82,4 @@ def fpsample(
|
|
93
82
|
U, S, V = torch.pca_lowrank(features, q=config.fps_dim)
|
94
83
|
features = U * S
|
95
84
|
|
96
|
-
return
|
85
|
+
return sample_farthest_points(features[None], K=config.num_sample)[1][0]
|
nystrom_ncut/visualize_utils.py
CHANGED
@@ -19,7 +19,7 @@ from .distance_utils import (
|
|
19
19
|
)
|
20
20
|
from .sampling_utils import (
|
21
21
|
SampleConfig,
|
22
|
-
|
22
|
+
subsample_features,
|
23
23
|
)
|
24
24
|
|
25
25
|
|
@@ -120,7 +120,7 @@ def extrapolate_knn_with_subsampling(
|
|
120
120
|
device = full_output.device if device is None else device
|
121
121
|
|
122
122
|
# sample subgraph
|
123
|
-
anchor_indices =
|
123
|
+
anchor_indices = subsample_features(
|
124
124
|
features=full_features,
|
125
125
|
disttype=distance,
|
126
126
|
config=sample_config,
|
@@ -160,7 +160,7 @@ def _rgb_with_dimensionality_reduction(
|
|
160
160
|
) -> torch.Tensor:
|
161
161
|
|
162
162
|
if True:
|
163
|
-
_subgraph_indices =
|
163
|
+
_subgraph_indices = subsample_features(
|
164
164
|
features=features,
|
165
165
|
disttype=disttype,
|
166
166
|
config=SampleConfig(method="fps"),
|
@@ -172,7 +172,7 @@ def _rgb_with_dimensionality_reduction(
|
|
172
172
|
distance=disttype,
|
173
173
|
)
|
174
174
|
|
175
|
-
subgraph_indices =
|
175
|
+
subgraph_indices = subsample_features(
|
176
176
|
features=features,
|
177
177
|
disttype=disttype,
|
178
178
|
config=SampleConfig(method="fps", num_sample=num_sample),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
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,15 @@
|
|
1
|
+
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
nystrom_ncut/__init__.py,sha256=HifrTcqX2-hYjBDe6xIThHvuIBYMPBA3EzjR8-qPMUM,512
|
3
|
+
nystrom_ncut/common.py,sha256=_PGJoImSk_Fb_5Ri-e_IsFoCcSfbGS8CxYUUHVoNM50,2036
|
4
|
+
nystrom_ncut/distance_utils.py,sha256=xSMKL-sFGrz0EL106vhVx0qSk3iSdSLRFhGL0KmAOnU,3121
|
5
|
+
nystrom_ncut/sampling_utils.py,sha256=7zCneqmkaA_fUkaZcykFjHtn7pxdZdsjAbKxJplegc0,2960
|
6
|
+
nystrom_ncut/visualize_utils.py,sha256=RsQVjPhxoIdxDOQ2PI7ifFDuEL23YXpZBdJ0wjjafek,22970
|
7
|
+
nystrom_ncut/nystrom/__init__.py,sha256=4EpxD3Cmc8Fif4vo8DG-6FpTfCnNanD5zCZxK3WrMwQ,121
|
8
|
+
nystrom_ncut/nystrom/distance_realization.py,sha256=9GX_XSISTvsEWUu8bG5AxtlkYYNItFspcH5wXiwSOKY,5789
|
9
|
+
nystrom_ncut/nystrom/normalized_cut.py,sha256=ZxFV8Sckp6wtpNyoA15DS7Vfu9QLvzNpwrwY0n9_GNs,6953
|
10
|
+
nystrom_ncut/nystrom/nystrom_utils.py,sha256=Wq364xlxBhr74lqyCkPWLBxq5YSt2zr-DSfYUHpYfgE,12989
|
11
|
+
nystrom_ncut-0.1.3.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
12
|
+
nystrom_ncut-0.1.3.dist-info/METADATA,sha256=tK9gbt1b0c5mGNm2e0OdAKQm7rFUWCuhn9myh_Vf408,6058
|
13
|
+
nystrom_ncut-0.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
14
|
+
nystrom_ncut-0.1.3.dist-info/top_level.txt,sha256=gM8IWWHYysIRTCvCTcdS4RShOyl9pxpylgSwPUZR2XM,22
|
15
|
+
nystrom_ncut-0.1.3.dist-info/RECORD,,
|
@@ -1,15 +0,0 @@
|
|
1
|
-
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
nystrom_ncut/__init__.py,sha256=Wgud0tGaNkK2m_qVU47rXQqKdoR-4ztDXXD9UKzc4c8,488
|
3
|
-
nystrom_ncut/common.py,sha256=_PGJoImSk_Fb_5Ri-e_IsFoCcSfbGS8CxYUUHVoNM50,2036
|
4
|
-
nystrom_ncut/distance_utils.py,sha256=U1223ri8OuIzj0wjhAUhHWcsEvREDitgz8i1rRlCfj8,3069
|
5
|
-
nystrom_ncut/sampling_utils.py,sha256=uoWWSyfttv5fnOSq8KFXomWiNO-THiPPbLXfupnVar0,3444
|
6
|
-
nystrom_ncut/visualize_utils.py,sha256=xDlkE5sMXehK5hNz9U1twqgHZVzmV5tf5O9bL96AiaM,22982
|
7
|
-
nystrom_ncut/nystrom/__init__.py,sha256=4EpxD3Cmc8Fif4vo8DG-6FpTfCnNanD5zCZxK3WrMwQ,121
|
8
|
-
nystrom_ncut/nystrom/distance_realization.py,sha256=9GX_XSISTvsEWUu8bG5AxtlkYYNItFspcH5wXiwSOKY,5789
|
9
|
-
nystrom_ncut/nystrom/normalized_cut.py,sha256=ZxFV8Sckp6wtpNyoA15DS7Vfu9QLvzNpwrwY0n9_GNs,6953
|
10
|
-
nystrom_ncut/nystrom/nystrom_utils.py,sha256=MEmW5xgOu8u2HCwjFapHAOFFXhoVslBbLG4Cn-mYMDU,12995
|
11
|
-
nystrom_ncut-0.1.2.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
12
|
-
nystrom_ncut-0.1.2.dist-info/METADATA,sha256=0wsHYtW3cY4Bzq-lH_y_Blazt6YMrwWxsmR7SOHMyzs,6058
|
13
|
-
nystrom_ncut-0.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
14
|
-
nystrom_ncut-0.1.2.dist-info/top_level.txt,sha256=gM8IWWHYysIRTCvCTcdS4RShOyl9pxpylgSwPUZR2XM,22
|
15
|
-
nystrom_ncut-0.1.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|