示例#1
0
def _catch_unhashable(x):
    if hasattr(x, '__getitem__'):
        res = list(x)
        for i, value in enumerate(x):
            if isinstance(value, np.ndarray):
                res[i] = _hash_numpy_array(value)
            else:
                res[i] = value
        return tuple(res)
    elif isinstance(x, np.ndarray):
        return _hash_numpy_array(x)

    return x
示例#2
0
    def _compute_eigendecomposition(self, neig):
        """ Conducts the eigenvalue decomposition and stores k eigenvalues, left and right eigenvectors """
        from msmtools.analysis import rdl_decomposition
        self._p_id = _hash_numpy_array(self.transition_matrix)

        if self.reversible:
            self._R, self._D, self._L = rdl_decomposition(
                self.transition_matrix,
                norm='reversible',
                k=neig,
                ncv=self.ncv)
            # everything must be real-valued
            self._R = self._R.real
            self._D = self._D.real
            self._L = self._L.real
        else:
            self._R, self._D, self._L = rdl_decomposition(
                self.transition_matrix, k=neig, norm='standard', ncv=self.ncv)
            # if the imaginary parts are zero, discard them.
            if _np.all(self._R.imag == 0):
                self._R = _np.real(self._R)
            if _np.all(self._D.imag == 0):
                self._D = _np.real(self._D)
            if _np.all(self._L.imag == 0):
                self._L = _np.real(self._L)

        self._eigenvalues = _np.diag(self._D)
示例#3
0
    def _ensure_eigendecomposition(self, neig=None):
        """Ensures that eigendecomposition has been performed with at least neig eigenpairs

        neig : int
            number of eigenpairs needed. If not given the default value will
            be used - see __init__()

        """
        if neig is None:
            neig = self.neig
        # ensure that eigenvalue decomposition with k components is done.
        try:
            m = self._D.shape[0]  # this will raise and exception if self._D doesn't exist yet.
            if m < neig or self._p_id != _hash_numpy_array(self.P):
                # not enough eigenpairs present
                # or eigendecomposition computed for an outdated transition matrix - recompute.
                self._compute_eigendecomposition(neig)
        except AttributeError:
            # no eigendecomposition yet - compute:
            self._compute_eigendecomposition(neig)
示例#4
0
def _hash_dtrajs(dtraj_list):
    from pyemma.util.numeric import _hash_numpy_array
    x = _hash_numpy_array(dtraj_list[0])
    for d in dtraj_list[1:]:
        x ^= _hash_numpy_array(d)
    return x
示例#5
0
def _hash_dtrajs(dtraj_list):
    x = 0
    from pyemma.util.numeric import _hash_numpy_array
    for d in dtraj_list:
        x ^= _hash_numpy_array(d)
    return x