def __init__(self, P, dt=1):
        """
        Constructs a sampling object with transition matrix P. The results will be produced every dt'th time step

        Parameters
        ----------
        P : (n, n) ndarray
            transition matrix
        dt : int
            trajectory will be saved every dt time steps.
            Internally, the dt'th power of P is taken to ensure a more efficient simulation.

        """
        if scipy.sparse.issparse(P):
            warnings.warn("Markov Chain sampler not implemented for sparse matrices. "
                          "Converting transition matrix to dense array")
            P = P.toarray()
        # process input
        if dt > 1:
            # take a power of P if requested
            self.P = np.linalg.matrix_power(P, dt)
        else:
            # create local copy and transform to ndarray if in a different format
            self.P = np.array(P)
        self.n = self.P.shape[0]

        # initialize mu
        self.mudist = None

        # generate discrete random value generators for each line
        self.rgs = np.ndarray((self.n), dtype=object)
        from scipy.stats import rv_discrete
        for i in range(self.n):
            nz = np.nonzero(self.P[i])
            self.rgs[i] = rv_discrete(values=(nz, self.P[i, nz]))
def __init__ ( self , P , dt = 1 ) : if scipy . sparse . issparse ( P ) : warnings . warn ( "Markov Chain sampler not implemented for sparse matrices. " "Converting transition matrix to dense array" ) P = P . toarray ( ) if dt > 1 : self . P = np . linalg . matrix_power ( P , dt ) else : self . P = np . array ( P ) self . n = self . P . shape [ 0 ] self . mudist = None self . rgs = np . ndarray ( ( self . n ) , dtype = object ) from scipy . stats import rv_discrete for i in range ( self . n ) : nz = np . nonzero ( self . P [ i ] ) self . rgs [ i ] = rv_discrete ( values = ( nz , self . P [ i , nz ] ) )
Constructs a sampling object with transition matrix P. The results will be produced every dt'th time step

        Parameters
        ----------
        P : (n, n) ndarray
            transition matrix
        dt : int
            trajectory will be saved every dt time steps.
            Internally, the dt'th power of P is taken to ensure a more efficient simulation.