Ejemplo n.º 1
0
def test_PhaGat2_classification():
    import phagraphnn.utilities as ut
    from phagraphnn.PhaGraph import PhaGraph,PhaNode

    data = ut.readChemblXls("./tests/data/CHE_3.xls")
    graph_list = []
    for i in range(0,len(data)):
        graph = PhaGraph()
        mol = ut.CDPLmolFromSmiles(data[i][1],True)
        graph(ut.CDPLphaGenerator(None,mol,"lig_only"))
        graph.setProperty("ic50",(0,1))
        graph_list.append(graph)
    from phagraphnn.DataPreparer import DataPreparer
    loader = DataPreparer(graph_list,3,property_string="ic50",mpn="gru",is_path=False)

    from phagraphnn.PhaGatModel2 import PhaGatModel2 as gat
    import tensorflow as tf

    seq = tf.keras.Sequential([
    tf.keras.layers.Dense(16, activation='relu', input_shape=(128,),name="first_layer"),
    tf.keras.layers.Dense(8, activation='relu',name="second_layer"),
    tf.keras.layers.Dense(2,activation= None)],name="output_NN")

    gat = gat(hidden_dim=32,output_nn=seq,regression = False)
    lr = 0.001
    gat.compile(loss=tf.keras.losses.BinaryCrossentropy(),
                optimizer=tf.keras.optimizers.Adam(lr))
    rec = tf.keras.metrics.MeanAbsoluteError()
    for batch in loader:
        inputs,af,other = batch
        gat(inputs)
        for epoch in range(0,10):
            pred,loss = gat.train(inputs=inputs,outputs=af,learning_rate=lr)
Ejemplo n.º 2
0
        16, activation='relu', input_shape=(32, ), name="first_layer"),
    tf.keras.layers.Dense(8, activation='relu', name="second_layer"),
    tf.keras.layers.Dense(1, activation=None)
],
                               name="output_NN")

seq_gru3 = tf.keras.Sequential([
    tf.keras.layers.Dense(
        16, activation='relu', input_shape=(32, ), name="first_layer"),
    tf.keras.layers.Dense(8, activation='relu', name="second_layer"),
    tf.keras.layers.Dense(1, activation=None)
],
                               name="output_NN")

# here the model is defined
gat = gat(hidden_dim=32, emb_dim=32, output_nn=seq_gat)
gat2 = gat2(hidden_dim=32, emb_dim=32, output_nn=seq_gat2, num_heads=3)
gru = gru(32, 1, seq_gru)
gru2 = gru2(32, 1, seq_gru2)
gru3 = gru3(32, 1, seq_gru3)
lr = 0.001
gat.compile(loss=tf.keras.losses.mse,
            optimizer=tf.keras.optimizers.RMSprop(lr))
gat2.compile(loss=tf.keras.losses.mse,
             optimizer=tf.keras.optimizers.RMSprop(lr))
gru.compile(loss=tf.keras.losses.mse,
            optimizer=tf.keras.optimizers.RMSprop(lr))
gru2.compile(loss=tf.keras.losses.mse,
             optimizer=tf.keras.optimizers.RMSprop(lr))
gru3.compile(loss=tf.keras.losses.mse,
             optimizer=tf.keras.optimizers.RMSprop(lr))