Exemple #1
0
 	def featspacelen(self) : 
		""" Vary the feature space and the sequence length """
		self.tasklist = []
		featspace = self.kwdargs['featspace']
		seqspace = 20
		seqlen = self.kwdargs['seqlen']	
		dims = [(seqspace,featspace)]*seqlen

		# Repeat for all the tasks described	
		for taskid in range(self.ntimes) :	
			hmm = HMM()
			self._set_params_generic(hmm,seqlen,dims)
			cmrf = CMRF(hmm)	
			feats = self._gen_feats_generic(seqlen,featspace)
			task = Task('sim'+STUDY+'_'+self.name+'_'+\
				str(seqlen)+'_'+str(featspace)+'_'+str(taskid),cmrf,feats)				
			# Run Brute force to enumerate the frontier
			if self.kwdargs['run_brute'] : 
				with benchmark(task.name+'brute') as t:
					seq,energies = self.bruteforce(cmrf,feats)			
				task.all_seq = seq
				task.all_seq_energy = energies
				task.brute_time = t.elapsed			

			# Now run the toy simulation`
			with benchmark(task.name+'pareto') as t : 
				task.frontier,task.frontier_energy = \
					pareto_frontier(cmrf,feats)		
			if self.plot_all :
				task.plot_frontier(frontier_only=True)
			task.pareto_time = t.elapsed
			self.tasklist.append(task)
Exemple #2
0
	def ziftied(self) :
		""" Set up the toy simulation """	
		self.tasklist = []
		feats = self.kwdargs['feats']
		weights = self.kwdargs['weights']
		hmm = HMM()
		self._set_params_ziftied(hmm)
		#1/0
		cmrf = CMRF(hmm)
		for taskid in range(self.ntimes) :	
			task = Task('bio'+str(STUDY)+'_'+self.name+'_'+str(taskid),cmrf,\
				feats)				
			# Run Brute force to enumerate the frontier
#			with benchmark(task.name+'brute') as t:
#				seq,energies = self.bruteforce(cmrf,feats)			
#			task.all_seq = seq
#			task.all_seq_energy = energies
#			task.brute_time = t.elapsed			

			# Sample the frontier
			with benchmark(task.name+'sample') as t:
				seq,energies = self.sample(cmrf,feats)			
			task.sample_seq = seq
			task.sample_seq_energy = energies
			task.sample_time = t.elapsed			

			# Now run the toy simulation`
			with benchmark(task.name+'pareto') as t : 
				task.frontier,task.frontier_energy = \
					pareto_frontier(cmrf,feats)		
			if self.plot_all :
				task.plot_frontier(frontier_only = True,plot_samples=True)
			task.pareto_time = t.elapsed
			self.tasklist.append(task)	
Exemple #3
0
	def toy(self) :
		""" Set up the toy simulation """	
		self.tasklist = []
		feats = self.get_feats_standard()
		hmm = HMM()
		self._set_params_toy(hmm)
		cmrf = CMRF(hmm)
		for taskid in range(self.ntimes) :	
			task = Task('sim'+STUDY+'_'+self.name+'_'+str(taskid),cmrf,\
				feats)				
			# Run Brute force to enumerate the frontier
			with benchmark(task.name+'brute') as t:
				seq,energies = self.bruteforce(cmrf,feats)			
			task.all_seq = seq
			task.all_seq_energy = energies
			task.brute_time = t.elapsed			

			# Now run the toy simulation`
			with benchmark(task.name+'pareto') as t : 
				task.frontier,task.frontier_energy = \
					pareto_frontier(cmrf,feats)		
			if self.plot_all :
				task.plot_frontier()
			task.pareto_time = t.elapsed
			self.tasklist.append(task)	
Exemple #4
0
	def randfeatsuntied(self) : 
		""" Run many iterations of toy with random probs  """
		self.tasklist = []
		feats = self.get_feats_standard()
	
		# Repeat for all the tasks described	
		for taskid in range(self.ntimes) :	
			hmm = HMM()
			self._set_params_randprobsuntied(hmm)
			cmrf = CMRF(hmm)	
			feats = self._gen_feats_random()
			task = Task('sim'+STUDY+'_'+self.name+'_'+str(taskid),cmrf,\
				feats)				
			# Run Brute force to enumerate the frontier
			with benchmark(task.name+'brute') as t:
				seq,energies = self.bruteforce(cmrf,feats)			
			task.all_seq = seq
			task.all_seq_energy = energies
			task.brute_time = t.elapsed			

			# Now run the toy simulation`
			with benchmark(task.name+'pareto') as t : 
				task.frontier,task.frontier_energy = \
					pareto_frontier(cmrf,feats)		
			if self.plot_all :
				task.plot_frontier()
			task.pareto_time = t.elapsed
			self.tasklist.append(task)	
