def test_eigenvectors(self): evec = self.tica_obj.eigenvectors _, evec_ref = eig_corr(self.cov_ref, self.cov_tau_ref, sign_maxelement=True) assert (np.all(evec.shape == (2, 2))) np.testing.assert_allclose(evec, evec_ref) evec_nr = self.tica_obj_nr.eigenvectors _, evec_ref = eig_corr(self.cov_ref_nr, self.cov_tau_ref_nr, sign_maxelement=True) assert (np.all(evec_nr.shape == (2, 2))) np.testing.assert_allclose(evec_ref, evec_nr)
def test_eigenvalues(self): eval = self.tica_obj.eigenvalues eval_ref, _ = eig_corr(self.cov_ref, self.cov_tau_ref) assert len(eval) == 2 assert np.max(np.abs(eval) < 1) np.testing.assert_allclose(eval_ref, eval) eval_nr = self.tica_obj_nr.eigenvalues eval_ref, _ = eig_corr(self.cov_ref_nr, self.cov_tau_ref_nr) assert len(eval_nr) == 2 assert np.max(np.abs(eval_nr) < 1) np.testing.assert_allclose(eval_ref, eval_nr)
def _diagonalize(self): # diagonalize with low rank approximation self._logger.debug("diagonalize Cov and Cov_tau.") eigenvalues, eigenvectors = eig_corr(self._covar.cov, self._covar.cov_tau, self.epsilon, sign_maxelement=True) if self.kinetic_map and self.commute_map: raise ValueError( 'Trying to use both kinetic_map and commute_map. Use either or.' ) if self.kinetic_map: # scale by eigenvalues eigenvectors *= eigenvalues[None, :] if self.commute_map: # scale by (regularized) timescales timescales = 1 - self.lag / np.log(np.abs(eigenvalues)) # dampen timescales smaller than the lag time, as in section 2.5 of ref. [5] regularized_timescales = 0.5 * timescales * np.maximum( np.tanh(np.pi * ((timescales - self.lag) / self.lag) + 1), 0) eigenvectors *= np.sqrt(regularized_timescales / 2) self._logger.debug("finished diagonalisation.") # compute cumulative variance cumvar = np.cumsum(np.abs(eigenvalues)**2) cumvar /= cumvar[-1] self._model.update_model_params(cumvar=cumvar, eigenvalues=eigenvalues, eigenvectors=eigenvectors) self._estimated = True
def _diagonalize(self): # diagonalize with low rank approximation self.logger.debug("Diagonalize Cov and Cov_tau.") Wktau = self._model.cov_tau[self._model.column_indices, :] try: eigenvalues, eigenvectors = eig_corr(self._oasis.Wk, Wktau, self.epsilon, sign_maxelement=True) except ZeroRankError: raise ZeroRankError('All input features are constant in all time steps. ' 'No dimension would be left after dimension reduction.') self.logger.debug("Finished diagonalization.") # compute cumulative variance cumvar = np.cumsum(np.abs(eigenvalues) ** 2) cumvar /= cumvar[-1] self._model.update_model_params(cumvar=cumvar, eigenvalues=eigenvalues, eigenvectors=eigenvectors) self._estimated = True