def gs_nai( g, targets, num_samples, optimizer, batch_size=4, epochs=4, bias=True, dropout=0.0, normalize="l2", seed=0, shuffle=True, ): set_seed(seed) tf.random.set_seed(seed) if shuffle: random.seed(seed) nodes = list(g.nodes()) generator = GraphSAGENodeGenerator(g, batch_size, num_samples) train_gen = generator.flow(nodes, targets, shuffle=True) model = gs_nai_model( num_samples, generator, targets, optimizer, bias, dropout, normalize ) model.fit_generator( train_gen, epochs=epochs, verbose=1, use_multiprocessing=False, workers=4, shuffle=shuffle, ) return model
def gs_link_prediction( g, edge_ids, edge_labels, num_samples, optimizer, batch_size=4, epochs=4, bias=True, dropout=0.0, normalize="l2", seed=0, shuffle=True, ): set_seed(seed) tf.random.set_seed(seed) if shuffle: random.seed(seed) generator = GraphSAGELinkGenerator(g, batch_size, num_samples) train_gen = generator.flow(edge_ids, edge_labels, shuffle=True) model = gs_link_pred_model(num_samples, generator, optimizer, bias, dropout, normalize) model.fit( train_gen, epochs=epochs, verbose=1, use_multiprocessing=False, workers=4, shuffle=shuffle, ) return model
def set_all_seeds(seed: int): os.environ['PYTHONHASHSEED'] = str(seed) random.seed(seed) np.random.seed(seed) tf.random.set_seed(seed) sgrand.set_seed(seed) session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=0, inter_op_parallelism_threads=0) sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf) tf.compat.v1.keras.backend.set_session(sess)
def unsup_gs( g, num_samples, optimizer, batch_size=4, epochs=4, bias=True, dropout=0.0, normalize="l2", number_of_walks=1, walk_length=5, seed=0, shuffle=True, ): set_seed(seed) tf.random.set_seed(seed) if shuffle: random.seed(seed) nodes = list(g.nodes()) unsupervised_samples = UnsupervisedSampler(g, nodes=nodes, length=walk_length, number_of_walks=number_of_walks) generator = GraphSAGELinkGenerator(g, batch_size, num_samples) train_gen = generator.flow(unsupervised_samples) model = unsup_gs_model(num_samples, generator, optimizer, bias, dropout, normalize) model.fit( train_gen, epochs=epochs, verbose=1, use_multiprocessing=False, workers=4, shuffle=shuffle, ) return model
from sklearn import model_selection from sklearn.linear_model import LogisticRegression from sklearn.manifold import TSNE from IPython.display import display, HTML from tensorflow.keras.optimizers import Adam from tensorflow.keras.callbacks import EarlyStopping import tensorflow as tf from tensorflow.keras import Model if tf.test.gpu_device_name(): print('Default GPU Device:{}'.format(tf.test.gpu_device_name())) from pathlib import Path from helper import Preprocess, Feature set_seed(0) tf.random.set_seed(0) # %% [markdown] # ## Load graph and node features # %% DATA_DIR = Path("../../data/") FEATURE_DIR = Path("../../data/features/") FEATURE_NAME = 'adjacentTFs' MODEL_NAME='renamed_genes' data_processor = Preprocess() # %%