Skip to content

Commit 733a888

Browse files
committed
removed reduced rank algorithm from main branch (see #54)
1 parent 5be748c commit 733a888

File tree

1 file changed

+6
-55
lines changed

1 file changed

+6
-55
lines changed

mlcolvar/core/stats/tica.py

+6-55
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def extra_repr(self) -> str:
4141
repr = f"in_features={self.in_features}, out_features={self.out_features}"
4242
return repr
4343

44-
def compute(self, data, weights = None, remove_average=True, save_params=False, algorithm = 'least_squares'):
44+
def compute(self, data, weights = None, remove_average=True, save_params=False):
4545
"""Perform TICA computation.
4646
4747
Parameters
@@ -54,17 +54,12 @@ def compute(self, data, weights = None, remove_average=True, save_params=False,
5454
whether to make the inputs mean free, by default True
5555
save_params : bool, optional
5656
Save parameters of estimator, by default False
57-
algorithm : str, optional
58-
Algorithm to use, by default 'least_squares'. Options are 'least_squares' and 'reduced_rank'. Both algorithms are described in [1]_.
57+
5958
Returns
6059
-------
61-
torch.Tensor
62-
Eigenvalues
60+
torch.Tensor,torch.Tensor
61+
eigenvalues,eigenvectors
6362
64-
References
65-
----------
66-
.. [1] V. Kostic, P. Novelli, A. Maurer, C. Ciliberto, L. Rosasco, and M. Pontil, "Learning Dynamical Systems via Koopman Operator Regression in Reproducing Kernel Hilbert Spaces" (2022).
67-
6863
"""
6964
# parse args
7065

@@ -81,16 +76,7 @@ def compute(self, data, weights = None, remove_average=True, save_params=False,
8176
C_0 = correlation_matrix(x_t,x_t,w_t)
8277
C_lag = correlation_matrix(x_t,x_lag,w_lag)
8378

84-
if (algorithm == 'reduced_rank') and (self.out_features >= self.in_features):
85-
warnings.warn('out_features is greater or equal than in_features. reduced_rank is equal to least_squares.')
86-
algorithm = 'least_squares'
87-
88-
if algorithm == 'reduced_rank':
89-
evals, evecs = reduced_rank_eig(C_0, C_lag, self.reg_C_0, rank = self.out_features)
90-
elif algorithm != 'least_squares':
91-
raise ValueError(f'algorithm {algorithm} not recognized. Options are least_squares and reduced_rank.')
92-
else:
93-
evals, evecs = cholesky_eigh(C_lag,C_0,self.reg_C_0,n_eig=self.out_features)
79+
evals, evecs = cholesky_eigh(C_lag,C_0,self.reg_C_0,n_eig=self.out_features)
9480

9581
if save_params:
9682
self.evals = evals
@@ -176,40 +162,5 @@ def test_tica():
176162
s2 = tica(X2)
177163
print(X2.shape,'-->',s2.shape)
178164

179-
def test_reduced_rank_tica():
180-
in_features = 10
181-
X = torch.rand(100,in_features)*100
182-
x_t = X[:-1]
183-
x_lag = X[1:]
184-
w_t = torch.rand(len(x_t))
185-
w_lag = w_t
186-
187-
# direct way, compute tica function
188-
tica = TICA(in_features,out_features=5)
189-
print(tica)
190-
tica.compute([x_t,x_lag],[w_t,w_lag], save_params=True, algorithm='reduced_rank')
191-
s = tica(X)
192-
print(X.shape,'-->',s.shape)
193-
print('eigvals',tica.evals)
194-
print('timescales', tica.timescales(lag=10))
195-
196-
# step by step
197-
tica = TICA(in_features)
198-
C_0 = correlation_matrix(x_t,x_t)
199-
C_lag = correlation_matrix(x_t,x_lag)
200-
print(C_0.shape,C_lag.shape)
201-
202-
evals, evecs = reduced_rank_eig(C_0, C_lag, 1e-6, rank = 5)
203-
print(evals.shape,evecs.shape)
204-
205-
print('>> batch')
206-
s = tica(X)
207-
print(X.shape,'-->',s.shape)
208-
print('>> single')
209-
X2 = X[0]
210-
s2 = tica(X2)
211-
print(X2.shape,'-->',s2.shape)
212-
213165
if __name__ == "__main__":
214-
test_tica()
215-
test_reduced_rank_tica()
166+
test_tica()

0 commit comments

Comments
 (0)