Пример #1
0
def sequential(graph_stats):
    prev = graph_stats[0]
    for curr in graph_stats[1:]:
        comparator = GraphPairCompare(prev, curr)
        dist = comparator.js_distance()
        yield dist
        prev = curr
def main():
    base_path = '/data/infinity-mirror/'
    input_path = '/home/dgonza26/infinity-mirror/input'
    dataset = 'flights'
    model = 'GraphRNN'

    output_path = os.path.join(base_path, 'stats', 'degree')

    abs_lambda = []
    trials = []

    R = [(root, generation) for root, generation in load_data(
        os.path.join(base_path, 'cleaned'), dataset)]
    R.sort(key=lambda x: x[1])
    R = [root for (root, generation) in R]

    if dataset == 'clique-ring-500-4':
        G = nx.ring_of_cliques(500, 4)
    else:
        G = init(os.path.join(input_path, f'{dataset}.g'))

    # add the initial graph and transpose the list
    roots = [list(r) for r in zip(*R)]

    cols = ['model', 'gen', 'abs']
    rows = {col: [] for col in cols}

    gs0 = GraphStats(graph=G, run_id=1)
    for i, chain in enumerate(roots, 1):
        print(f'chain: {i}')
        for idx, graph in enumerate(chain, 1):
            print(f'\tgen: {idx} ... ', end='', flush=True)
            comparator = GraphPairCompare(gs0, GraphStats(graph=graph,
                                                          run_id=1))
            try:
                rows['abs'].append(comparator.js_distance())
            except Exception as e:
                print(f'ERROR\n{e}')
            else:
                rows['model'].append('GraphRNN')
                rows['gen'].append(idx)
                print('done')

    df = pd.DataFrame(rows)
    print(df.head())
    df.to_csv(f'{output_path}/{dataset}_{model}_lambda.csv',
              float_format='%.7f',
              sep='\t',
              index=False,
              na_rep='nan')
    print(f'wrote {output_path}/{dataset}_{model}_lambda.csv')
    #df.to_csv(f'{output_path}/{dataset}_{model}_lambda.csv', float_format='%.7f', sep='\t', index=False, na_rep='nan')

    return
Пример #3
0
def absolute(graph_stats):
    for gs in graph_stats[1:]:
        comparator = GraphPairCompare(graph_stats[0], gs)
        dist = comparator.js_distance()
        yield dist