data_loader/data_helper.py
def load_dataset(ds_name):
    """
    construct graphs and labels from dataset text in data folder
    :param ds_name: name of data set you want to load
    :return: two numpy arrays of shape (num_of_graphs).
            the graphs array contains in each entry a ndarray represent adjacency matrix of a graph of shape (num_vertex, num_vertex, num_vertex_labels)
            the labels array in index i represent the class of graphs[i]
    """
    directory = BASE_DIR + "/data/benchmark_graphs/{0}/{0}.txt".format(ds_name)
    graphs = []
    labels = []
    with open(directory, "r") as data:
        num_graphs = int(data.readline().rstrip().split(" ")[0])
        for i in range(num_graphs):
            graph_meta = data.readline().rstrip().split(" ")
            num_vertex = int(graph_meta[0])
            curr_graph = np.zeros(shape=(num_vertex, num_vertex, NUM_LABELS[ds_name]+1), dtype=np.float32)
            labels.append(int(graph_meta[1]))
            for j in range(num_vertex):
                vertex = data.readline().rstrip().split(" ")
                if NUM_LABELS[ds_name] != 0:
                    curr_graph[j, j, int(vertex[0])+1]= 1.
                for k in range(2,len(vertex)):
                    curr_graph[j, int(vertex[k]), 0] = 1.
            curr_graph = noramlize_graph(curr_graph)
            graphs.append(curr_graph)
    graphs = np.array(graphs)
    for i in range(graphs.shape[0]):
        graphs[i] = np.transpose(graphs[i], [2,0,1])
    return graphs, np.array(labels)

    construct graphs and labels from dataset text in data folder
    :param ds_name: name of data set you want to load
    :return: two numpy arrays of shape (num_of_graphs).
            the graphs array contains in each entry a ndarray represent adjacency matrix of a graph of shape (num_vertex, num_vertex, num_vertex_labels)
            the labels array in index i represent the class of graphs[i]
    
construct graphs and labels from dataset text in data folder
construct graphs and labels from dataset text in data folder
def load_dataset(ds_name):
    directory = BASE_DIR + "/data/benchmark_graphs/{0}/{0}.txt".format(ds_name)
    graphs = []
    labels = []
    with open(directory, "r") as data:
        num_graphs = int(data.readline().rstrip().split(" ")[0])
        for i in range(num_graphs):
            graph_meta = data.readline().rstrip().split(" ")
            num_vertex = int(graph_meta[0])
            curr_graph = np.zeros(shape=(num_vertex, num_vertex, NUM_LABELS[ds_name]+1), dtype=np.float32)
            labels.append(int(graph_meta[1]))
            for j in range(num_vertex):
                vertex = data.readline().rstrip().split(" ")
                if NUM_LABELS[ds_name] != 0:
                    curr_graph[j, j, int(vertex[0])+1]= 1.
                for k in range(2,len(vertex)):
                    curr_graph[j, int(vertex[k]), 0] = 1.
            curr_graph = noramlize_graph(curr_graph)
            graphs.append(curr_graph)
    graphs = np.array(graphs)
    for i in range(graphs.shape[0]):
        graphs[i] = np.transpose(graphs[i], [2,0,1])
    return graphs, np.array(labels)
def load_dataset ( ds_name ) : directory = BASE_DIR + "/data/benchmark_graphs/{0}/{0}.txt" . format ( ds_name ) graphs = [ ] labels = [ ] with open ( directory , "r" ) as data : num_graphs = int ( data . readline ( ) . rstrip ( ) . split ( " " ) [ 0 ] ) for i in range ( num_graphs ) : graph_meta = data . readline ( ) . rstrip ( ) . split ( " " ) num_vertex = int ( graph_meta [ 0 ] ) curr_graph = np . zeros ( shape = ( num_vertex , num_vertex , NUM_LABELS [ ds_name ] + 1 ) , dtype = np . float32 ) labels . append ( int ( graph_meta [ 1 ] ) ) for j in range ( num_vertex ) : vertex = data . readline ( ) . rstrip ( ) . split ( " " ) if NUM_LABELS [ ds_name ] != 0 : curr_graph [ j , j , int ( vertex [ 0 ] ) + 1 ] = 1. for k in range ( 2 , len ( vertex ) ) : curr_graph [ j , int ( vertex [ k ] ) , 0 ] = 1. curr_graph = noramlize_graph ( curr_graph ) graphs . append ( curr_graph ) graphs = np . array ( graphs ) for i in range ( graphs . shape [ 0 ] ) : graphs [ i ] = np . transpose ( graphs [ i ] , [ 2 , 0 , 1 ] ) return graphs , np . array ( labels )
construct graphs and labels from dataset text in data folder
construct graphs and labels from dataset text in data folder
"""
    construct graphs and labels from dataset text in data folder
    :param ds_name: name of data set you want to load
    :return: two numpy arrays of shape (num_of_graphs).
            the graphs array contains in each entry a ndarray represent adjacency matrix of a graph of shape (num_vertex, num_vertex, num_vertex_labels)
            the labels array in index i represent the class of graphs[i]
    """
two numpy arrays of shape (num_of_graphs).
the graphs array contains in each entry a ndarray represent adjacency matrix of a graph of shape (num_vertex, num_vertex, num_vertex_labels)
the labels array in index i represent the class of graphs[i]
two numpy arrays of shape ( num_of_graphs ) . the graphs array contains in each entry a ndarray represent adjacency matrix of a graph of shape ( num_vertex num_vertex num_vertex_labels ) the labels array in index i represent the class of graphs [ i ]
ds_name
name of data set you want to load
name of data set you want to load