nystrom-ncut 0.0.3__tar.gz → 0.0.4__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {nystrom_ncut-0.0.3/src/nystrom_ncut.egg-info → nystrom_ncut-0.0.4}/PKG-INFO +1 -1
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/pyproject.toml +1 -1
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/nystrom.py +15 -10
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4/src/nystrom_ncut.egg-info}/PKG-INFO +1 -1
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/tests/test.py +26 -16
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/LICENSE +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/MANIFEST.in +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/README.md +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/requirements.txt +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/setup.cfg +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/__init__.py +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/common.py +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/ncut_pytorch.py +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/propagation_utils.py +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut/visualize_utils.py +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut.egg-info/SOURCES.txt +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut.egg-info/dependency_links.txt +0 -0
- {nystrom_ncut-0.0.3 → nystrom_ncut-0.0.4}/src/nystrom_ncut.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.4
|
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/
|
@@ -52,6 +52,18 @@ class OnlineNystrom:
|
|
52
52
|
self.transform_matrix: torch.Tensor = None # [n x n_components]
|
53
53
|
self.LS: torch.Tensor = None # [n]
|
54
54
|
|
55
|
+
def _update_to_kernel(self) -> Tuple[torch.Tensor, torch.Tensor]:
|
56
|
+
self.A = self.S = self.kernel.transform()
|
57
|
+
U, L = solve_eig(
|
58
|
+
self.A,
|
59
|
+
num_eig=self.inverse_approximation_dim,
|
60
|
+
eig_solver=self.eig_solver,
|
61
|
+
) # [n x (? + 1)], [? + 1]
|
62
|
+
self.Ahinv_UL = U * (L ** -0.5) # [n x (? + 1)]
|
63
|
+
self.Ahinv_VT = U.mT # [(? + 1) x n]
|
64
|
+
self.Ahinv = self.Ahinv_UL @ self.Ahinv_VT # [n x n]
|
65
|
+
return U, L
|
66
|
+
|
55
67
|
def fit(self, features: torch.Tensor):
|
56
68
|
OnlineNystrom.fit_transform(self, features)
|
57
69
|
return self
|
@@ -60,17 +72,8 @@ class OnlineNystrom:
|
|
60
72
|
self.anchor_features = features
|
61
73
|
|
62
74
|
self.kernel.fit(self.anchor_features)
|
63
|
-
self.A = self.S = self.kernel.transform() # [n x n]
|
64
|
-
|
65
75
|
self.inverse_approximation_dim = max(self.n_components, features.shape[-1]) + 1
|
66
|
-
U, L =
|
67
|
-
self.A,
|
68
|
-
num_eig=self.inverse_approximation_dim,
|
69
|
-
eig_solver=self.eig_solver,
|
70
|
-
) # [n x (? + 1)], [? + 1]
|
71
|
-
self.Ahinv_UL = U * (L ** -0.5) # [n x (? + 1)]
|
72
|
-
self.Ahinv_VT = U.mT # [(? + 1) x n]
|
73
|
-
self.Ahinv = self.Ahinv_UL @ self.Ahinv_VT # [n x n]
|
76
|
+
U, L = self._update_to_kernel() # [n x (? + 1)], [? + 1]
|
74
77
|
|
75
78
|
self.transform_matrix = (U / L)[:, :self.n_components] # [n x n_components]
|
76
79
|
self.LS = L[:self.n_components] # [n_components]
|
@@ -83,6 +86,7 @@ class OnlineNystrom:
|
|
83
86
|
chunks = torch.chunk(features, n_chunks, dim=0)
|
84
87
|
for chunk in chunks:
|
85
88
|
self.kernel.update(chunk)
|
89
|
+
self._update_to_kernel()
|
86
90
|
|
87
91
|
compressed_BBT = torch.zeros((self.inverse_approximation_dim, self.inverse_approximation_dim)) # [(? + 1) x (? + 1))]
|
88
92
|
for i, chunk in enumerate(chunks):
|
@@ -101,6 +105,7 @@ class OnlineNystrom:
|
|
101
105
|
else:
|
102
106
|
""" Unchunked version """
|
103
107
|
B = self.kernel.update(features).mT # [n x m]
|
108
|
+
self._update_to_kernel()
|
104
109
|
compressed_B = self.Ahinv_VT @ B # [indirect_pca_dim x m]
|
105
110
|
|
106
111
|
self.S = self.S + self.Ahinv_UL @ (compressed_B @ compressed_B.mT) @ self.Ahinv_UL.mT # [n x n]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nystrom_ncut
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.4
|
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,5 +1,7 @@
|
|
1
1
|
import numpy as np
|
2
2
|
import torch
|
3
|
+
import torch.nn.functional as Fn
|
4
|
+
|
3
5
|
from src.nystrom_ncut.ncut_pytorch import NCUT, axis_align
|
4
6
|
# from ncut_pytorch.src import rgb_from_umap_sphere
|
5
7
|
# from ncut_pytorch.src.new_ncut_pytorch import NewNCUT
|
@@ -35,28 +37,36 @@ if __name__ == "__main__":
|
|
35
37
|
# # ))
|
36
38
|
# raise Exception(
|
37
39
|
|
38
|
-
torch.set_printoptions(precision=
|
39
|
-
torch.
|
40
|
-
|
40
|
+
torch.set_printoptions(precision=8, sci_mode=False, linewidth=400)
|
41
|
+
torch.set_default_dtype(torch.float64)
|
42
|
+
# torch.manual_seed(1212)
|
43
|
+
# np.random.seed(1212)
|
41
44
|
|
42
|
-
M = torch.rand((
|
43
|
-
|
44
|
-
kwargs = dict(num_eig=7, sample_method="random")
|
45
|
-
nNC = NCUT(**kwargs)
|
45
|
+
M = torch.rand((200, 12))
|
46
|
+
NC = NCUT(n_components=12, num_sample=80, sample_method="random", chunk_size=20)
|
46
47
|
|
47
48
|
torch.manual_seed(1212)
|
48
49
|
np.random.seed(1212)
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
X, eigs = NC.fit_transform(M)
|
51
|
+
print(eigs)
|
52
|
+
raise Exception()
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
normalized_M = Fn.normalize(M, p=2, dim=-1)
|
55
|
+
A = torch.exp(-(1 - normalized_M @ normalized_M.mT))
|
56
|
+
R = torch.diag(torch.sum(A, dim=-1) ** -0.5)
|
57
|
+
L = R @ A @ R
|
58
|
+
# print(L)
|
59
|
+
print(X @ torch.diag(eigs) @ X.mT)
|
60
|
+
print(L)
|
61
|
+
print(torch.abs(X @ torch.diag(eigs) @ X.mT / L - 1))
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
# torch.manual_seed(1212)
|
64
|
+
# np.random.seed(1212)
|
65
|
+
#
|
66
|
+
# aX, R = axis_align(X)
|
67
|
+
# print(aX[:3])
|
68
|
+
# print(R)
|
69
|
+
# print(R @ R.mT)
|
60
70
|
raise Exception()
|
61
71
|
|
62
72
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|