(self, k=1)
Generates a k-th order Markov model
            for the underlying sequence
Generates a k-th order Markov model
            for the underlying sequence
Generates a k - th order Markov model for the underlying sequence
def fitMarkovModel(self, k=1):
        """ Generates a k-th order Markov model
            for the underlying sequence
        """

        # TODO: Add support for k=0

        assert len(self.sequence)>0, "Error: Empty sequence"

        # MLE fit of transition probabilities
        self.P[k] = _co.defaultdict( lambda:  _co.defaultdict( lambda: 0.0 )  )

        Log.add('Fitting Markov model with order k = ' + str(k))

        # Generate initial memory prefix
        mem = (())
        for s in self.sequence[:k]:
            mem += (s,)

        # count state transitions
        for s in self.sequence[k:]:
            self.P[k][mem][s] += 1.0

            # shift memory by one element
            mem = mem[1:] + (s,)

        # normalize transitions
        for m in self.P[k]:
            S = float(sum(self.P[k][m].values()))
            for s in self.P[k][m]:
                self.P[k][m][s] /= S
        Log.add('finished.')
def fitMarkovModel ( self , k = 1 ) : # TODO: Add support for k=0 assert len ( self . sequence ) > 0 , "Error: Empty sequence" # MLE fit of transition probabilities self . P [ k ] = _co . defaultdict ( lambda : _co . defaultdict ( lambda : 0.0 ) ) Log . add ( 'Fitting Markov model with order k = ' + str ( k ) ) # Generate initial memory prefix mem = ( ( ) ) for s in self . sequence [ : k ] : mem += ( s , ) # count state transitions for s in self . sequence [ k : ] : self . P [ k ] [ mem ] [ s ] += 1.0 # shift memory by one element mem = mem [ 1 : ] + ( s , ) # normalize transitions for m in self . P [ k ] : S = float ( sum ( self . P [ k ] [ m ] . values ( ) ) ) for s in self . P [ k ] [ m ] : self . P [ k ] [ m ] [ s ] /= S Log . add ( 'finished.' )