Esempio n. 1
0
def timescales_from_eigenvalues(ev, tau=1):
    r"""Compute implied time scales from given eigenvalues
    
    Parameters
    ----------
    eval : eigenvalues
    tau : lag time

    Returns
    -------
    ts : ndarray
        The implied time scales to the given eigenvalues, in the same order.
    
    """

    """Check for dominant eigenvalues with large imaginary part"""
    if not np.allclose(ev.imag, 0.0):
        warnings.warn('Using eigenvalues with non-zero imaginary part '
                      'for implied time scale computation', ImaginaryEigenValueWarning)

    """Check for multiple eigenvalues of magnitude one"""
    ind_abs_one = isclose(np.abs(ev), 1.0)
    if sum(ind_abs_one) > 1:
        warnings.warn('Multiple eigenvalues with magnitude one.', SpectralWarning)

    """Compute implied time scales"""
    ts = np.zeros(len(ev))

    """Eigenvalues of magnitude one imply infinite timescale"""
    ts[ind_abs_one] = np.inf

    """All other eigenvalues give rise to finite timescales"""
    ts[np.logical_not(ind_abs_one)] = \
        -1.0 * tau / np.log(np.abs(ev[np.logical_not(ind_abs_one)]))
    return ts
Esempio n. 2
0
def timescales_from_eigenvalues(eval, tau=1):
    r"""Compute implied time scales from given eigenvalues
    
    Parameters
    ----------
    eval : eigenvalues
    tau : lag time

    Returns
    -------
    ts : ndarray
        The implied time scales to the given eigenvalues, in the same order.
    
    """
    
    """Check for dominant eigenvalues with large imaginary part"""
    if not np.allclose(eval.imag, 0.0):
        warnings.warn('Using eigenvalues with non-zero imaginary part '
                      'for implied time scale computation', ImaginaryEigenValueWarning)

    """Check for multiple eigenvalues of magnitude one"""
    ind_abs_one=isclose(np.abs(eval), 1.0)
    if sum(ind_abs_one)>1:
        warnings.warn('Multiple eigenvalues with magnitude one.', SpectralWarning)

    """Compute implied time scales"""
    ts=np.zeros(len(eval))

    """Eigenvalues of magnitude one imply infinite timescale"""
    ts[ind_abs_one]=np.inf

    """All other eigenvalues give rise to finite timescales"""
    ts[np.logical_not(ind_abs_one)]=\
        -1.0*tau/np.log(np.abs(eval[np.logical_not(ind_abs_one)]))
    return ts
Esempio n. 3
0
def timescales(T, tau=1, k=None, ncv=None):
    r"""Compute implied time scales of given transition matrix
    
    Parameters
    ----------
    T : transition matrix
    tau : lag time
    k : int (optional)
        Compute the first k implied time scales.
    ncv : int (optional)
        The number of Lanczos vectors generated, `ncv` must be greater than k;
        it is recommended that ncv > 2*k

    Returns
    -------
    ts : ndarray
        The implied time scales of the transition matrix.
    """
    if k is None:
        raise ValueError(
            "Number of time scales required for decomposition of sparse matrix"
        )
    values = scipy.sparse.linalg.eigs(T,
                                      k=k,
                                      which='LM',
                                      return_eigenvectors=False,
                                      ncv=ncv)
    """Sort by absolute value"""
    ind = np.argsort(np.abs(values))[::-1]
    values = values[ind]
    """Check for dominant eigenvalues with large imaginary part"""
    if not np.allclose(values.imag, 0.0):
        warnings.warn(
            'Using eigenvalues with non-zero imaginary part '
            'for implied time scale computation', ImaginaryEigenValueWarning)
    """Check for multiple eigenvalues of magnitude one"""
    ind_abs_one = isclose(np.abs(values), 1.0)
    if sum(ind_abs_one) > 1:
        warnings.warn('Multiple eigenvalues with magnitude one.',
                      SpectralWarning)
    """Compute implied time scales"""
    ts = np.zeros(len(values))
    """Eigenvalues of magnitude one imply infinite rate"""
    ts[ind_abs_one] = np.inf
    """All other eigenvalues give rise to finite rates"""
    ts[np.logical_not(ind_abs_one)] = \
        -1.0 * tau / np.log(np.abs(values[np.logical_not(ind_abs_one)]))
    return ts
Esempio n. 4
0
def timescales(T, tau=1, k=None, ncv=None):
    r"""Compute implied time scales of given transition matrix
    
    Parameters
    ----------
    T : transition matrix
    tau : lag time
    k : int (optional)
        Compute the first k implied time scales.
    ncv : int (optional)
        The number of Lanczos vectors generated, `ncv` must be greater than k;
        it is recommended that ncv > 2*k

    Returns
    -------
    ts : ndarray
        The implied time scales of the transition matrix.
    """
    if k is None:
        raise ValueError("Number of time scales required for decomposition of sparse matrix")
    values = scipy.sparse.linalg.eigs(T, k=k, which='LM', return_eigenvectors=False, ncv=ncv)

    """Sort by absolute value"""
    ind = np.argsort(np.abs(values))[::-1]
    values = values[ind]

    """Check for dominant eigenvalues with large imaginary part"""
    if not np.allclose(values.imag, 0.0):
        warnings.warn('Using eigenvalues with non-zero imaginary part '
                      'for implied time scale computation', ImaginaryEigenValueWarning)

    """Check for multiple eigenvalues of magnitude one"""
    ind_abs_one = isclose(np.abs(values), 1.0)
    if sum(ind_abs_one) > 1:
        warnings.warn('Multiple eigenvalues with magnitude one.', SpectralWarning)

    """Compute implied time scales"""
    ts = np.zeros(len(values))

    """Eigenvalues of magnitude one imply infinite rate"""
    ts[ind_abs_one] = np.inf

    """All other eigenvalues give rise to finite rates"""
    ts[np.logical_not(ind_abs_one)] = \
        -1.0 * tau / np.log(np.abs(values[np.logical_not(ind_abs_one)]))
    return ts