def expand(self, _=None): json = self.model.toJSON() prefix = self.stateName + '_' states = map(deepcopy, self.model.states) for i in range(len(states)): states[i].stateName = prefix + states[i].stateName transitions = map( lambda x: { 'from': prefix + x['from'], 'to': prefix + x['to'], 'prob': x['prob'], }, json['transitions'], ) return double_track_hmm(states, transitions, prefix + 'I1', prefix + 'End', self.mathType)
def expand(self, params=None): if params == None: raise "Houston, we have a problem" consensuses = params['consensus'] prefix_t = self.stateName + '_{}_' prefix_i = 0 states = list() transitions = list() init = self.stateName + '_Init' end = self.stateName + '_End' total = 0.0 for consensus in consensuses: prefix = prefix_t.format(prefix_i) prefix_i += 1 model = self.factory.getHMM(consensus) probability = self.consensusDistribution[consensus] total += probability json = model.toJSON() new_init = prefix + 'Init' new_end = prefix + 'End' st = map(deepcopy, model.states) for i in range(len(st)): st[i].stateName = prefix + st[i].stateName tr = map( lambda x: { 'from': prefix + x['from'], 'to': prefix + x['to'], 'prob': x['prob'], }, json['transitions'], ) st, tr, new_init, new_end = double_track_hmm( st, tr, new_init, new_end, self.mathType ) transitions.extend(tr) states.extend(st) transitions.extend([ { 'from': init, 'to': new_init, 'prob': probability, }, { 'from': new_end, 'to': end, 'prob': 1.0, }, ]) #transitions.append({ # 'from': init, # 'to': init, # 'prob': 1.0 - total, #}) template = { '__name__': 'GeneralizedPairState', 'name': init, 'startprob': 1.0, 'endprob': 0.0, 'emission': [(('', ''), self.mathType(1.0))], 'durations': [((0, 0), self.mathType(1.0))], } st = GeneralizedPairState(self.mathType) st.load(template) states.append(st) template['name'] = end template['startprob'] = 0.0 template['endprob'] = 1.0 st = GeneralizedPairState(self.mathType) st.load(template) states.append(st) return states, transitions, init, end