nystrom-ncut 0.1.0__py3-none-any.whl → 0.1.1__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/common.py CHANGED
@@ -33,7 +33,7 @@ def to_euclidean(x: torch.Tensor, disttype: DistanceOptions) -> torch.Tensor:
33
33
  raise ValueError(f"to_euclidean not implemented for disttype {disttype}.")
34
34
 
35
35
 
36
- def quantile_min_max(x, q1=0.01, q2=0.99, n_sample=10000):
36
+ def quantile_min_max(x: torch.Tensor, q1: float, q2: float, n_sample: int = 10000):
37
37
  if x.shape[0] > n_sample:
38
38
  np.random.seed(0)
39
39
  random_idx = np.random.choice(x.shape[0], n_sample, replace=False)
@@ -43,7 +43,7 @@ def quantile_min_max(x, q1=0.01, q2=0.99, n_sample=10000):
43
43
  return vmin, vmax
44
44
 
45
45
 
46
- def quantile_normalize(x, q=0.95):
46
+ def quantile_normalize(x: torch.Tensor, q: float = 0.95):
47
47
  """normalize each dimension of x to [0, 1], take 95-th percentage, this robust to outliers
48
48
  </br> 1. sort x
49
49
  </br> 2. take q-th quantile
@@ -1,5 +1,5 @@
1
1
  import logging
2
- from typing import Any, Callable, Dict, Literal, Tuple
2
+ from typing import Any, Callable, Dict, Literal
3
3
 
4
4
  import numpy as np
5
5
  import torch
@@ -12,9 +12,6 @@ from .common import (
12
12
  quantile_min_max,
13
13
  quantile_normalize,
14
14
  )
15
- from .nystrom import (
16
- DistanceRealization,
17
- )
18
15
  from .propagation_utils import (
19
16
  run_subgraph_sampling,
20
17
  extrapolate_knn,
@@ -334,14 +331,14 @@ def rgb_from_umap_3d(
334
331
  return rgb
335
332
 
336
333
 
337
- def flatten_sphere(X_3d):
338
- x = np.arctan2(X_3d[:, 0], X_3d[:, 1])
339
- y = -np.arccos(X_3d[:, 2])
340
- X_2d = np.stack([x, y], axis=1)
334
+ def flatten_sphere(X_3d: torch.Tensor) -> torch.Tensor:
335
+ x = torch.atan2(X_3d[:, 0], X_3d[:, 1])
336
+ y = -torch.acos(X_3d[:, 2])
337
+ X_2d = torch.stack((x, y), dim=1)
341
338
  return X_2d
342
339
 
343
340
 
344
- def rotate_rgb_cube(rgb, position=1):
341
+ def rotate_rgb_cube(rgb: torch.Tensor, position: int = 1) -> torch.Tensor:
345
342
  """rotate RGB cube to different position
346
343
 
347
344
  Args:
@@ -365,7 +362,7 @@ def rotate_rgb_cube(rgb, position=1):
365
362
  return rgb
366
363
 
367
364
 
