if __name__ == "__main__": hmm = HMM() # Set the params of the h,, set_params_hmm_exp1(hmm) cmrf = CMRF(hmm) seq1 = "a" * 12 feat1 = "HHHHLLLLHHHH" seq2 = "b" * 12 feat2 = "BBBBLLLLBBBB" # Plot the entire sequence space ll_list1, ll_list2 = [], [] for seq in product("ab", repeat=12): ll_list1.append(cmrf.score(seq, feat1)) ll_list2.append(cmrf.score(seq, feat2)) # Find the pareto frontier frontier, frontier_energy = pareto_frontier(cmrf, [feat1, feat2]) pl.figure() pl.plot(ll_list1, ll_list2, "b*") pl.plot(*zip(*sorted(frontier_energy)), color="magenta", marker="*", linestyle="dashed") ctr = dict(zip(set(frontier_energy), [0] * len(set(frontier_energy)))) for i, e in enumerate(frontier_energy): ctr[e] += 1 if i == 0: pl.text(e[0] + 0.5, e[1] - 0.4, str(i), fontsize=10) pl.text(e[0] - 3, e[1] + 0.8, frontier[i], fontsize=9) else:
set_params_hmm_exp1(hmm) cmrf = CMRF(hmm) seq1 = 'a' * 12 feat1 = 'HHHHLLLLHHHH' seq2 = 'b' * 12 feat2 = 'BBBBLLLLBBBB' ### DEBUG import pickle cmrf = pickle.load(open('cmrf.pkl')) # Plot the entire sequence space ll_list1, ll_list2 = [], [] seq_list = ["".join(s) for s in product('ab', repeat=12)] for seq in seq_list: ll_list1.append(cmrf.score(seq, feat1)) ll_list2.append(cmrf.score(seq, feat2)) min_feat1id = ll_list1.index(min(ll_list1)) min_feat2id = ll_list2.index(min(ll_list2)) # Find the pareto frontier frontier, frontier_energy = pareto_frontier(cmrf, [feat1, feat2]) # Plot only the frontier pl.figure() pl.plot(*zip(*sorted(frontier_energy)),color='magenta',marker='*',\ linestyle='dashed') ctr = dict(zip(set(frontier_energy), [0] * len(set(frontier_energy)))) for i, e in enumerate(frontier_energy): ctr[e] += 1
hmm.trans[-1][-1].append(val) return hmm if __name__ == '__main__': b = BoostedHMM() hmm1, hmm2 = b.hmm1, b.hmm2 # Set the params of the hmm cmrf1 = CMRF(hmm1) cmrf2 = CMRF(hmm2) feat = 'HHHHHHHHHHHH' # Plot the entire sequence space ll_list1, ll_list2 = [], [] for seq in product('ab', repeat=12): ll_list1.append(cmrf1.score(seq, feat)) ll_list2.append(cmrf2.score(seq, feat)) ll_list3, ll_list4 = [], [] for seq in b.kseqlist: ll_list3.append(cmrf1.score(seq, feat)) ll_list4.append(cmrf2.score(seq, feat)) pl.figure() pl.plot(ll_list1, ll_list2, 'b*') pl.plot(ll_list3, ll_list4, 'r*') pl.xlabel('Energy1:') pl.ylabel('Energy2:') pl.title('Energy Plot') xmin, xmax = pl.xlim() ymin, ymax = pl.ylim()
val = (counts2[i].get(aa1+aa2,0)+self.smoothfac) / (counts[i].get(aa1,0)+self.smoothfac*len(hmm.alphabet)) hmm.trans[-1][-1].append(val) return hmm if __name__ == '__main__' : b = BoostedHMM() hmm1,hmm2 = b.hmm1,b.hmm2 # Set the params of the hmm cmrf1 = CMRF(hmm1) cmrf2 = CMRF(hmm2) feat = 'HHHHHHHHHHHH' # Plot the entire sequence space ll_list1,ll_list2 = [],[] for seq in product('ab',repeat=12): ll_list1.append(cmrf1.score(seq,feat)) ll_list2.append(cmrf2.score(seq,feat)) ll_list3,ll_list4 = [],[] for seq in b.kseqlist: ll_list3.append(cmrf1.score(seq,feat)) ll_list4.append(cmrf2.score(seq,feat)) pl.figure() pl.plot(ll_list1,ll_list2,'b*') pl.plot(ll_list3,ll_list4,'r*') pl.xlabel('Energy1:') pl.ylabel('Energy2:') pl.title('Energy Plot') xmin,xmax = pl.xlim()