Beispiel #1
0
def run_gmgan_for_docking(nmodel=3, MAX_EXPNUM=1, nsamples=[1, 10, 30, 50], num_train_input=100, sup_max_epoch=10000, max_epochs=20000):
    queries = np.loadtxt('data/docking_queries.csv', delimiter=',')
    vmps = np.loadtxt('data/docking_weights.csv', delimiter=',')
    starts = np.loadtxt('data/docking_starts.csv', delimiter=',')
    goals = np.loadtxt('data/docking_goals.csv', delimiter=',')

    # clean the data
    wtest = np.expand_dims(vmps, axis=1)
    cc, successId = evaluate_docking(wtest, queries, starts,goals)
    data = np.concatenate([queries, starts, goals], axis=1)
    data = data[successId, :]
    vmps = vmps[successId,:]
    knum = np.shape(vmps)[1]
    rstates = np.random.randint(0, 100, size=MAX_EXPNUM)

    nn_structure = {'d_feat': 20,
                    'feat_layers': [40],
                    'mean_layers': [60],
                    'scale_layers': [60],
                    'mixing_layers': [60],
                    'discriminator': [20],
                    'lambda': [10],
                    'd_response': [40,5],
                    'd_context': [10,5]}
    gmgan = GMGAN(n_comps=nmodel, context_dim=6, response_dim=knum, nn_structure=nn_structure)

    gmgan.entropy_ratio = 0.0

    gmgan.lratio['entropy'] = 200
    gmgan.gen_sup_lrate = 0.00005
    gmgan.gen_adv_lrate = 0.00005
    gmgan.dis_lrate = 0.0002
    gmgan.sup_max_epoch = sup_max_epoch

    csrates = np.zeros(shape=(MAX_EXPNUM, len(nsamples)))
    train_input = np.random.uniform(low=np.min(queries, axis=0), high=np.max(queries, axis=0), size=(num_train_input, np.shape(queries)[1]))

    for expId in range(MAX_EXPNUM):
        trdata, tdata, trvmps, tvmps = train_test_split(data, vmps, test_size=0.3, random_state=rstates[expId])
        trdata, _, trvmps, _ = train_test_split(trdata, trvmps, test_size=0.3, random_state=rstates[expId])
        print("use {} data for training and {} data for testing".format(np.shape(trdata)[0], np.shape(tdata)[0]))
        print("======== Exp: {} ========".format(expId))
        trqueries = trdata[:,0:6]

        gmgan.create_network()#num_real_data=np.shape(trdata)[0])
        gmgan.init_train()
        gmgan.train(train_context=train_input, real_context=trqueries, real_response=trvmps, max_epochs=max_epochs, is_load=False, is_save=False)

        tqueries = tdata[:, 0:6]
        for i in range(len(nsamples)):
            wout = gmgan.generate(tqueries, nsamples[i])
            starts = tdata[:, 6:8]
            goals = tdata[:, 8:10]
            srate, _ = evaluate_docking(wout, tqueries, starts, goals)
            csrates[expId, i] = srate

    srates = np.mean(csrates, axis=0)
    return srates
Beispiel #2
0
def train_evaluate_mdgan_for_docking(mdgan,
                                     trqueries,
                                     trvmps,
                                     tdata,
                                     use_entropy=False,
                                     max_epochs=20000):
    if use_entropy:
        mdgan.entropy_ratio = 0.2
    else:
        mdgan.entropy_ratio = 0.0

    train_input = np.random.uniform(low=np.min(trqueries, axis=0),
                                    high=np.max(trqueries, axis=0),
                                    size=(10000, np.shape(trqueries)[1]))
    mdgan.create_network(num_real_data=np.shape(trqueries)[0])
    mdgan.init_train()
    mdgan.train(train_context=train_input,
                real_context=trqueries,
                real_response=trvmps,
                max_epochs=max_epochs,
                is_load=False,
                is_save=False)

    tqueries = tdata[:, 0:6]
    starts = tdata[:, 6:8]
    goals = tdata[:, 8:10]
    wout = mdgan.generate_multi(tqueries, 1)
    srate, _ = evaluate_docking(wout, tqueries, starts, goals)
    return srate