Exemple #5
0
    def toy(self):
        """ Set up the toy simulation """
        self.tasklist = []
        feats = self.get_feats_standard()
        hmm = HMM()
        self._set_params_toy(hmm)
        cmrf = CMRF(hmm)
        for taskid in range(self.ntimes):
            task = Task('sim'+STUDY+'_'+self.name+'_'+str(taskid),cmrf,\
             feats)
            # Run Brute force to enumerate the frontier
            with benchmark(task.name + 'brute') as t:
                seq, energies = self.bruteforce(cmrf, feats)
            task.all_seq = seq
            task.all_seq_energy = energies
            task.brute_time = t.elapsed

            # Now run the toy simulation`
            with benchmark(task.name + 'pareto') as t:
                task.frontier,task.frontier_energy = \
                 pareto_frontier(cmrf,feats)
            if self.plot_all:
                task.plot_frontier()
            task.pareto_time = t.elapsed
            self.tasklist.append(task)
Exemple #6
0
    def featspacelen(self):
        """ Vary the feature space and the sequence length """
        self.tasklist = []
        featspace = self.kwdargs['featspace']
        seqspace = 20
        seqlen = self.kwdargs['seqlen']
        dims = [(seqspace, featspace)] * seqlen

        # Repeat for all the tasks described
        for taskid in range(self.ntimes):
            hmm = HMM()
            self._set_params_generic(hmm, seqlen, dims)
            cmrf = CMRF(hmm)
            feats = self._gen_feats_generic(seqlen, featspace)
            task = Task('sim'+STUDY+'_'+self.name+'_'+\
             str(seqlen)+'_'+str(featspace)+'_'+str(taskid),cmrf,feats)
            # Run Brute force to enumerate the frontier
            if self.kwdargs['run_brute']:
                with benchmark(task.name + 'brute') as t:
                    seq, energies = self.bruteforce(cmrf, feats)
                task.all_seq = seq
                task.all_seq_energy = energies
                task.brute_time = t.elapsed

            # Now run the toy simulation`
            with benchmark(task.name + 'pareto') as t:
                task.frontier,task.frontier_energy = \
                 pareto_frontier(cmrf,feats)
            if self.plot_all:
                task.plot_frontier(frontier_only=True)
            task.pareto_time = t.elapsed
            self.tasklist.append(task)
Exemple #7
0
    def randfeatsuntied(self):
        """ Run many iterations of toy with random probs  """
        self.tasklist = []
        feats = self.get_feats_standard()

        # Repeat for all the tasks described
        for taskid in range(self.ntimes):
            hmm = HMM()
            self._set_params_randprobsuntied(hmm)
            cmrf = CMRF(hmm)
            feats = self._gen_feats_random()
            task = Task('sim'+STUDY+'_'+self.name+'_'+str(taskid),cmrf,\
             feats)
            # Run Brute force to enumerate the frontier
            with benchmark(task.name + 'brute') as t:
                seq, energies = self.bruteforce(cmrf, feats)
            task.all_seq = seq
            task.all_seq_energy = energies
            task.brute_time = t.elapsed

            # Now run the toy simulation`
            with benchmark(task.name + 'pareto') as t:
                task.frontier,task.frontier_energy = \
                 pareto_frontier(cmrf,feats)
            if self.plot_all:
                task.plot_frontier()
            task.pareto_time = t.elapsed
            self.tasklist.append(task)
Exemple #8
0
    # 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:
            pl.text(e[0] + 0.5, e[1] - 0.4, str(i), fontsize=10)
            pl.text(e[0] - 3, e[1] - 1.5, frontier[i], fontsize=9)

    pl.xlabel("Energy:" + feat1)
Exemple #9
0
    ### 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
        pl.text(e[0], e[1] + 0.1 * ctr[e], str(i), fontsize=10)
        pl.text(e[0] + 0.1, e[1] + 0.1 * ctr[e], frontier[i], fontsize=9)
    pl.xlabel('Energy:' + feat1)
    pl.ylabel('Energy:' + feat2)
    pl.title('Energy Plot')
    xmin, xmax = pl.xlim()
    ymin, ymax = pl.ylim()