Beispiel #1
0
def main(layer, edge_path, edge_filename, output_path, walk_filename, n,
         length, p, q, is_weighted, is_directed, job_id):

    if is_weighted == 1:
        weighted = True
    else:
        weighted = False

    if is_directed == 1:
        directed = True
    else:
        directed = False

    file_name = os.path.join(edge_path, layer, edge_filename)
    tmp_edge = pd.read_csv(file_name, index_col="Unnamed: 0")
    tmp_edge[['source', 'target']] = tmp_edge[['source', 'target']].astype(str)

    # 1) for each layer first create a nx-Digraph
    nxg = graph_utils.Build_nx_Graph(source_target_weight=tmp_edge,
                                     directed=True)

    # 2) Create stellar Di graphs
    sdg = StellarDiGraph(nxg)

    # 3) Initialize the walk and do the begin checks
    BDWW.BeginWalk(sdg, begin_checks=True, weighted=True, directed=True)

    rw = BDWW.BiasedDirectedRandomWalk(sdg,
                                       directed=True,
                                       weighted=True,
                                       begin_checks=False)

    nodes = list(sdg.nodes())
    walks = rw.run(nodes=nodes,
                   length=length,
                   n=n,
                   p=p,
                   q=q,
                   weighted=weighted,
                   directed=directed)

    result_path = os.path.join(output_path, layer)
    if not os.path.isdir(result_path):
        print("making a new directory for the output")
        os.mkdir(result_path)

    if job_id is not None:
        walk_file_name = str.split(walk_filename,
                                   ".")[0] + "_" + str(job_id) + ".csv"
    else:
        walk_file_name = walk_filename
    utils.Write_List_of_Lists_from_CSV(result_path, walk_file_name, walks)
Beispiel #2
0
# - We typically pass all nodes to `corrupted_generator.flow` because this is an unsupervised task
# - We don't pass `targets` to `corrupted_generator.flow` because these are binary labels (true nodes, false nodes) that are created by `CorruptedGenerator`

# %%
# HinSAGE model 
graphsage_generator = DirectedGraphSAGENodeGenerator(
    G, batch_size=50, in_samples=[30, 5], out_samples=[30, 5], seed=0
)

graphsage_model = DirectedGraphSAGE(
    layer_sizes=[128, 16], activations=["relu", "relu"], generator=graphsage_generator, aggregator=MeanPoolingAggregator
)


corrupted_generator = CorruptedGenerator(graphsage_generator)
gen = corrupted_generator.flow(G.nodes())

# %% [markdown]
# ## Model Creation and Training
# 
# We create and train our `DeepGraphInfomax` model. Note that the loss used here must always be `tf.nn.sigmoid_cross_entropy_with_logits`.

# %%
import tensorflow as tf


# %%
infomax = DeepGraphInfomax(graphsage_model, corrupted_generator)
x_in, x_out = infomax.in_out_tensors()

model = Model(inputs=x_in, outputs=x_out)
Beispiel #3
0
import os
import pandas as pd
from cell import graph_utils
import cell.BiasedDirectedWeightedWalk as BDWW
from stellargraph import StellarDiGraph

layer = 'base_unnormalized_allcombined'

edge_path = "/Users/fahimehb/Documents/NPP_GNN_project/dat/edgelists/VISp/"
edge_filename = "selfconnection_added_edges_node21_32_removed.csv"

file_name = os.path.join(edge_path, layer, edge_filename)
tmp_edge = pd.read_csv(file_name, index_col="Unnamed: 0")
tmp_edge[['source', 'target']] = tmp_edge[['source', 'target']].astype(str)
nxg = graph_utils.build_nx_graph(source_target_weight=tmp_edge, directed=True)
sdg = StellarDiGraph(nxg)
BDWW.BeginWalk(sdg, begin_checks=True, weighted=True, directed=True)
rw = BDWW.BiasedDirectedRandomWalk(sdg,
                                   directed=True,
                                   weighted=True,
                                   begin_checks=False)

nodes = list(sdg.nodes())
walks = rw.run(nodes=nodes,
               length=2,
               n=1,
               p=1,
               q=1,
               weighted=True,
               directed=True)
print(walks)