Beispiel #3
0
def train_evaluate_gmgan_for_docking(gmgan, trqueries, trvmps, tdata, use_entropy=False, max_epochs=20000, sup_max_epoch=0,
                                     sample_num=1, g_lrate=0.0003, d_lrate=0.001):
    if use_entropy:
        gmgan.entropy_ratio = 1
    else:
        gmgan.entropy_ratio = 0

    gmgan.lratio['entropy'] = 10
    gmgan.lratio['adv_cost'] = 0
    gmgan.gen_sup_lrate = g_lrate
    gmgan.gen_adv_lrate = g_lrate
    gmgan.dis_lrate = d_lrate
    gmgan.sup_max_epoch = sup_max_epoch

    train_input = np.random.uniform(low=np.min(trqueries, axis=0), high=np.max(trqueries, axis=0), size=(10000, np.shape(trqueries)[1]))

    gmgan.create_network()
    gmgan.init_train()
    gmgan.train(train_context=train_input, real_context=trqueries, real_response=trvmps, max_epochs=max_epochs, is_load=False, is_save=False)

    tqueries = tdata[:, 0:6]
    starts = tdata[:, 6:8]
    goals = tdata[:, 8:10]
    wout = gmgan.generate(tqueries, 10000, n_output=sample_num)
    srate, _ = evaluate_docking(wout, tqueries, starts, goals)
    return srate
Beispiel #4
0
def train_evaluate_mdnmp_for_docking(mdnmp,
                                     trqueries,
                                     trvmps,
                                     tdata,
                                     max_epochs=20000,
                                     sample_num=1,
                                     learning_rate=0.00003):
    weights = np.ones(shape=(np.shape(trvmps)[0], 1))
    train_weights = np.copy(weights)
    mdnmp.build_mdn(learning_rate=learning_rate)
    mdnmp.init_train()
    isSuccess, nlls, ents = mdnmp.train(trqueries,
                                        trvmps,
                                        train_weights,
                                        max_epochs=max_epochs,
                                        is_load=False,
                                        is_save=False)

    srate = 0
    if isSuccess:
        tqueries = tdata[:, 0:6]
        wout, _ = mdnmp.predict(tqueries, sample_num)
        starts = tdata[:, 6:8]
        goals = tdata[:, 8:10]
        srate, _ = evaluate_docking(wout, tqueries, starts, goals)

    return srate, nlls, ents
Beispiel #5
0
def train_evaluate_baseline_for_docking(model_name,
                                        trqueries,
                                        trvmps,
                                        tdata,
                                        sample_num=1):

    model = possible_models[model_name]
    if model is not None:
        model.fit(trqueries, trvmps)

    tqueries = tdata[:, 0:6]
    starts = tdata[:, 6:8]
    goals = tdata[:, 8:10]
    wmeans = model.predict(tqueries)

    if model is not None:
        wouts = sample_baseline(wmeans, sample_num)
    else:
        wouts = np.random.uniform(low=trvmps.min(),
                                  high=trvmps.max(),
                                  size=(100, sample_num, np.shape(trvmps)[1]))

    srate, _ = evaluate_docking(wouts, tqueries, starts, goals)
    return srate
parser = OptionParser()
parser.add_option("-m", "--nmodel", dest="nmodel", type="int", default=3)
parser.add_option("-n", "--num_exp", dest="expnum", type="int", default=1)
parser.add_option("-d", "--result_dir", dest="result_dir", type="string", default="results_compare_docking")
(options, args) = parser.parse_args(sys.argv)


