<commit_before># Author(s): <NAME> (<EMAIL>) and <NAME>
#            (<EMAIL>)
# Contributors: <NAME>, <NAME>, <NAME>
# Copyright (c) 2014, Stanford University
# All rights reserved.

"""
Functions for performing mean first passage time
calculations for an MSM.

For a useful introduction to Markov Chains (both ergodic
and absorbing) check out Chapter 11 in:

.. [1] <NAME>. and <NAME>. Introduction to
       Probability. American Mathematical Soc., 1998.

The absorbing Markov Chain information is interesting, but
note that we are using ergodic Markov Chains.
"""
from __future__ import print_function, division, absolute_import
import numpy as np
import scipy
from mdtraj.utils.six.moves import xrange
import copy

__all__ = ['mfpts']


def create_perturb_params(tmat, countsmat):
    '''
    Helper function for computing mfpts when "errors" argument is passed. 
    Generates the means and standard deviations of the Gaussian random variables
    for each transition probability that will be sampled from during the error calculation.
    
    Parameters:
    ----------
    tmat: np.ndarray
        The msm transition matrix 
    countsmat: np.ndarray
        The msm counts matrix
    '''
    counts = (np.ones((len(tmat), len(tmat))) * np.sum(countsmat, axis=1)).transpose()
    scale = ((tmat - tmat ** 2) / counts ** 0.5) + 10 ** -15
    return (tmat, scale)


def perturb_tmat(loc, scale):
    '''
    Helper function for computing mfpts when "errors" argument is passed.
    Perturbs each nonzero transition probability by treating it as a Gaussian random variable
    and sampling from it once.
    
    Parameters:
    ----------
    loc: np.ndarray:
        The transition matrix, whose elements serve as the means of the Gaussian random variables
    scale: np.ndarray:
        The matrix of standard deviations of the Gaussians. For transition probability (i,j), this is <commit_msg>Update mfpt.py<commit_after># Author(s): <NAME> (<EMAIL>) and <NAME>
#            (<EMAIL>)
# Contributors: <NAME>, <NAME>, <NAME>
# Copyright (c) 2014, Stanford University
# All rights reserved.

"""
Functions for performing mean first passage time
calculations for an MSM.

For a useful introduction to Markov Chains (both ergodic
and absorbing) check out Chapter 11 in:

.. [1] <NAME>. and <NAME>. Introduction to
       Probability. American Mathematical Soc., 1998.

The absorbing Markov Chain information is interesting, but
note that we are using ergodic Markov Chains.
"""
from __future__ import print_function, division, absolute_import
import numpy as np
import scipy
from mdtraj.utils.six.moves import xrange
import copy

__all__ = ['mfpts']


def create_perturb_params(tmat, countsmat):
    '''
    Helper function for computing mfpts when "errors" argument is passed. 
    Generates the means and standard deviations of the Gaussian random variables
    for each transition probability that will be sampled from during the error calculation.
    
    Parameters:
    ----------
    tmat: np.ndarray
        The msm transition matrix 
    countsmat: np.ndarray
        The msm counts matrix
    '''
    counts = (np.ones((len(tmat), len(tmat))) * np.sum(countsmat, axis=1)).transpose()
    scale = ((tmat - tmat ** 2) ** 0.5 / counts ** 0.5) + 10 ** -15
    return (tmat, scale)


def perturb_tmat(loc, scale):
    '''
    Helper function for computing mfpts when "errors" argument is passed.
    Perturbs each nonzero transition probability by treating it as a Gaussian random variable
    and sampling from it once.
    
    Parameters:
    ----------
    loc: np.ndarray:
        The transition matrix, whose elements serve as the means of the Gaussian random variables
    scale: np.ndarray:
        The matrix of standard deviations of the Gaussians. For transition probability (i,j), this is 
{'fraction_non_alphanumeric': 0.09338929695697797, 'fraction_numerical': 0.01049317943336831, 'mean_word_length': 3.255580357142857, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '3588268', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1032, 'n_words': 448}