def _calculateMarkovChain(self):
        # we employ a sparse representation here:
        # dict of dicts...
        self.mc = {}
        startLabel = self.getStartLabel()
        self.stateLabel4msg = [""] * self.dh.getN()
        self.msgs4state = {}
        self.mc[startLabel] = {}
        for commId in self.dh.getCommunicationIds():
            # all states embraced by (order-1) START_STATE and END_STATE
            states = self.dh.getStateIdsForComm(commId, self.order-1)
            indices = self.dh.getMsgIndexForComm(commId)
            for ind in range(0, len(states)-self.order):
                s1 = STATE_SEP.join(states[ind:(ind+self.order)])
                s2 = STATE_SEP.join(states[(ind+1):(ind+self.order+1)])
                # increase the transition count
                trans = self.mc.setdefault(s1, {})
                trans[s2] = trans.get(s2, 0) + 1
                # store the state labels
                if self.order == 1:
                    if ind >= 1:
                        self.setStateLabel(indices[ind-1], s1)
                else:
                    # higher order markov chain
                    if ind < len(indices):
                        self.setStateLabel(indices[ind], s1)
                    if ind == 0:
                        trans = self.mc[startLabel]
                        trans[s1] = trans.get(s1, 0) + 1
dataset/ETHPy150Open hgascon/pulsar/pulsar/core/model.py/ModelFilesGenerator._calculateMarkovChain/original