Ejemplo n.º 1
0
def experiment2_():
    L = 10
    sigma = 1
    code = sample_code(L, 1)
    mu = -10
    Ne = 2
    sites = [random_site(L) for i in xrange(10000)]
    apw_eps = [score(code, site) for site in sites]
    site_sigma = sd(apw_eps)
    pssm = sample_matrix(L, sqrt(site_sigma**2 / L))

    #linear_eps = [score_seq(pssm, site) for site in sites]
    def apw_phat(site):
        ep = score(code, site)
        return 1 / (1 + exp(ep - mu))**(Ne - 1)

    def linear_phat(site):
        ep = score_seq(pssm, site)
        return 1 / (1 + exp(ep - mu))**(Ne - 1)

    def sample_apw_site():
        return mh(apw_phat, proposal=mutate_site, x0=random_site(L))

    apw_chain = mh(apw_phat, proposal=mutate_site, x0=random_site(L))
    linear_chain = mh(linear_phat, proposal=mutate_site, x0=random_site(L))
    apw_fits = map(apw_phat, apw_chain)
    linear_fits = map(linear_phat, linear_chain)
    return apw_fits, linear_fits
Ejemplo n.º 2
0
def experiment3(trials=10):
    mu = -10
    Ne = 5
    L = 10
    sigma = 1
    codes = [sample_code(L, sigma) for i in range(trials)]
    pssms = [sample_matrix(L, sigma) for i in range(trials)]
    sites = [random_site(L) for i in xrange(10000)]
    apw_site_sigmas = [
        sd([score(code, site) for site in sites]) for code in codes
    ]
    linear_site_sigmas = [
        sd([score_seq(pssm, site) for site in sites]) for pssm in pssms
    ]

    def apw_phat(code, site):
        ep = score(code, site)
        return 1 / (1 + exp(ep - mu))**(Ne - 1)

    def apw_occ(code, site):
        ep = score(code, site)
        return 1 / (1 + exp(ep - mu))

    def linear_phat(pssm, site):
        ep = score_seq(pssm, site)
        return 1 / (1 + exp(ep - mu))**(Ne - 1)

    def linear_occ(pssm, site):
        ep = score_seq(pssm, site)
        return 1 / (1 + exp(ep - mu))

    apw_mean_fits = [
        exp(
            mean(
                map(
                    log10,
                    mh(lambda s: apw_phat(code, s),
                       proposal=mutate_site,
                       x0=random_site(L),
                       capture_state=lambda s: apw_occ(code, s))[1:])))
        for code in tqdm(codes)
    ]
    linear_mean_fits = [
        exp(
            mean(
                map(
                    log10,
                    mh(lambda s: linear_phat(pssm, s),
                       proposal=mutate_site,
                       x0=random_site(L),
                       capture_state=lambda s: linear_occ(pssm, s))[1:])))
        for pssm in tqdm(pssms)
    ]
    plt.scatter(apw_site_sigmas, apw_mean_fits, label='apw')
    plt.scatter(linear_site_sigmas,
                linear_mean_fits,
                color='g',
                label='linear')
    plt.semilogy()
    plt.legend(loc='lower right')
def experiment3(trials=10):
    mu = -10
    Ne = 5
    L = 10
    sigma = 1
    codes = [sample_code(L, sigma) for i in range(trials)]
    pssms = [sample_matrix(L, sigma) for i in range(trials)]
    sites = [random_site(L) for i in xrange(10000)]
    apw_site_sigmas = [sd([score(code,site) for site in sites]) for code in codes]
    linear_site_sigmas = [sd([score_seq(pssm,site) for site in sites]) for pssm in pssms]
    def apw_phat(code, site):
        ep = score(code, site)
        return 1/(1+exp(ep-mu))**(Ne-1)
    def apw_occ(code, site):
        ep = score(code, site)
        return 1/(1+exp(ep-mu))
    def linear_phat(pssm, site):
        ep = score_seq(pssm, site)
        return 1/(1+exp(ep-mu))**(Ne-1)
    def linear_occ(pssm, site):
        ep = score_seq(pssm, site)
        return 1/(1+exp(ep-mu))
    apw_mean_fits = [exp(mean(map(log10, mh(lambda s:apw_phat(code, s), proposal=mutate_site, x0=random_site(L),
                                          capture_state = lambda s:apw_occ(code, s))[1:])))
                         for code in tqdm(codes)]
    linear_mean_fits = [exp(mean(map(log10, mh(lambda s:linear_phat(pssm, s), proposal=mutate_site, x0=random_site(L),
                                             capture_state = lambda s:linear_occ(pssm, s))[1:])))
                        for pssm in tqdm(pssms)]
    plt.scatter(apw_site_sigmas, apw_mean_fits, label='apw')
    plt.scatter(linear_site_sigmas, linear_mean_fits, color='g',label='linear')
    plt.semilogy()
    plt.legend(loc='lower right')
def experiment2_():
    L = 10
    sigma = 1
    code = sample_code(L, 1)
    mu = -10
    Ne = 2
    sites = [random_site(L) for i in xrange(10000)]
    apw_eps = [score(code, site) for site in sites]
    site_sigma = sd(apw_eps)
    pssm = sample_matrix(L, sqrt(site_sigma**2/L))
    #linear_eps = [score_seq(pssm, site) for site in sites]
    def apw_phat(site):
        ep = score(code, site)
        return 1/(1+exp(ep-mu))**(Ne-1)
    def linear_phat(site):
        ep = score_seq(pssm, site)
        return 1/(1+exp(ep-mu))**(Ne-1)
    def sample_apw_site():
        return mh(apw_phat, proposal=mutate_site, x0=random_site(L))
    apw_chain = mh(apw_phat, proposal=mutate_site, x0=random_site(L))
    linear_chain = mh(linear_phat, proposal=mutate_site, x0=random_site(L))
    apw_fits = map(apw_phat, apw_chain)
    linear_fits = map(linear_phat, linear_chain)
    return apw_fits, linear_fits
Ejemplo n.º 5
0
 def apw_phat(code, site):
     ep = score(code, site)
     return 1 / (1 + exp(ep - mu))**(Ne - 1)
Ejemplo n.º 6
0
 def apw_occ(code, mu, site):
     ep = score(code, site)
     return 1 / (1 + exp(ep - mu))
 def apw_occ(code, site):
     ep = score(code, site)
     return 1/(1+exp(ep-mu))
 def apw_phat(code, site):
     ep = score(code, site)
     return 1/(1+exp(ep-mu))**(Ne-1)