def sanity_check(trials = 1000): L = 10 matrix = [[-2,0,0,0] for i in range(L)] mu = -10 Ne = 2 nu = Ne - 1 log_match_phats = [-nu * log(1+exp(-2*k - mu)) + log_choose(L,k) + k * log(1/4.0) + (L-k) * log(3/4.0) for k in range(L+1)] match_ps = normalize(map(exp, log_match_phats)) mh_motif = sample_motif_mh(matrix, mu, Ne, trials) mh_match_counts = Counter([site.count('A') for site in mh_motif]) mh_match_ps = [mh_match_counts[k]/float(trials) for k in range(L+1)] cftp_motif = sample_motif_cftp(matrix, mu, Ne, trials) cftp_match_counts = Counter([site.count('A') for site in cftp_motif]) cftp_match_ps = [cftp_match_counts[k]/float(trials) for k in range(L+1)] plt.plot(match_ps, label="Analytic") plt.plot(mh_match_ps, label="MH") plt.plot(cftp_match_ps, label="CFTP") plt.xlabel("Matches") plt.ylabel("Frequency")
def sanity_check(trials=1000): L = 10 matrix = [[-2, 0, 0, 0] for i in range(L)] mu = -10 Ne = 2 nu = Ne - 1 log_match_phats = [ -nu * log(1 + exp(-2 * k - mu)) + log_choose(L, k) + k * log(1 / 4.0) + (L - k) * log(3 / 4.0) for k in range(L + 1) ] match_ps = normalize(map(exp, log_match_phats)) mh_motif = sample_motif_mh(matrix, mu, Ne, trials) mh_match_counts = Counter([site.count('A') for site in mh_motif]) mh_match_ps = [mh_match_counts[k] / float(trials) for k in range(L + 1)] cftp_motif = sample_motif_cftp(matrix, mu, Ne, trials) cftp_match_counts = Counter([site.count('A') for site in cftp_motif]) cftp_match_ps = [ cftp_match_counts[k] / float(trials) for k in range(L + 1) ] plt.plot(match_ps, label="Analytic") plt.plot(mh_match_ps, label="MH") plt.plot(cftp_match_ps, label="CFTP") plt.xlabel("Matches") plt.ylabel("Frequency")
def log_w(n, L, rho): return log_choose(n * L, rho) + rho * log(3)
def log_prob_motif_with_mismatch(n, L, k): N = n * L return log_choose(N, k) + k * log(3 / 4.0) + (N - k) * log(1 / 4.0)
def log_dprop(motif, _): k = motif_hamming_distance(ringer, motif) # number of mutations from ringer #return log_choose(N,k) + k * log(p) + (N-k)*log(1-p) + k*log(1/3.0) #return -log(N) + k * log(1/3.0) return log(ps[k]) - log_choose(N, k) + k * log(1 / 3.0)
def log_dprop(motif, _): k = motif_hamming_distance(ringer, motif) # number of mutations from ringer ### return log(ps[k]) + k * log(1/3.0) ### XXX BE LESS RETARDED ABOUT THIS XXX # p(k)*(1/choose(N,k)) * (1/3.0)**k return log(ps[k]) - log_choose(N, k) + k * log(1.0 / 3)
def log_rho_weight(rho, n, L): return log_choose(n*L,rho) + rho*3