Esempio n. 1
0
def cut_transitions_square(filename, start, end, outfile, count="cut"):
    """Read transitions from file and cut out the piece start->end,
    so size NxN with N=end-start, row/col end is not included
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename, dim_trans)

    #L = end-start+1
    if 'edges' in header:
        edges = header['edges']
        edges = edges[start:end + 1]
    else:
        edges = None
    #count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    A = transmatrix[start:end, start:end]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A, outfile, lt, count, edges=edges, dt=dt, dn=dn)
Esempio n. 2
0
    def read_transition(self, filename, reduction=False):
        dim_trans = guess_dim_transition_square(filename)
        header = read_transition_header(filename)
        transmatrix = read_transition_square(filename, dim_trans)

        if reduction:
            dim_trans, header, transmatrix = reduce_Tmat(
                dim_trans, header, transmatrix)

        if not self.started:  # initialize settings
            self.started = True
            self.count = header['count']
            self.dim_trans = dim_trans
            if 'edges' in header:
                self.edges = header['edges']
            else:
                self.edges = np.arange(self.dim_trans + 1.)
        else:  # assert same settings
            assert self.count == header['count']
            assert self.dim_trans == dim_trans
            if 'edges' in header:
                assert (self.edges == header['edges']).all()

        self.list_lt.append(header['lt'])
        self.list_dt.append(header['dt'])
        self.list_dn.append(header['dn'])
        self.list_trans.append(transmatrix)
Esempio n. 3
0
def cyclic_permuation_transitions_square(
    filename,
    shift,
    outfile,
):  #count=None):
    """Shift indices periodically
    Read transitions from file and cut out the piece [shift:] and paste it behind [:shift],
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename, dim_trans)

    if 'edges' in header:
        edges = header['edges']
    else:
        edges = None
    count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    n = dim_trans
    A = np.zeros(transmatrix.shape, int)
    A[:(n - shift), :(n - shift)] = transmatrix[shift:, shift:]
    A[(n - shift):, :(n - shift)] = transmatrix[:shift, shift:]
    A[:(n - shift), (n - shift):] = transmatrix[shift:, :shift]
    A[(n - shift):, (n - shift):] = transmatrix[:shift, :shift]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A, outfile, lt, count, edges=edges, dt=dt, dn=dn)
Esempio n. 4
0
def cut_transitions_square(filename,start,end,outfile,count="cut"):
    """Read transitions from file and cut out the piece start->end,
    so size NxN with N=end-start, row/col end is not included
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename,dim_trans)

    #L = end-start+1
    if 'edges' in header:
        edges = header['edges']
        edges = edges[start:end+1]
    else:
        edges = None
    #count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    A = transmatrix[start:end,start:end]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A,outfile,lt,count,edges=edges,dt=dt,dn=dn)
Esempio n. 5
0
    def read_transition(self,filename,reduction=False):
        dim_trans = guess_dim_transition_square(filename)
        header = read_transition_header(filename)
        transmatrix = read_transition_square(filename,dim_trans)

        if reduction:
            dim_trans,header,transmatrix = reduce_Tmat(dim_trans,header,transmatrix)

        if not self.started: # initialize settings
            self.started = True
            self.count = header['count']
            self.dim_trans = dim_trans
            if 'edges' in header:
                self.edges = header['edges']
            else:
                self.edges = np.arange(self.dim_trans+1.)
        else: # assert same settings
            assert self.count == header['count']
            assert self.dim_trans == dim_trans
            if 'edges' in header:
                assert (self.edges == header['edges']).all()

        self.list_lt.append(header['lt'])
        self.list_dt.append(header['dt'])
        self.list_dn.append(header['dn'])
        self.list_trans.append(transmatrix)
Esempio n. 6
0
def cyclic_permuation_transitions_square(filename,shift,outfile,): #count=None):
    """Shift indices periodically
    Read transitions from file and cut out the piece [shift:] and paste it behind [:shift],
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename,dim_trans)

    if 'edges' in header:
        edges = header['edges']
    else:
        edges = None
    count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    n = dim_trans
    A = np.zeros(transmatrix.shape,int)
    A[:(n-shift),:(n-shift)] = transmatrix[shift:,shift:]
    A[(n-shift):,:(n-shift)] = transmatrix[:shift,shift:]
    A[:(n-shift),(n-shift):] = transmatrix[shift:,:shift]
    A[(n-shift):,(n-shift):] = transmatrix[:shift,:shift]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A,outfile,lt,count,edges=edges,dt=dt,dn=dn)