<commit_before>import numpy as np
from decomposition import mu as statdist

def is_transition_matrix(T, tol=1e-15):
    dim = T.shape[0]
    X = np.abs(T) - T
    x = np.sum(T, axis = 1)
    return np.abs(x - np.ones(dim)).max() < dim * tol and X.max() < 2.0 * tol


def is_rate_matrix(K, tol=1e-15):
    """
    True if K is a rate matrix
    Parameters
    ----------
    K : numpy.ndarray matrix
        Matrix to check
    tol : float
        tolerance to check with

    Returns
    -------
    Truth value : bool
        True, if K negated diagonal is positive and row sums up to zero.
        False, otherwise
    """
    R = K - K.diagonal()
    off_diagonal_positive = np.allclose(R, abs(R), 0.0, atol=tol)
    
    row_sum = K.sum(axis = 1)
    row_sum_eq_0 = np.allclose(row_sum, 0.0, atol=tol)
    
    return off_diagonal_positive and row_sum_eq_0
<commit_msg>[msm/analysis] added docstring to dense.is_transition_matrix<commit_after>import numpy as np
from decomposition import mu as statdist

def is_transition_matrix(T, tol=1e-15):
    """
    Tests whether T is a transition matrix
    
    Parameters
    ----------
    T : ndarray shape=(n, n)
        matrix to test
    tol : float
        tolerance to check with
    
    Returns
    -------
    Truth value : bool
        True, if all elements are in interval [0, 1] 
            and each row of T sums up to 1.
        False, otherwise
    """
    if T.shape[0] != T.shape[1]:
        raise ValueError('T is not a quadratic matrix')
    dim = T.shape[0]
    X = np.abs(T) - T
    x = np.sum(T, axis = 1)
    return np.abs(x - np.ones(dim)).max() < dim * tol and X.max() < 2.0 * tol


def is_rate_matrix(K, tol=1e-15):
    """
    True if K is a rate matrix
    Parameters
    ----------
    K : numpy.ndarray matrix
        Matrix to check
    tol : float
        tolerance to check with

    Returns
    -------
    Truth value : bool
        True, if K negated diagonal is positive and row sums up to zero.
        False, otherwise
    """
    R = K - K.diagonal()
    off_diagonal_positive = np.allclose(R, abs(R), 0.0, atol=tol)
    
    row_sum = K.sum(axis = 1)
    row_sum_eq_0 = np.allclose(row_sum, 0.0, atol=tol)
    
    return off_diagonal_positive and row_sum_eq_0

{'fraction_non_alphanumeric': 0.11861394935584185, 'fraction_numerical': 0.0173256330519769, 'mean_word_length': 2.0147255689424366, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1352152', 'n_tokens_mistral': 799, 'n_tokens_neox': 767, 'n_words': 243}