This file contains hidden or 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 | |
| def gcn_message(edge): | |
| # In: a graph edge | |
| # Out: a message containing the features of the source node | |
| return {'msg' : edges.src['h']} | |
| def gcn_reduce(node): | |
| # In: a graph node |
This file contains hidden or 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
| class GCN(nn.Module): | |
| def __init__(self, in_feats, hidden_size, num_classes): | |
| super(GCN, self).__init__() | |
| self.gcn1 = GCNLayer(in_feats, hidden_size) | |
| self.gcn2 = GCNLayer(hidden_size, num_classes) | |
| self.softmax = nn.Softmax() | |
| def forward(self, g, inputs): | |
| h = self.gcn1(g, inputs) | |
| h = torch.relu(h) |
This file contains hidden or 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
| features = torch.eye(node_count) | |
| print(features[2]) | |
| tensor([[0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., | |
| 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) |
This file contains hidden or 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 dgl | |
| import torch | |
| import numpy as np | |
| import pickle | |
| node_count = 34 | |
| epochs = 30 | |
| # Load edges | |
| with open('edge_list.pickle', 'rb') as f: |
This file contains hidden or 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
| edge_list = [] | |
| for e in g.E().toList(): | |
| edge_list.append((e.inV.id, e.outV.id)) | |
| print(edge_list) | |
| [('0', '8'), ('1', '17'), ('24', '31'), ('13', '33'), ('0', '1'), ('2', '8'), ('0', '19'), | |
| ('25', '31'), ('14', '33'), ('0', '2'), ('2', '9'), ('1', '19'), ('28', '31'), ('15', '33'), | |
| ('1', '2'), ('0', '10'), ('0', '21'), ('2', '32'), ('18', '33'), ('0', '3'), ('4', '10'), | |
| ('1', '21'), ('8', '32'), ('19', '33'), ('1', '3'), ('5', '10'), ('23', '25'), ('14', '32'), | |
| ('20', '33'), ('2', '3'), ('0', '11'), ('24', '25'), ('15', '32'), ('22', '33'), ('0', '4'), |
This file contains hidden or 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
| # Print all vertices (don't run this on large database!) | |
| print(g.V().toList()) | |
| [v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17], v[18], v[19], v[20], v[21], v[22], v[23], v[24], v[25], v[26], v[27], v[28], v[29], v[30], v[31], v[32], v[33]] | |
| # Print all edges (don't run this on large database!) | |
| print(g.E().toList()) | |
| [e[edge15][8-edge->0], e[edge31][17-edge->1], e[edge47][31-edge->24], e[edge63][33-edge->13], e[edge0][1-edge->0], e[edge16][8-edge->2], e[edge32][19-edge->0], e[edge48][31-edge->25], e[edge64][33-edge->14], e[edge1][2-edge->0], e[edge17][9-edge->2], e[edge33][19-edge->1], e[edge49][31-edge->28], e[edge65][33-edge->15], e[edge2][2-edge->1], e[edge18][10-edge->0], e[edge34][21-edge->0], e[edge50][32-edge->2], e[edge66][33-edge->18], e[edge3][3-edge->0], e[edge19][10-edge->4], e[edge35][21-edge->1], e[edge51][32-edge->8], e[edge67][33-edge->19], e[edge4][3-edge->1], e[edge20][10-edge->5], e[edge36][25-edge->23], e[edge52][32-edge-> |
This file contains hidden or 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 gremlin_python import statics | |
| from gremlin_python.structure.graph import Graph | |
| from gremlin_python.process.graph_traversal import __ | |
| from gremlin_python.process.strategies import * | |
| from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection | |
| graph = Graph() | |
| remoteConn = DriverRemoteConnection('ws://ENDPOINT:PORT/gremlin','g') | |
| g = graph.traversal().withRemote(remoteConn) |
This file contains hidden or 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
| ~id | name:String | |
|---|---|---|
| 0 | node0 | |
| 1 | node1 | |
| 2 | node2 | |
| 3 | node3 | |
| 4 | node4 | |
| 5 | node5 | |
| 6 | node6 | |
| 7 | node7 | |
| 8 | node8 |
This file contains hidden or 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
| ~id | ~from | ~to | |
|---|---|---|---|
| edge0 | 1 | 0 | |
| edge1 | 2 | 0 | |
| edge2 | 2 | 1 | |
| edge3 | 3 | 0 | |
| edge4 | 3 | 1 | |
| edge5 | 3 | 2 | |
| edge6 | 4 | 0 | |
| edge7 | 5 | 0 | |
| edge8 | 6 | 0 |
This file contains hidden or 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
| AWSTemplateFormatVersion: 2010-09-09 | |
| Parameters: | |
| ModelName: | |
| Description: First model name | |
| Type: String | |
| ModelDataUrl: | |
| Description: Location of first model artefact | |
| Type: String | |
| ModelName2: |