Esempio n. 1
0
def multi_species_benchmarks_opt2(lamR):
    repeats = 50
    lamP = 1
    #lamSs = [0.3,0.5,0.7,1]#+list(np.logspace(-1.5, 1.5, 3))
    #lamRs = [3,5,7]#np.logspace(0, 2, 5)
    iron_conds = range(ba.iron_conds)
    timeseries_conds = range(ba.timeseries_conds)
    subtilis_conds = range(ba.subtilis_conds)
    (BS_priors, sign) = ba.load_priors('gsSDnamesWithActivitySign082213','B_subtilis')
    orth = ba.load_orth('bs_ba_ortho_804',['B_anthracis','B_subtilis']) #TODO make the order impossible to get 

    lamR = lamR[0]
    lamS = 0
  
    acc_s = 0
    acc_a = 0
    aupr = 0
    corr = 0
    for rep in range(repeats):
        random.shuffle(iron_conds)
        random.shuffle(timeseries_conds)
        random.shuffle(subtilis_conds)

        sub_s_i = int(len(subtilis_conds)/8)
        sub_i_i = int(len(iron_conds)*0.75)
        sub_t_i = int(len(timeseries_conds)*0.75)

        sub_s = subtilis_conds[0:sub_s_i]
        sub_i = iron_conds[0:sub_i_i]
        sub_t = timeseries_conds[0:sub_t_i]
        
        ba.run_both_adjust(lamP=lamP, lamR=lamR, lamS=lamS, outf='tmp2', sub_s=sub_s, sub_i=sub_i, sub_t=sub_t)

        sub_st = subtilis_conds[sub_s_i:]
        sub_it = iron_conds[sub_i_i:]
        sub_tt = timeseries_conds[sub_t_i:]                    

        (bs_e, bs_t, bs_genes, bs_tfs) = ba.load_B_subtilis(sub_st)
        (ba_e, ba_t, ba_genes, ba_tfs) = ba.load_B_anthracis(sub_it, sub_tt)

        corr += ba.betas_fused_corr('tmp2_subtilis', 'tmp2_anthracis', orth)
        print corr/(rep+1)
        eval_s = ba.eval_prediction('tmp2_subtilis', bs_e, bs_t, bs_genes, bs_tfs,'R2')
        eval_a = ba.eval_prediction('tmp2_anthracis', ba_e, ba_t, ba_genes, ba_tfs,'R2')

        (net, bs_genes, bs_tfs) = ba.load_network('tmp2_subtilis')
        aupr += ba.eval_network_pr(net, bs_genes, bs_tfs, BS_priors)
        print aupr/(rep+1)
        acc_s += eval_s
        acc_a += eval_a
    return aupr/repeats
Esempio n. 2
0
def multi_species_benchmarks2(solver):
    repeats = 50
    lamPs = np.array([1])#np.logspace(0, 3, 10)
    lamSs = [0]#+list(np.logspace(-1.5, 1.5, 3))
    lamRs = [3]#np.logspace(0, 2, 5)
    iron_conds = range(ba.iron_conds)
    timeseries_conds = range(ba.timeseries_conds)
    subtilis_conds = range(ba.subtilis_conds)
    outf = file('benchmark_results/multi_species_bench4','w')
    (BS_priors, sign) = ba.load_priors('gsSDnamesWithActivitySign082213','B_subtilis')
    orth = ba.load_orth('bs_ba_ortho_804',['B_anthracis','B_subtilis']) #TODO make the order impossible to get 
    
    for lamP in lamPs:
        for lamS in lamSs:
            for lamR in lamRs:
                
                acc_s = 0
                acc_a = 0
                aupr = 0
                corr = 0
                for rep in range(repeats):
                    random.shuffle(iron_conds)
                    random.shuffle(timeseries_conds)
                    random.shuffle(subtilis_conds)

                    sub_s_i = int(len(subtilis_conds)/5)
                    sub_i_i = int(len(iron_conds)*0.75)
                    sub_t_i = int(len(timeseries_conds)*0.75)

                    sub_s = subtilis_conds[0:sub_s_i]
                    sub_i = iron_conds[0:sub_i_i]
                    sub_t = timeseries_conds[0:sub_t_i]
                    if solver=='run_both':
                        ba.run_both(lamP=lamP, lamR=lamR, lamS=lamS, outf='tmp2', sub_s = sub_s, sub_i = sub_i, sub_t = sub_t)
                    if solver=='run_both_adjust':
                        ba.run_both_adjust(lamP=lamP, lamR=lamR, lamS=lamS, outf='tmp2', sub_s=sub_s, sub_i=sub_i, sub_t=sub_t)
                    if solver=='run_both_refit':
                        ba.run_both_refit(lamP=lamP, lamR=lamR, lamS=lamS, outf='tmp2', sub_s = sub_s, sub_i = sub_i, sub_t = sub_t, it=10,k=20)
                    if solver=='scad':
                        ba.run_both(lamP=lamP, lamR=lamR, lamS=lamS, outf='tmp2', sub_s=sub_s, sub_i=sub_i, sub_t=sub_t, it=10, k=20, it_s=10)

                    sub_st = subtilis_conds[sub_s_i:]
                    sub_it = iron_conds[sub_i_i:]
                    sub_tt = timeseries_conds[sub_t_i:]                    

                    (bs_e, bs_t, bs_genes, bs_tfs) = ba.load_B_subtilis(sub_st)
                    (ba_e, ba_t, ba_genes, ba_tfs) = ba.load_B_anthracis(sub_it, sub_tt)

                    corr += ba.betas_fused_corr('tmp2_subtilis', 'tmp2_anthracis', orth)
                    print corr/rep
                    eval_s = ba.eval_prediction('tmp2_subtilis', bs_e, bs_t, bs_genes, bs_tfs,'R2')
                    eval_a = ba.eval_prediction('tmp2_anthracis', ba_e, ba_t, ba_genes, ba_tfs,'R2')

                    (net, bs_genes, bs_tfs) = ba.load_network('tmp2_subtilis')
                    aupr += ba.eval_network_pr(net, bs_genes, bs_tfs, BS_priors)
                    print aupr/rep
                    acc_s += eval_s
                    acc_a += eval_a
                writestr = 'lamP=%f\tlamS=%f\tlamR=%f\tsubtilis=%f\tanthracis=%f\taupr=%f\tcorr_bs=%f\n' % (lamP, lamS, lamR, acc_s/repeats, acc_a/repeats, aupr/repeats, corr/repeats)
                outf.write(writestr)
                print writestr
                    
    outf.close()