def test_tene():
    """
    Testing the TENE node embedding.
    """
    graph = nx.newman_watts_strogatz_graph(250, 10, 0.2)

    features = np.random.uniform(0, 1, (250, 128))
    model = TENE()
    model.fit(graph, features)
    embedding = model.get_embedding()

    assert embedding.shape[0] == graph.number_of_nodes()
    assert embedding.shape[1] == 2 * model.dimensions
    assert type(embedding) == np.ndarray

    graph = nx.newman_watts_strogatz_graph(150, 10, 0.2)

    features = np.random.uniform(0, 1, (150, 128))
    model = TENE(dimensions=8)
    model.fit(graph, features)
    embedding = model.get_embedding()

    assert embedding.shape[0] == graph.number_of_nodes()
    assert embedding.shape[1] == 2 * model.dimensions
    assert type(embedding) == np.ndarray
Beispiel #2
0
model.fit(g)
model.get_embedding()

#---------------
# TENE example
#---------------

g = nx.newman_watts_strogatz_graph(100, 20, 0.05)

t = np.random.uniform(0,1,(100,2000))

tp = nx.newman_watts_strogatz_graph(100, 20, 0.05)

tp = nx.adjacency_matrix(tp)

model = TENE()

model.fit(g, t)
model.get_embedding()

model.fit(g, tp)
model.get_embedding()

#---------------
# BANE example
#---------------

g = nx.newman_watts_strogatz_graph(100, 20, 0.05)

x = np.random.uniform(0,1,(100,2000))
import numpy as np
import networkx as nx
from karateclub.node_embedding.attributed import TENE

import dgl
from dgl.data import CoraGraphDataset

data = CoraGraphDataset()
g = data[0]
g = dgl.add_self_loop(
    dgl.node_subgraph(g, list(set(np.random.choice(len(g.nodes()), 5)))))
X = np.array(g.ndata['feat'])
g = dgl.to_networkx(g).to_undirected()

# g = nx.newman_watts_strogatz_graph(200, 20, 0.05)
#
# X = np.random.uniform(0, 1, (200, 200))

model = TENE()

model.fit(g, X)
embedding = model.get_embedding()
embedding = np.sum(embedding, axis=0)
# print(np.concatenate((embedding, embedding), axis=0).shape)
print(embedding.shape)
Beispiel #4
0
"""TENE example."""

import numpy as np
import networkx as nx
from karateclub.node_embedding.attributed import TENE

g = nx.newman_watts_strogatz_graph(200, 20, 0.05)

x = np.random.uniform(0, 1, (200, 200))

model = TENE()

model.fit(g, x)
Beispiel #5
0
                    help="the negative slope of leaky relu")
parser.add_argument('--early-stop',
                    action='store_true',
                    default=True,
                    help="indicates whether to use early stop or not")
parser.add_argument('--fastmode',
                    action="store_true",
                    default=False,
                    help="skip re-evaluate the validation set")
args = parser.parse_args()

data = CoraGraphDataset()
dataset = data[0]
dataset = dgl.add_self_loop(dataset)

embedding_model = TENE()
embedding_model.fit(
    dgl.to_networkx(dataset).to_undirected(), np.array(dataset.ndata['feat']))
dataset_embedding = embedding_model.get_embedding()
dataset_embedding = np.sum(dataset_embedding, axis=0)

heads = ([args.num_heads] * args.num_layers) + [args.num_out_heads]
GNN_model = GAT(args.num_layers, dataset.ndata['feat'].shape[1],
                args.num_hidden, data.num_labels, heads, F.elu, args.in_drop,
                args.attn_drop, args.negative_slope, args.residual)
GNN_model.load_state_dict(torch.load('GAT/es_checkpoint.pt'))

env = myenv(GNN_model, embedding_model, dataset)
env.reset()

# if gpu is to be used