This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import numpy as np | |
import torch | |
from sklearn.preprocessing import StandardScaler | |
# load graph from networkx library | |
G = nx.karate_club_graph() | |
# retrieve the labels for each node | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import pandas as pd | |
from torch_geometric.data import InMemoryDataset, Data | |
from sklearn.model_selection import train_test_split | |
import torch_geometric.transforms as T | |
# custom dataset | |
class KarateDataset(InMemoryDataset): | |
def __init__(self, transform=None): | |
super(KarateDataset, self).__init__('.', transform, None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch_geometric.nn import GCNConv | |
# GCN model with 2 layers | |
class Net(torch.nn.Module): | |
def __init__(self): | |
super(Net, self).__init__() | |
self.conv1 = GCNConv(data.num_features, 16) | |
self.conv2 = GCNConv(16, int(data.num_classes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torch.manual_seed(42) | |
optimizer_name = "Adam" | |
lr = 1e-1 | |
optimizer = getattr(torch.optim, optimizer_name)(model.parameters(), lr=lr) | |
epochs = 200 | |
def train(): | |
model.train() | |
optimizer.zero_grad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ge import DeepWalk | |
# load graph from networkx library | |
G = nx.karate_club_graph() | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) | |
# convert nodes from int to str format | |
keys = np.arange(0,34) | |
values = [str(i) for i in keys] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.manifold import TSNE | |
import matplotlib.pyplot as plt | |
# retrieve the labels for each node | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) | |
# assigning colours to node labels | |
color_map = [] | |
for i in labels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import numpy as np | |
import torch | |
# load graph from networkx library | |
G = nx.karate_club_graph() | |
# retrieve the labels for each node | |
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import pandas as pd | |
from torch_geometric.data import InMemoryDataset, Data | |
from sklearn.model_selection import train_test_split | |
import torch_geometric.transforms as T | |
# custom dataset | |
class KarateDataset(InMemoryDataset): | |
def __init__(self, transform=None): | |
super(KarateDataset, self).__init__('.', transform, None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import dgl | |
import torch | |
from dgl.data import DGLDataset | |
from sklearn.model_selection import train_test_split | |
# prepare the embeddings corresponding to each node | |
nodes = pd.DataFrame(list(H.nodes())) | |
nodes.columns = ['nodes'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import networkx as nx | |
from spektral.data import Dataset | |
from sklearn.preprocessing import OneHotEncoder | |
from sklearn.model_selection import train_test_split | |
from spektral.transforms import AdjToSpTensor, LayerPreprocess | |
from spektral.layers import GCNConv | |
# spektral custom dataset class | |
class KarateDataset(Dataset): |
OlderNewer