nystrom-ncut 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (25) hide show
  1. {nystrom_ncut-0.2.0/src/nystrom_ncut.egg-info → nystrom_ncut-0.2.2}/PKG-INFO +1 -1
  2. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/pyproject.toml +1 -1
  3. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/nystrom/nystrom_utils.py +1 -0
  4. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/transformer/axis_align.py +8 -4
  5. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/transformer/transformer_mixin.py +2 -0
  6. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2/src/nystrom_ncut.egg-info}/PKG-INFO +1 -1
  7. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/LICENSE +0 -0
  8. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/MANIFEST.in +0 -0
  9. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/README.md +0 -0
  10. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/requirements.txt +0 -0
  11. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/setup.cfg +0 -0
  12. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/__init__.py +0 -0
  13. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/__init__.py +0 -0
  14. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/common.py +0 -0
  15. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/distance_utils.py +0 -0
  16. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/nystrom/__init__.py +0 -0
  17. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/nystrom/distance_realization.py +0 -0
  18. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/nystrom/normalized_cut.py +0 -0
  19. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/sampling_utils.py +0 -0
  20. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/transformer/__init__.py +0 -0
  21. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut/visualize_utils.py +0 -0
  22. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut.egg-info/SOURCES.txt +0 -0
  23. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut.egg-info/dependency_links.txt +0 -0
  24. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/src/nystrom_ncut.egg-info/top_level.txt +0 -0
  25. {nystrom_ncut-0.2.0 → nystrom_ncut-0.2.2}/tests/test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nystrom_ncut
3
- Version: 0.2.0
3
+ Version: 0.2.2
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.2.0"
7
+ version = "0.2.2"
8
8
  authors = [
9
9
  { name = "Huzheng Yang", email = "huze.yann@gmail.com" },
10
10
  { name = "Wentinn Liao", email = "wentinn.liao@gmail.com" },
@@ -93,6 +93,7 @@ class OnlineNystrom(TorchTransformerMixin):
93
93
 
94
94
  self.transform_matrix = (U / L)[:, :self.n_components] # [n x n_components]
95
95
  self.eigenvalues_ = L[:self.n_components] # [n_components]
96
+ self.is_fitted = True
96
97
  return U[:, :self.n_components] # [n x n_components]
97
98
 
98
99
  def update(self, features: torch.Tensor) -> torch.Tensor:
@@ -1,4 +1,3 @@
1
- import random
2
1
  from typing import Literal
3
2
 
4
3
  import torch
@@ -14,7 +13,7 @@ class AxisAlign(TorchTransformerMixin):
14
13
  Args:
15
14
  max_iter (int, optional): Maximum number of iterations.
16
15
  """
17
- SortOptions = Literal["count", "norm"]
16
+ SortOptions = Literal["count", "norm", "marginal_norm"]
18
17
 
19
18
  def __init__(
20
19
  self,
@@ -33,7 +32,7 @@ class AxisAlign(TorchTransformerMixin):
33
32
 
34
33
  # Initialize R matrix with the first column from a random row of EigenVectors
35
34
  self.R = torch.empty((d, d), device=X.device)
36
- self.R[0] = normalized_X[random.randint(0, n - 1)]
35
+ self.R[0] = normalized_X[torch.randint(0, n, (), device=X.device)]
37
36
 
38
37
  # Loop to populate R with k orthogonal directions
39
38
  c = torch.zeros((n,), device=X.device)
@@ -62,11 +61,16 @@ class AxisAlign(TorchTransformerMixin):
62
61
  if self.sort_method == "count":
63
62
  sort_metric = torch.bincount(idx, minlength=d)
64
63
  elif self.sort_method == "norm":
65
- sort_metric = torch.linalg.norm(X @ self.R.mT, dim=0)
64
+ rotated_X = X @ self.R.mT
65
+ sort_metric = torch.linalg.norm(rotated_X, dim=0)
66
+ elif self.sort_method == "marginal_norm":
67
+ rotated_X = X @ self.R.mT
68
+ sort_metric = torch.zeros((d,), device=X.device).index_add_(0, idx, rotated_X[range(n), idx] ** 2)
66
69
  else:
67
70
  raise ValueError(f"Invalid sort method {self.sort_method}.")
68
71
 
69
72
  self.R = self.R[torch.argsort(sort_metric, dim=0, descending=True)]
73
+ self.is_fitted = True
70
74
  return self
71
75
 
72
76
  def transform(self, X: torch.Tensor, normalize: bool = True, hard: bool = False) -> torch.Tensor:
@@ -36,6 +36,8 @@ class TorchTransformerMixin:
36
36
  >>> transformer.fit_transform(X)
37
37
  array([1, 1, 1])
38
38
  """
39
+ def __init__(self):
40
+ self.is_fitted: bool = False
39
41
 
40
42
  @abstractmethod
41
43
  def fit(self, X: torch.Tensor, **fit_kwargs: Any) -> "TorchTransformerMixin":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nystrom_ncut
3
- Version: 0.2.0
3
+ Version: 0.2.2
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