368
- def rgb_from_3d_rgb_cube(X_3d, q=0.95):
365
+ def rgb_from_3d_rgb_cube(X_3d: torch.Tensor, q: float = 0.95) -> torch.Tensor:
369
366
  """convert 3D t-SNE to RGB color space
370
367
  Args:
371
368
  X_3d (torch.Tensor): 3D t-SNE embedding, shape (n_samples, 3)
@@ -383,6 +380,26 @@ def rgb_from_3d_rgb_cube(X_3d, q=0.95):
383
380
  return rgb
384
381
 
385
382
 
383
+ def rgb_from_3d_lab_cube(X_3d: torch.Tensor, q: float = 0.95, full_range: bool = True) -> torch.Tensor:
384
+ from skimage import color
385
+ X_3d = X_3d - torch.mean(X_3d, dim=0)
386
+ U, S, VT = torch.linalg.svd(X_3d)
387
+ X_3d = torch.flip(U[:, :3] * S, dims=(1,))
388
+
389
+ AB_scale = 128.0 / torch.quantile(torch.linalg.norm(X_3d[:, 1:], dim=1), q=q, dim=0)
390
+ L_min, L_max = torch.quantile(X_3d[:, 0], q=torch.tensor(((1 - q) / 2, (1 + q) / 2)), dim=0)
391
+ L_scale = 100.0 / (L_max - L_min)
392
+
393
+ X_3d[:, 0] = X_3d[:, 0] - L_min
394
+ if full_range:
395
+ lab = X_3d * torch.tensor((L_scale, AB_scale, AB_scale))
396
+ else:
397
+ lab = X_3d * L_scale
398
+
399
+ rgb = torch.tensor(color.lab2rgb(lab.numpy(force=True)))
400
+ return rgb
401
+
402
+
386
403
  def convert_to_lab_color(rgb, full_range=True):
387
404
  from skimage import color
388
405
  import copy
@@ -401,7 +418,7 @@ def convert_to_lab_color(rgb, full_range=True):
401
418
  return lab_rgb
402
419
 
403
420
 
404
- def rgb_from_2d_colormap(X_2d, q=0.95):
421
+ def rgb_from_2d_colormap(X_2d: torch.Tensor, q: float = 0.95):
405
422
  xy = X_2d.clone()
406
423
  for i in range(2):
407
424
  xy[:, i] = quantile_normalize(xy[:, i], q=q)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nystrom_ncut
3
- Version: 0.1.0
3
+ Version: 0.1.1
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/
@@ -1,14 +1,14 @@
1
1
  __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  nystrom_ncut/__init__.py,sha256=ffExLdGTaPsUweHcYc61Ose6a5A5Tfo9hm48zjEl6ho,441
3
- nystrom_ncut/common.py,sha256=l5kjF6neukdtbMrt5bE69pN0JM9r-93JYltLlYJuBik,2227
3
+ nystrom_ncut/common.py,sha256=2nffH0I2UrE6-7gQV6NlA7xSXeAl2GPR5F_5Or1yMt4,2275
4
4
  nystrom_ncut/propagation_utils.py,sha256=79M61iJfp_RWj_xLOn51PHiextWcEWTQ7NWl2T51-3Y,10907
5
- nystrom_ncut/visualize_utils.py,sha256=uGfBBkETQ8uRJ-UXPWpiXT8KEYMLmEHXPKJMLvN0c34,16543
5
+ nystrom_ncut/visualize_utils.py,sha256=EQKsNTfCssLYJv7HhwHxAyI18GLrkwbnOIrIKVoYZ1w,17344
6
6
  nystrom_ncut/nystrom/__init__.py,sha256=4EpxD3Cmc8Fif4vo8DG-6FpTfCnNanD5zCZxK3WrMwQ,121
7
7
  nystrom_ncut/nystrom/distance_realization.py,sha256=FGH7VjbtRrSROH0d8OPuCUxLQy5j7Z8BuE4hrSGGZG4,6031
8
8
  nystrom_ncut/nystrom/normalized_cut.py,sha256=s9ZS3-tQbWnxAlPc01v9l7fqBhl28lvOalaCO2y-Gd8,7175
9
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,,
10
+ nystrom_ncut-0.1.1.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
11
+ nystrom_ncut-0.1.1.dist-info/METADATA,sha256=XQymsKFQrtzWDKjwUbyVv8KiWwdbsMSCGIKPS9WcBGk,6058
12
+ nystrom_ncut-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
13
+ nystrom_ncut-0.1.1.dist-info/top_level.txt,sha256=gM8IWWHYysIRTCvCTcdS4RShOyl9pxpylgSwPUZR2XM,22
14
+ nystrom_ncut-0.1.1.dist-info/RECORD,,