nystrom-ncut 0.0.12__py3-none-any.whl → 0.1.0__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 -2
- nystrom_ncut/common.py +9 -0
- nystrom_ncut/nystrom/distance_realization.py +1 -0
- nystrom_ncut/nystrom/normalized_cut.py +1 -1
- nystrom_ncut/nystrom/nystrom.py +6 -2
- nystrom_ncut/propagation_utils.py +30 -20
- nystrom_ncut/visualize_utils.py +60 -66
- {nystrom_ncut-0.0.12.dist-info → nystrom_ncut-0.1.0.dist-info}/METADATA +1 -1
- nystrom_ncut-0.1.0.dist-info/RECORD +14 -0
- nystrom_ncut-0.0.12.dist-info/RECORD +0 -14
- {nystrom_ncut-0.0.12.dist-info → nystrom_ncut-0.1.0.dist-info}/LICENSE +0 -0
- {nystrom_ncut-0.0.12.dist-info → nystrom_ncut-0.1.0.dist-info}/WHEEL +0 -0
- {nystrom_ncut-0.0.12.dist-info → nystrom_ncut-0.1.0.dist-info}/top_level.txt +0 -0
nystrom_ncut/__init__.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
from .nystrom import (
|
2
|
-
DistanceRealization,
|
3
2
|
NCut,
|
4
3
|
axis_align,
|
5
4
|
)
|
@@ -15,7 +14,7 @@ from .visualize_utils import (
|
|
15
14
|
rgb_from_tsne_2d,
|
16
15
|
rgb_from_umap_3d,
|
17
16
|
rgb_from_umap_2d,
|
18
|
-
|
17
|
+
rgb_from_euclidean_tsne_3d,
|
19
18
|
rotate_rgb_cube,
|
20
19
|
convert_to_lab_color,
|
21
20
|
get_mask,
|
nystrom_ncut/common.py
CHANGED
@@ -24,6 +24,15 @@ def lazy_normalize(x: torch.Tensor, n: int = 1000, **normalize_kwargs: Any) -> t
|
|
24
24
|
return Fn.normalize(x, **normalize_kwargs)
|
25
25
|
|
26
26
|
|
27
|
+
def to_euclidean(x: torch.Tensor, disttype: DistanceOptions) -> torch.Tensor:
|
28
|
+
if disttype == "cosine":
|
29
|
+
return lazy_normalize(x, p=2, dim=-1)
|
30
|
+
elif disttype == "rbf":
|
31
|
+
return x
|
32
|
+
else:
|
33
|
+
raise ValueError(f"to_euclidean not implemented for disttype {disttype}.")
|
34
|
+
|
35
|
+
|
27
36
|
def quantile_min_max(x, q1=0.01, q2=0.99, n_sample=10000):
|
28
37
|
if x.shape[0] > n_sample:
|
29
38
|
np.random.seed(0)
|
@@ -122,6 +122,7 @@ class DistanceRealization(OnlineNystromSubsampleFit):
|
|
122
122
|
n_components=n_components,
|
123
123
|
kernel=GramKernel(distance, eig_solver),
|
124
124
|
num_sample=num_sample,
|
125
|
+
distance=distance,
|
125
126
|
sample_method=sample_method,
|
126
127
|
eig_solver=eig_solver,
|
127
128
|
chunk_size=chunk_size,
|
@@ -118,11 +118,11 @@ class NCut(OnlineNystromSubsampleFit):
|
|
118
118
|
n_components=n_components,
|
119
119
|
kernel=LaplacianKernel(affinity_focal_gamma, distance, eig_solver),
|
120
120
|
num_sample=num_sample,
|
121
|
+
distance=distance,
|
121
122
|
sample_method=sample_method,
|
122
123
|
eig_solver=eig_solver,
|
123
124
|
chunk_size=chunk_size,
|
124
125
|
)
|
125
|
-
self.distance: DistanceOptions = distance
|
126
126
|
|
127
127
|
|
128
128
|
def axis_align(eigen_vectors: torch.Tensor, max_iter=300):
|
nystrom_ncut/nystrom/nystrom.py
CHANGED
@@ -4,6 +4,7 @@ from typing import Literal, Tuple
|
|
4
4
|
import torch
|
5
5
|
|
6
6
|
from ..common import (
|
7
|
+
DistanceOptions,
|
7
8
|
SampleOptions,
|
8
9
|
ceildiv,
|
9
10
|
)
|
@@ -145,6 +146,7 @@ class OnlineNystromSubsampleFit(OnlineNystrom):
|
|
145
146
|
n_components: int,
|
146
147
|
kernel: OnlineKernel,
|
147
148
|
num_sample: int,
|
149
|
+
distance: DistanceOptions,
|
148
150
|
sample_method: SampleOptions,
|
149
151
|
eig_solver: EigSolverOptions = "svd_lowrank",
|
150
152
|
chunk_size: int = 8192,
|
@@ -157,6 +159,7 @@ class OnlineNystromSubsampleFit(OnlineNystrom):
|
|
157
159
|
chunk_size=chunk_size,
|
158
160
|
)
|
159
161
|
self.num_sample: int = num_sample
|
162
|
+
self.distance: DistanceOptions = distance
|
160
163
|
self.sample_method: SampleOptions = sample_method
|
161
164
|
self.anchor_indices: torch.Tensor = None
|
162
165
|
|
@@ -176,8 +179,9 @@ class OnlineNystromSubsampleFit(OnlineNystrom):
|
|
176
179
|
self.anchor_indices = precomputed_sampled_indices
|
177
180
|
else:
|
178
181
|
self.anchor_indices = run_subgraph_sampling(
|
179
|
-
features,
|
180
|
-
self.num_sample,
|
182
|
+
features=features,
|
183
|
+
num_sample=self.num_sample,
|
184
|
+
disttype=self.distance,
|
181
185
|
sample_method=self.sample_method,
|
182
186
|
)
|
183
187
|
sampled_features = features[self.anchor_indices]
|
@@ -9,15 +9,17 @@ from .common import (
|
|
9
9
|
SampleOptions,
|
10
10
|
ceildiv,
|
11
11
|
lazy_normalize,
|
12
|
+
to_euclidean,
|
12
13
|
)
|
13
14
|
|
14
15
|
|
15
|
-
@torch.no_grad()
|
16
|
+
# @torch.no_grad()
|
16
17
|
def run_subgraph_sampling(
|
17
18
|
features: torch.Tensor,
|
18
19
|
num_sample: int,
|
20
|
+
disttype: DistanceOptions,
|
21
|
+
sample_method: SampleOptions,
|
19
22
|
max_draw: int = 1000000,
|
20
|
-
sample_method: SampleOptions = "farthest",
|
21
23
|
):
|
22
24
|
if num_sample >= features.shape[0]:
|
23
25
|
# if too many samples, use all samples and bypass Nystrom-like approximation
|
@@ -28,6 +30,7 @@ def run_subgraph_sampling(
|
|
28
30
|
else:
|
29
31
|
# sample subgraph
|
30
32
|
if sample_method == "farthest": # default
|
33
|
+
features = to_euclidean(features, disttype)
|
31
34
|
if num_sample > max_draw:
|
32
35
|
logging.warning(
|
33
36
|
f"num_sample is larger than max_draw, apply farthest point sampling on random sampled {max_draw} samples"
|
@@ -144,12 +147,12 @@ def extrapolate_knn(
|
|
144
147
|
anchor_features: torch.Tensor, # [n x d]
|
145
148
|
anchor_output: torch.Tensor, # [n x d']
|
146
149
|
extrapolation_features: torch.Tensor, # [m x d]
|
150
|
+
distance: DistanceOptions,
|
147
151
|
knn: int = 10, # k
|
148
|
-
distance: DistanceOptions = "cosine",
|
149
152
|
affinity_focal_gamma: float = 1.0,
|
150
153
|
chunk_size: int = 8192,
|
151
154
|
device: str = None,
|
152
|
-
move_output_to_cpu: bool = False
|
155
|
+
move_output_to_cpu: bool = False,
|
153
156
|
) -> torch.Tensor: # [m x d']
|
154
157
|
"""A generic function to propagate new nodes using KNN.
|
155
158
|
|
@@ -168,7 +171,7 @@ def extrapolate_knn(
|
|
168
171
|
>>> old_eigenvectors = torch.randn(3000, 20)
|
169
172
|
>>> old_features = torch.randn(3000, 100)
|
170
173
|
>>> new_features = torch.randn(200, 100)
|
171
|
-
>>> new_eigenvectors = extrapolate_knn(old_features,old_eigenvectors,new_features,knn=3)
|
174
|
+
>>> new_eigenvectors = extrapolate_knn(old_features, old_eigenvectors, new_features, knn=3)
|
172
175
|
>>> # new_eigenvectors.shape = (200, 20)
|
173
176
|
|
174
177
|
"""
|
@@ -197,21 +200,24 @@ def extrapolate_knn(
|
|
197
200
|
_V = _V.cpu()
|
198
201
|
V_list.append(_V)
|
199
202
|
|
200
|
-
|
201
|
-
return
|
203
|
+
extrapolation_output = torch.cat(V_list, dim=0)
|
204
|
+
return extrapolation_output
|
202
205
|
|
203
206
|
|
204
207
|
# wrapper functions for adding new nodes to existing graph
|
205
208
|
def extrapolate_knn_with_subsampling(
|
206
|
-
full_features: torch.Tensor,
|
207
|
-
full_output: torch.Tensor,
|
208
|
-
extrapolation_features: torch.Tensor,
|
209
|
-
|
210
|
-
num_sample: int,
|
209
|
+
full_features: torch.Tensor, # [n x d]
|
210
|
+
full_output: torch.Tensor, # [n x d']
|
211
|
+
extrapolation_features: torch.Tensor, # [m x d]
|
212
|
+
num_sample: int, # n'
|
211
213
|
sample_method: SampleOptions,
|
212
|
-
|
213
|
-
|
214
|
-
|
214
|
+
distance: DistanceOptions,
|
215
|
+
knn: int = 10, # k
|
216
|
+
affinity_focal_gamma: float = 1.0,
|
217
|
+
chunk_size: int = 8192,
|
218
|
+
device: str = None,
|
219
|
+
move_output_to_cpu: bool = False,
|
220
|
+
) -> torch.Tensor: # [m x d']
|
215
221
|
"""Propagate eigenvectors to new nodes using KNN. Note: this is equivalent to the class API `NCUT.tranform(new_features)`, expect for the sampling is re-done in this function.
|
216
222
|
Args:
|
217
223
|
full_output (torch.Tensor): eigenvectors from existing nodes, shape (num_sample, num_eig)
|
@@ -237,8 +243,9 @@ def extrapolate_knn_with_subsampling(
|
|
237
243
|
|
238
244
|
# sample subgraph
|
239
245
|
anchor_indices = run_subgraph_sampling(
|
240
|
-
full_features,
|
241
|
-
num_sample,
|
246
|
+
features=full_features,
|
247
|
+
num_sample=num_sample,
|
248
|
+
disttype=distance,
|
242
249
|
sample_method=sample_method,
|
243
250
|
)
|
244
251
|
|
@@ -247,12 +254,15 @@ def extrapolate_knn_with_subsampling(
|
|
247
254
|
extrapolation_features = extrapolation_features.to(device)
|
248
255
|
|
249
256
|
# propagate eigenvectors from subgraph to new nodes
|
250
|
-
|
257
|
+
extrapolation_output = extrapolate_knn(
|
251
258
|
anchor_features,
|
252
259
|
anchor_output,
|
253
260
|
extrapolation_features,
|
261
|
+
distance,
|
254
262
|
knn=knn,
|
263
|
+
affinity_focal_gamma=affinity_focal_gamma,
|
255
264
|
chunk_size=chunk_size,
|
256
|
-
device=device
|
265
|
+
device=device,
|
266
|
+
move_output_to_cpu=move_output_to_cpu,
|
257
267
|
)
|
258
|
-
return
|
268
|
+
return extrapolation_output
|
nystrom_ncut/visualize_utils.py
CHANGED
@@ -8,6 +8,7 @@ from sklearn.base import BaseEstimator
|
|
8
8
|
|
9
9
|
from .common import (
|
10
10
|
lazy_normalize,
|
11
|
+
to_euclidean,
|
11
12
|
quantile_min_max,
|
12
13
|
quantile_normalize,
|
13
14
|
)
|
@@ -20,76 +21,72 @@ from .propagation_utils import (
|
|
20
21
|
)
|
21
22
|
|
22
23
|
|
23
|
-
def _identity(X: torch.Tensor) -> torch.Tensor:
|
24
|
-
return X
|
25
|
-
|
26
|
-
|
27
24
|
def _rgb_with_dimensionality_reduction(
|
28
25
|
features: torch.Tensor,
|
29
26
|
num_sample: int,
|
30
|
-
|
27
|
+
disttype: Literal["cosine", "euclidean"],
|
31
28
|
rgb_func: Callable[[torch.Tensor, float], torch.Tensor],
|
32
29
|
q: float,
|
33
30
|
knn: int,
|
34
31
|
reduction: Callable[..., BaseEstimator],
|
35
32
|
reduction_dim: int,
|
36
33
|
reduction_kwargs: Dict[str, Any],
|
37
|
-
transform_func: Callable[[torch.Tensor], torch.Tensor],
|
38
34
|
seed: int,
|
39
35
|
device: str,
|
40
|
-
) ->
|
36
|
+
) -> torch.Tensor:
|
41
37
|
|
42
38
|
if True:
|
43
39
|
_subgraph_indices = run_subgraph_sampling(
|
44
|
-
features,
|
40
|
+
features=features,
|
45
41
|
num_sample=10000,
|
42
|
+
disttype=disttype,
|
46
43
|
sample_method="farthest",
|
47
44
|
)
|
48
45
|
features = extrapolate_knn(
|
49
|
-
features[_subgraph_indices],
|
50
|
-
features[_subgraph_indices],
|
51
|
-
features,
|
52
|
-
distance=
|
46
|
+
anchor_features=features[_subgraph_indices],
|
47
|
+
anchor_output=features[_subgraph_indices],
|
48
|
+
extrapolation_features=features,
|
49
|
+
distance=disttype,
|
53
50
|
)
|
54
51
|
|
55
52
|
subgraph_indices = run_subgraph_sampling(
|
56
|
-
features,
|
57
|
-
num_sample,
|
53
|
+
features=features,
|
54
|
+
num_sample=num_sample,
|
55
|
+
disttype=disttype,
|
58
56
|
sample_method="farthest",
|
59
57
|
)
|
60
58
|
|
61
59
|
_inp = features[subgraph_indices].numpy(force=True)
|
62
60
|
_subgraph_embed = reduction(
|
63
61
|
n_components=reduction_dim,
|
64
|
-
metric=
|
62
|
+
metric=disttype,
|
65
63
|
random_state=seed,
|
66
64
|
**reduction_kwargs
|
67
65
|
).fit_transform(_inp)
|
68
66
|
|
69
67
|
_subgraph_embed = torch.tensor(_subgraph_embed, dtype=torch.float32)
|
70
|
-
|
68
|
+
rgb = rgb_func(extrapolate_knn(
|
71
69
|
features[subgraph_indices],
|
72
70
|
_subgraph_embed,
|
73
71
|
features,
|
72
|
+
disttype,
|
74
73
|
knn=knn,
|
75
|
-
distance=metric,
|
76
74
|
device=device,
|
77
75
|
move_output_to_cpu=True
|
78
|
-
))
|
79
|
-
rgb
|
80
|
-
return X_nd, rgb
|
76
|
+
), q)
|
77
|
+
return rgb
|
81
78
|
|
82
79
|
|
83
80
|
def rgb_from_tsne_2d(
|
84
81
|
features: torch.Tensor,
|
85
82
|
num_sample: int = 1000,
|
83
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
86
84
|
perplexity: int = 150,
|
87
|
-
metric: Literal["cosine", "euclidean"] = "cosine",
|
88
85
|
q: float = 0.95,
|
89
86
|
knn: int = 10,
|
90
87
|
seed: int = 0,
|
91
88
|
device: str = None,
|
92
|
-
):
|
89
|
+
) -> torch.Tensor:
|
93
90
|
"""
|
94
91
|
Returns:
|
95
92
|
(torch.Tensor): Embedding in 2D, shape (n_samples, 2)
|
@@ -108,32 +105,32 @@ def rgb_from_tsne_2d(
|
|
108
105
|
)
|
109
106
|
perplexity = num_sample // 2
|
110
107
|
|
111
|
-
|
108
|
+
rgb = _rgb_with_dimensionality_reduction(
|
112
109
|
features=features,
|
113
110
|
num_sample=num_sample,
|
114
|
-
|
111
|
+
disttype=disttype,
|
115
112
|
rgb_func=rgb_from_2d_colormap,
|
116
113
|
q=q,
|
117
114
|
knn=knn,
|
118
115
|
reduction=TSNE, reduction_dim=2, reduction_kwargs={
|
119
116
|
"perplexity": perplexity,
|
120
|
-
},
|
117
|
+
},
|
121
118
|
seed=seed,
|
122
119
|
device=device,
|
123
120
|
)
|
124
|
-
return
|
121
|
+
return rgb
|
125
122
|
|
126
123
|
|
127
124
|
def rgb_from_tsne_3d(
|
128
125
|
features: torch.Tensor,
|
129
126
|
num_sample: int = 1000,
|
127
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
130
128
|
perplexity: int = 150,
|
131
|
-
metric: Literal["cosine", "euclidean"] = "cosine",
|
132
129
|
q: float = 0.95,
|
133
130
|
knn: int = 10,
|
134
131
|
seed: int = 0,
|
135
132
|
device: str = None,
|
136
|
-
):
|
133
|
+
) -> torch.Tensor:
|
137
134
|
"""
|
138
135
|
Returns:
|
139
136
|
(torch.Tensor): Embedding in 3D, shape (n_samples, 3)
|
@@ -152,31 +149,32 @@ def rgb_from_tsne_3d(
|
|
152
149
|
)
|
153
150
|
perplexity = num_sample // 2
|
154
151
|
|
155
|
-
|
152
|
+
rgb = _rgb_with_dimensionality_reduction(
|
156
153
|
features=features,
|
157
154
|
num_sample=num_sample,
|
158
|
-
|
155
|
+
disttype=disttype,
|
159
156
|
rgb_func=rgb_from_3d_rgb_cube,
|
160
157
|
q=q,
|
161
158
|
knn=knn,
|
162
159
|
reduction=TSNE, reduction_dim=3, reduction_kwargs={
|
163
160
|
"perplexity": perplexity,
|
164
|
-
},
|
161
|
+
},
|
165
162
|
seed=seed,
|
166
163
|
device=device,
|
167
164
|
)
|
168
|
-
return
|
165
|
+
return rgb
|
169
166
|
|
170
167
|
|
171
|
-
def
|
168
|
+
def rgb_from_euclidean_tsne_3d(
|
172
169
|
features: torch.Tensor,
|
173
170
|
num_sample: int = 1000,
|
171
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
174
172
|
perplexity: int = 150,
|
175
173
|
q: float = 0.95,
|
176
174
|
knn: int = 10,
|
177
175
|
seed: int = 0,
|
178
176
|
device: str = None
|
179
|
-
):
|
177
|
+
) -> torch.Tensor:
|
180
178
|
"""
|
181
179
|
Returns:
|
182
180
|
(torch.Tensor): Embedding in 3D, shape (n_samples, 3)
|
@@ -195,40 +193,36 @@ def rgb_from_cosine_tsne_3d(
|
|
195
193
|
)
|
196
194
|
perplexity = num_sample // 2
|
197
195
|
|
198
|
-
def
|
199
|
-
|
200
|
-
return dr.fit_transform(X)
|
201
|
-
|
202
|
-
def rgb_from_cosine(X_3d: torch.Tensor, q: float) -> torch.Tensor:
|
203
|
-
return rgb_from_3d_rgb_cube(cosine_to_rbf(X_3d), q=q)
|
196
|
+
def rgb_func(X_3d: torch.Tensor, q: float) -> torch.Tensor:
|
197
|
+
return rgb_from_3d_rgb_cube(to_euclidean(X_3d, disttype), q=q)
|
204
198
|
|
205
|
-
|
199
|
+
rgb = _rgb_with_dimensionality_reduction(
|
206
200
|
features=features,
|
207
201
|
num_sample=num_sample,
|
208
|
-
|
209
|
-
rgb_func=
|
202
|
+
disttype="cosine",
|
203
|
+
rgb_func=rgb_func,
|
210
204
|
q=q,
|
211
205
|
knn=knn,
|
212
206
|
reduction=TSNE, reduction_dim=3, reduction_kwargs={
|
213
207
|
"perplexity": perplexity,
|
214
|
-
},
|
208
|
+
},
|
215
209
|
seed=seed,
|
216
210
|
device=device,
|
217
211
|
)
|
218
|
-
return
|
212
|
+
return rgb
|
219
213
|
|
220
214
|
|
221
215
|
def rgb_from_umap_2d(
|
222
216
|
features: torch.Tensor,
|
223
217
|
num_sample: int = 1000,
|
218
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
224
219
|
n_neighbors: int = 150,
|
225
220
|
min_dist: float = 0.1,
|
226
|
-
metric: Literal["cosine", "euclidean"] = "cosine",
|
227
221
|
q: float = 0.95,
|
228
222
|
knn: int = 10,
|
229
223
|
seed: int = 0,
|
230
224
|
device: str = None,
|
231
|
-
):
|
225
|
+
) -> torch.Tensor:
|
232
226
|
"""
|
233
227
|
Returns:
|
234
228
|
(torch.Tensor): Embedding in 2D, shape (n_samples, 2)
|
@@ -239,34 +233,34 @@ def rgb_from_umap_2d(
|
|
239
233
|
except ImportError:
|
240
234
|
raise ImportError("umap import failed, please install `pip install umap-learn`")
|
241
235
|
|
242
|
-
|
236
|
+
rgb = _rgb_with_dimensionality_reduction(
|
243
237
|
features=features,
|
244
238
|
num_sample=num_sample,
|
245
|
-
|
239
|
+
disttype=disttype,
|
246
240
|
rgb_func=rgb_from_2d_colormap,
|
247
241
|
q=q,
|
248
242
|
knn=knn,
|
249
243
|
reduction=UMAP, reduction_dim=2, reduction_kwargs={
|
250
244
|
"n_neighbors": n_neighbors,
|
251
245
|
"min_dist": min_dist,
|
252
|
-
},
|
246
|
+
},
|
253
247
|
seed=seed,
|
254
248
|
device=device,
|
255
249
|
)
|
256
|
-
return
|
250
|
+
return rgb
|
257
251
|
|
258
252
|
|
259
253
|
def rgb_from_umap_sphere(
|
260
254
|
features: torch.Tensor,
|
261
255
|
num_sample: int = 1000,
|
256
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
262
257
|
n_neighbors: int = 150,
|
263
258
|
min_dist: float = 0.1,
|
264
|
-
metric: Literal["cosine", "euclidean"] = "cosine",
|
265
259
|
q: float = 0.95,
|
266
260
|
knn: int = 10,
|
267
261
|
seed: int = 0,
|
268
262
|
device: str = None,
|
269
|
-
):
|
263
|
+
) -> torch.Tensor:
|
270
264
|
"""
|
271
265
|
Returns:
|
272
266
|
(torch.Tensor): Embedding in 2D, shape (n_samples, 2)
|
@@ -277,37 +271,37 @@ def rgb_from_umap_sphere(
|
|
277
271
|
except ImportError:
|
278
272
|
raise ImportError("umap import failed, please install `pip install umap-learn`")
|
279
273
|
|
280
|
-
def
|
281
|
-
return torch.stack((
|
274
|
+
def rgb_func(X: torch.Tensor, q: float) -> torch.Tensor:
|
275
|
+
return rgb_from_3d_rgb_cube(torch.stack((
|
282
276
|
torch.sin(X[:, 0]) * torch.cos(X[:, 1]),
|
283
277
|
torch.sin(X[:, 0]) * torch.sin(X[:, 1]),
|
284
278
|
torch.cos(X[:, 0]),
|
285
|
-
), dim=1)
|
279
|
+
), dim=1), q=q)
|
286
280
|
|
287
|
-
|
281
|
+
rgb = _rgb_with_dimensionality_reduction(
|
288
282
|
features=features,
|
289
283
|
num_sample=num_sample,
|
290
|
-
|
291
|
-
rgb_func=
|
284
|
+
disttype=disttype,
|
285
|
+
rgb_func=rgb_func,
|
292
286
|
q=q,
|
293
287
|
knn=knn,
|
294
288
|
reduction=UMAP, reduction_dim=2, reduction_kwargs={
|
295
289
|
"n_neighbors": n_neighbors,
|
296
290
|
"min_dist": min_dist,
|
297
291
|
"output_metric": "haversine",
|
298
|
-
},
|
292
|
+
},
|
299
293
|
seed=seed,
|
300
294
|
device=device,
|
301
295
|
)
|
302
|
-
return
|
296
|
+
return rgb
|
303
297
|
|
304
298
|
|
305
299
|
def rgb_from_umap_3d(
|
306
300
|
features: torch.Tensor,
|
307
301
|
num_sample: int = 1000,
|
302
|
+
disttype: Literal["cosine", "euclidean"] = "cosine",
|
308
303
|
n_neighbors: int = 150,
|
309
304
|
min_dist: float = 0.1,
|
310
|
-
metric: Literal["cosine", "euclidean"] = "cosine",
|
311
305
|
q: float = 0.95,
|
312
306
|
knn: int = 10,
|
313
307
|
seed: int = 0,
|
@@ -323,21 +317,21 @@ def rgb_from_umap_3d(
|
|
323
317
|
except ImportError:
|
324
318
|
raise ImportError("umap import failed, please install `pip install umap-learn`")
|
325
319
|
|
326
|
-
|
320
|
+
rgb = _rgb_with_dimensionality_reduction(
|
327
321
|
features=features,
|
328
322
|
num_sample=num_sample,
|
329
|
-
|
323
|
+
disttype=disttype,
|
330
324
|
rgb_func=rgb_from_3d_rgb_cube,
|
331
325
|
q=q,
|
332
326
|
knn=knn,
|
333
327
|
reduction=UMAP, reduction_dim=3, reduction_kwargs={
|
334
328
|
"n_neighbors": n_neighbors,
|
335
329
|
"min_dist": min_dist,
|
336
|
-
},
|
330
|
+
},
|
337
331
|
seed=seed,
|
338
332
|
device=device,
|
339
333
|
)
|
340
|
-
return
|
334
|
+
return rgb
|
341
335
|
|
342
336
|
|
343
337
|
def flatten_sphere(X_3d):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.0
|
3
|
+
Version: 0.1.0
|
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,14 @@
|
|
1
|
+
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
nystrom_ncut/__init__.py,sha256=ffExLdGTaPsUweHcYc61Ose6a5A5Tfo9hm48zjEl6ho,441
|
3
|
+
nystrom_ncut/common.py,sha256=l5kjF6neukdtbMrt5bE69pN0JM9r-93JYltLlYJuBik,2227
|
4
|
+
nystrom_ncut/propagation_utils.py,sha256=79M61iJfp_RWj_xLOn51PHiextWcEWTQ7NWl2T51-3Y,10907
|
5
|
+
nystrom_ncut/visualize_utils.py,sha256=uGfBBkETQ8uRJ-UXPWpiXT8KEYMLmEHXPKJMLvN0c34,16543
|
6
|
+
nystrom_ncut/nystrom/__init__.py,sha256=4EpxD3Cmc8Fif4vo8DG-6FpTfCnNanD5zCZxK3WrMwQ,121
|
7
|
+
nystrom_ncut/nystrom/distance_realization.py,sha256=FGH7VjbtRrSROH0d8OPuCUxLQy5j7Z8BuE4hrSGGZG4,6031
|
8
|
+
nystrom_ncut/nystrom/normalized_cut.py,sha256=s9ZS3-tQbWnxAlPc01v9l7fqBhl28lvOalaCO2y-Gd8,7175
|
9
|
+
nystrom_ncut/nystrom/nystrom.py,sha256=OV5o9UL9fkrz9HdsD6rXh7MTsenPKrtCNRIczMuDS_4,12779
|
10
|
+
nystrom_ncut-0.1.0.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
11
|
+
nystrom_ncut-0.1.0.dist-info/METADATA,sha256=wAhGONU0ZM1VWoLqEwtfAs3_GUAt4CItkHq3ISuFyVE,6058
|
12
|
+
nystrom_ncut-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
13
|
+
nystrom_ncut-0.1.0.dist-info/top_level.txt,sha256=gM8IWWHYysIRTCvCTcdS4RShOyl9pxpylgSwPUZR2XM,22
|
14
|
+
nystrom_ncut-0.1.0.dist-info/RECORD,,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
nystrom_ncut/__init__.py,sha256=JKfF6atok5T9V692RhlhgeRO5a2cN-bfAVa9irmTLfs,463
|
3
|
-
nystrom_ncut/common.py,sha256=RMPQvg9R2s7V-q7zAStN9YCZt7gpc5Ut-KSKtvELBQ4,1934
|
4
|
-
nystrom_ncut/propagation_utils.py,sha256=WeWKxRBm01ITILMgjsit5_fCe9oW1kJOPmAjjcmliMo,10340
|
5
|
-
nystrom_ncut/visualize_utils.py,sha256=JkDyWML6k7k6S2Z7xnpbUvMWssEXcXqXu7gBy8wnids,16809
|
6
|
-
nystrom_ncut/nystrom/__init__.py,sha256=4EpxD3Cmc8Fif4vo8DG-6FpTfCnNanD5zCZxK3WrMwQ,121
|
7
|
-
nystrom_ncut/nystrom/distance_realization.py,sha256=MWSdfPfUnr7BdiKFkogjQvcGagvj7OzLQklnVp0fPx8,6000
|
8
|
-
nystrom_ncut/nystrom/normalized_cut.py,sha256=_U3zrbe6V-5TQ4uWmqckxs2JTIhygQlnRDTFBI1ghD4,7194
|
9
|
-
nystrom_ncut/nystrom/nystrom.py,sha256=nL-zxbEE_ygJEZEPmeNrUpVeffvxdrsTcbxFanFuXQY,12613
|
10
|
-
nystrom_ncut-0.0.12.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
11
|
-
nystrom_ncut-0.0.12.dist-info/METADATA,sha256=pM-WT6Ly-IKYJ3DV2d-oOyc--K4VOyArB0sT5gHfHL4,6059
|
12
|
-
nystrom_ncut-0.0.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
13
|
-
nystrom_ncut-0.0.12.dist-info/top_level.txt,sha256=gM8IWWHYysIRTCvCTcdS4RShOyl9pxpylgSwPUZR2XM,22
|
14
|
-
nystrom_ncut-0.0.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|