示例#1
0
    def test_reconstruct_graph(self):
        """
        Test the reconstruction of an inputlayer.
        """
        graph = gb.create_directed_barbell(10, 10)
        random.seed(2)
        for u in graph.nodes(data=True):
            u[1]['label1'] = int(u[0])
            u[1]['label2'] = random.uniform(0.0, 1.0)
        gae = GraphAutoEncoder(graph,
                               learning_rate=0.01,
                               support_size=[5, 5],
                               dims=[3, 5, 7, 6, 2],
                               batch_size=12,
                               max_total_steps=100,
                               verbose=True)

        l1_struct, graph2 = gae.get_l1_structure(15, show_graph=False)
        # check if the nodes of the reconstructed graph is equal to 5
        self.assertEqual(
            graph2.number_of_nodes(), 5,
            "Number of nodes in reconstructed graph does not match with expectations"
        )

        # check if the returned nodes are correct by summing the node values.
        sum_values = np.sum(l1_struct, 1)
        self.assertAlmostEqual(
            sum_values[0, 1], 120, 4,
            "sum of nodes ids in reconstructed graph does not match with expectations"
        )
        self.assertAlmostEqual(
            sum_values[0, 0], 2.399999, 4,
            "sum of edges in reconstructed graph does not match with expectations"
        )
示例#2
0
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import pickle
import random
#%%
graph = gb.create_directed_barbell(10, 10)
random.seed(2)
for u in graph.nodes(data=True):
    u[1]['label1'] = int(u[0])
    u[1]['label2'] = random.uniform(0.0, 1.0)
gae = GraphAutoEncoder(graph, learning_rate=0.01, support_size=[5, 5], dims=[3, 5, 7, 6, 2],
                       batch_size=12, max_total_steps=10, verbose=True, useBN=True)
gae.fit()
embed = gae.calculate_embeddings()
l1_struct, graph2 = gae.get_l1_structure(15, show_graph=True, node_label='feat0')

#%%

# print(l1_struct)
# train_res = {}
# for i in range(len(gae.dims)):
#     train_res["l"+str(i+1)] = gae.train_layer(i+1)

# train_res['all'] = gae.train_layer(len(gae.dims), all_layers=True, dropout=None)
# embed = gae.calculate_embeddings()
# filename = '/Users/tonpoppe/workspace/GraphCase/data/model1'
# gae.save_model(filename)

# gae2 = GraphAutoEncoder(graph, learning_rate=0.01, support_size=[5, 5], dims=[3, 5, 7, 6, 2],
#                        batch_size=12, max_total_steps=100, verbose=True)
示例#3
0
                                                        2,
                                                        weight=1)
    color_dict = {0: 'red', 1: 'lightblue', 2: 'lightgreen'}
    for node in nt.nodes:
        node["color"] = color_dict[length_dict[node['id']]]
        node['shape'] = 'circle'
    for edge in nt.edges:
        edge['label'] = round(edge['weight'], 2)
    nt.toggle_physics(False)
    return nt


nt = plot_node(graph, 6)
nt.show(ROOT_FOLDER + "/temp/nx.html")

#%%
df, _, pv_graph = gae.get_l1_structure(6, node_label='feat0', get_pyvis=True)
# pv_graph.toggle_physics(False)
pv_graph.show(ROOT_FOLDER + "/temp/nx2.html")
pd_df = pd.DataFrame(data=np.squeeze(df),
                     columns=["edge", 'node_id', "label2"])

# %%

# nt = net.Network(directed=True, notebook=True)
# # populates the nodes and edges data structures
# nt.from_nx(graph)
# nt.set_edge_smooth('dynamic')
# nt.show("nx.html")
# %%