def main(G=5000000,iterations=50000,init_matrix=None,init_mu=None,verbose=True): """Test case for FD-inference""" print "generating genome" genome = random_site(G) print "generating eps" eps = score_genome_np(TRUE_ENERGY_MATRIX,genome) min_mu,max_mu = -40,0 mu = bisect_interval(lambda mu:np.sum(fd_solve_np(eps,mu))-q,min_mu,max_mu,verbose=True,tolerance=1e-1) print "computing ps" true_ps = fd_solve_np(eps,mu) print "true q:",np.sum(true_ps) print "generating chip dataset" mapped_reads = np.array(map_reads_np(chip_ps_np(true_ps,MEAN_FRAGMENT_LENGTH,NUM_CELLS_ORIGINAL),G)) print "finished chip dataset" if init_matrix is None: init_matrix = random_energy_matrix(w) if init_mu is None: init_mu = -20#random.random()*40 - 20 init_scores = score_genome_np(init_matrix,genome) init_state = ((init_matrix,init_mu),init_scores) logf = lambda state:complete_log_likelihood(state,mapped_reads) print "true mu:",mu print "true log_likelihood:",logf(((TRUE_ENERGY_MATRIX,mu),eps)) rprop = lambda state:complete_rprop(state,genome) print "hitting mh loop" matrix_chain = mh(logf,proposal=rprop,x0=init_state,dprop=log_dprop,capture_state=capture_state,verbose=verbose,use_log=True,iterations=iterations,modulus=100) return matrix_chain,genome,mapped_reads
def test_update_scores_np(): w = 10 matrix = random_energy_matrix(w) i = random.randrange(w) j = random.randrange(4) dw = random.random() print i,j,dw new_matrix = [row[:] for row in matrix] new_matrix[i][j] += dw genome = random_site(100000) fwd_scores,rev_scores = score_genome_np(matrix,genome,both_strands=True) fwd_scores_ref,rev_scores_ref = score_genome_np(new_matrix,genome,both_strands=True) fwd_scores_test,rev_scores_test = update_scores_np(fwd_scores,rev_scores,i,j,dw,w,genome) fwd_scores_ref2 = update_scores_np_ref(fwd_scores,i,j,dw,genome,w) print l2_np(fwd_scores_ref,fwd_scores_test),l2_np(fwd_scores_ref,fwd_scores_ref2) print l2_np(rev_scores_ref,rev_scores_test)