queries = np.loadtxt('../data/docking_queries.csv', delimiter=',')
vmps = np.loadtxt('../data/docking_weights.csv', delimiter=',')
starts = np.loadtxt('../data/docking_starts.csv', delimiter=',')
goals = np.loadtxt('../data/docking_goals.csv', delimiter=',')


wtest = np.expand_dims(vmps, axis=1)
cc, successId = evaluate_docking(wtest, queries, starts,goals)
data = np.concatenate([queries, starts, goals], axis=1)
data = data[successId, :]
vmps = vmps[successId,:]
knum = np.shape(vmps)[1]
rstates = np.random.randint(0, 100, size=options.expnum)

# create mdnmp
mdnmp_struct = {'d_feat': 20,
                'feat_layers': [40], #[60]
                'mean_layers': [60], #[60]
                'scale_layers': [60],
                'mixing_layers': [20]}
mdnmp = MDNMP(n_comps=options.nmodel, d_input=6, d_output=knum, nn_structure=mdnmp_struct, scaling=1, var_init=VAR_INIT)

# create gmgan
Beispiel #7
0
def run_mdnmp_for_docking(nmodel=3,
                          MAX_EXPNUM=20,
                          use_entropy_cost=[False, True],
                          model_names=["Original MDN", "Entropy MDN"],
                          nsamples=[1, 10, 30, 50, 70]):
    queries = np.loadtxt('data/docking_queries.csv', delimiter=',')
    vmps = np.loadtxt('data/docking_weights.csv', delimiter=',')
    starts = np.loadtxt('data/docking_starts.csv', delimiter=',')
    goals = np.loadtxt('data/docking_goals.csv', delimiter=',')

    # clean the data
    wtest = np.expand_dims(vmps, axis=1)
    cc, successId = evaluate_docking(wtest, queries, starts, goals)
    data = np.concatenate([queries, starts, goals], axis=1)
    data = data[successId, :]
    vmps = vmps[successId, :]
    knum = np.shape(vmps)[1]

    rstates = np.random.randint(0, 100, size=MAX_EXPNUM)
    srates = {}

    nn_structure = {
        'd_feat': 20,
        'feat_layers': [40],
        'mean_layers': [60],
        'scale_layers': [60],
        'mixing_layers': [60]
    }

    for k in range(len(use_entropy_cost)):
        mdnmp = MDNMP(n_comps=nmodel,
                      d_input=6,
                      d_output=knum,
                      nn_structure=nn_structure,
                      scaling=1)

        if use_entropy_cost[k]:
            mdnmp.lratio['entropy'] = 1
        else:
            mdnmp.lratio['entropy'] = 0

        csrates = np.zeros(shape=(MAX_EXPNUM, len(nsamples)))

        for expId in range(MAX_EXPNUM):
            trdata, tdata, trvmps, tvmps = train_test_split(
                data, vmps, test_size=0.3, random_state=rstates[expId])
            trdata, _, trvmps, _ = train_test_split(
                trdata, trvmps, test_size=0.3, random_state=rstates[expId])
            print("use {} data for training and {} data for testing".format(
                np.shape(trdata)[0],
                np.shape(tdata)[0]))
            print("======== Exp: {} with {} ========".format(
                expId, model_names[k]))

            weights = np.ones(shape=(np.shape(trvmps)[0], 1))
            train_weights = np.copy(weights)

            trqueries = trdata[:, 0:6]
            mdnmp.build_mdn(learning_rate=0.00003)
            mdnmp.init_train()
            mdnmp.train(trqueries,
                        trvmps,
                        train_weights,
                        max_epochs=20000,
                        is_load=False,
                        is_save=False)
            tqueries = tdata[:, 0:6]

            for i in range(len(nsamples)):
                wout, _ = mdnmp.predict(tqueries, nsamples[i])
                starts = tdata[:, 6:8]
                goals = tdata[:, 8:10]
                srate, _ = evaluate_docking(wout, tqueries, starts, goals)
                csrates[expId, i] = srate

        srates[model_names[k]] = np.mean(csrates, axis=0)

    return srates