图神经网络构建代码

上传者: jinmaodao1990 | 上传时间: 2019-12-21 20:00:21 | 文件大小: 119KB | 文件类型: zip
# GPF ## 一、GPF(Graph Processing Flow):利用图神经网络处理问题的一般化流程 1、图节点预表示:利用NE框架,直接获得全图每个节点的Embedding; 2、正负样本采样:(1)单节点样本;(2)节点对样本; 3、抽取封闭子图:可做类化处理,建立一种通用图数据结构; 4、子图特征融合:预表示、节点特征、全局特征、边特征; 5、网络配置:可以是图输入、图输出的网络;也可以是图输入,分类/聚类结果输出的网络; 6、训练和测试; ## 二、主要文件: 1、graph.py:读入图数据; 2、embeddings.py:预表示学习; 3、sample.py:采样; 4、subgraphs.py/s2vGraph.py:抽取子图; 5、batchgraph.py:子图特征融合; 6、classifier.py:网络配置; 7、parameters.py/until.py:参数配置/帮助文件; ## 三、使用 1、在parameters.py中配置相关参数(可默认); 2、在example/文件夹中运行相应的案例文件--包括链接预测、节点状态预测; 以链接预测为例: ### 1、导入配置参数 ```from parameters import parser, cmd_embed, cmd_opt``` ### 2、参数转换 ``` args = parser.parse_args() args.cuda = not args.noCuda and torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) if args.hop != 'auto': args.hop = int(args.hop) if args.maxNodesPerHop is not None: args.maxNodesPerHop = int(args.maxNodesPerHop) ``` ### 3、读取数据 ``` g = graph.Graph() g.read_edgelist(filename=args.dataName, weighted=args.weighted, directed=args.directed) g.read_node_status(filename=args.labelName) ``` ### 4、获取全图节点的Embedding ``` embed_args = cmd_embed.parse_args() embeddings = embeddings.learn_embeddings(g, embed_args) node_information = embeddings #print node_information ``` ### 5、正负节点采样 ``` train, train_status, test, test_status = sample.sample_single(g, args.testRatio, max_train_num=args.maxTrainNum) ``` ### 6、抽取节点对的封闭子图 ``` net = until.nxG_to_mat(g) #print net train_graphs, test_graphs, max_n_label = subgraphs.singleSubgraphs(net, train, train_status, test, test_status, args.hop, args.maxNodesPerHop, node_information) print('# train: %d, # test: %d' % (len(train_graphs), len(test_graphs))) ``` ### 7、加载网络模型,并在classifier中配置相关参数 ``` cmd_args = cmd_opt.parse_args() cmd_args.feat_dim = max_n_label + 1 cmd_args.attr_dim = node_information.shape[1] cmd_args.latent_dim = [int(x) for x in cmd_args.latent_dim.split('-')] if len(cmd_args.latent_dim)

文件下载

资源详情

[{"title":"( 80 个子文件 119KB ) 图神经网络构建代码","children":[{"title":"GPF-master","children":[{"title":".gitignore <span style='color:#111;'> 1.17KB </span>","children":null,"spread":false},{"title":"GPF","children":[{"title":"data","children":[{"title":"Testdata.ipynb <span style='color:#111;'> 3.31KB </span>","children":null,"spread":false},{"title":"USAir.edgeList.txt <span style='color:#111;'> 15.84KB </span>","children":null,"spread":false},{"title":"karate.label.txt <span style='color:#111;'> 159B </span>","children":null,"spread":false},{"title":"USAir.mat <span style='color:#111;'> 5.09KB </span>","children":null,"spread":false},{"title":"USAir.label.txt <span style='color:#111;'> 1.84KB </span>","children":null,"spread":false},{"title":"karate.edgelist.txt <span style='color:#111;'> 389B </span>","children":null,"spread":false}],"spread":true},{"title":"GraphNet","children":[{"title":"pscn.py <span style='color:#111;'> 2.64KB </span>","children":null,"spread":false},{"title":"__init__.py <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"s2v_lib.py <span style='color:#111;'> 6.18KB </span>","children":null,"spread":false},{"title":"s2v_lib","children":[{"title":"mlp.py <span style='color:#111;'> 1.67KB </span>","children":null,"spread":false},{"title":"embedding.py <span style='color:#111;'> 4.74KB </span>","children":null,"spread":false},{"title":"Makefile <span style='color:#111;'> 825B </span>","children":null,"spread":false},{"title":"src","children":[{"title":"lib","children":[{"title":"config.cpp <span style='color:#111;'> 51B </span>","children":null,"spread":false},{"title":"graph_struct.cpp <span style='color:#111;'> 1.69KB </span>","children":null,"spread":false},{"title":"msg_pass.cpp <span style='color:#111;'> 2.68KB </span>","children":null,"spread":false}],"spread":true},{"title":"s2v_lib.cpp <span style='color:#111;'> 3.61KB </span>","children":null,"spread":false}],"spread":true},{"title":"build","children":[{"title":"dll","children":[{"title":"libs2v.d <span style='color:#111;'> 160B </span>","children":null,"spread":false},{"title":"libs2v.so <span style='color:#111;'> 32.46KB </span>","children":null,"spread":false}],"spread":false},{"title":"lib","children":[{"title":"config.o <span style='color:#111;'> 2.05KB </span>","children":null,"spread":false},{"title":"graph_struct.o <span style='color:#111;'> 15.05KB </span>","children":null,"spread":false},{"title":"config.d <span style='color:#111;'> 56B </span>","children":null,"spread":false},{"title":"msg_pass.d <span style='color:#111;'> 105B </span>","children":null,"spread":false},{"title":"graph_struct.d <span style='color:#111;'> 74B </span>","children":null,"spread":false},{"title":"msg_pass.o <span style='color:#111;'> 8.88KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"s2v_lib.py <span style='color:#111;'> 6.16KB </span>","children":null,"spread":false},{"title":"include","children":[{"title":"msg_pass.h <span style='color:#111;'> 453B </span>","children":null,"spread":false},{"title":"config.h <span style='color:#111;'> 657B </span>","children":null,"spread":false},{"title":"s2v_lib.h <span style='color:#111;'> 847B </span>","children":null,"spread":false},{"title":"graph_struct.h <span style='color:#111;'> 2.60KB </span>","children":null,"spread":false}],"spread":false},{"title":"pytorch_util.py <span style='color:#111;'> 1.81KB </span>","children":null,"spread":false}],"spread":true},{"title":"gat.py <span style='color:#111;'> 2.17KB </span>","children":null,"spread":false},{"title":"gcn_layers.py <span style='color:#111;'> 1.22KB </span>","children":null,"spread":false},{"title":"pytorch_util.py <span style='color:#111;'> 1.81KB </span>","children":null,"spread":false},{"title":"gcn.py <span style='color:#111;'> 1.83KB </span>","children":null,"spread":false},{"title":"mlp_dropout.py <span style='color:#111;'> 1.94KB </span>","children":null,"spread":false},{"title":"DGCNN.py <span style='color:#111;'> 5.68KB </span>","children":null,"spread":false},{"title":"gat_layers.py <span style='color:#111;'> 3.61KB </span>","children":null,"spread":false}],"spread":false},{"title":"src","children":[{"title":"classifier.py <span style='color:#111;'> 4.95KB </span>","children":null,"spread":false},{"title":"subgraphs.py <span style='color:#111;'> 10.79KB </span>","children":null,"spread":false},{"title":"sample.py <span style='color:#111;'> 2.24KB </span>","children":null,"spread":false},{"title":"batchgraph.py <span style='color:#111;'> 1.86KB </span>","children":null,"spread":false},{"title":"graph.py <span style='color:#111;'> 3.30KB </span>","children":null,"spread":false},{"title":"Parameters.py <span style='color:#111;'> 8.08KB </span>","children":null,"spread":false},{"title":"s2vGraph.py <span style='color:#111;'> 1.22KB </span>","children":null,"spread":false},{"title":"main_pairs.py <span style='color:#111;'> 2.43KB </span>","children":null,"spread":false},{"title":"main_single.py <span style='color:#111;'> 2.50KB </span>","children":null,"spread":false},{"title":"main_fixDegree.py <span style='color:#111;'> 2.51KB </span>","children":null,"spread":false},{"title":"embeddings.py <span style='color:#111;'> 3.56KB </span>","children":null,"spread":false},{"title":"until.py <span style='color:#111;'> 600B </span>","children":null,"spread":false}],"spread":false},{"title":"example","children":[{"title":"main_pairs.py <span style='color:#111;'> 2.48KB </span>","children":null,"spread":false},{"title":"main_single.py <span style='color:#111;'> 2.55KB </span>","children":null,"spread":false},{"title":"main_fixDegree.py <span style='color:#111;'> 2.56KB </span>","children":null,"spread":false}],"spread":true},{"title":"readme.txt <span style='color:#111;'> 776B </span>","children":null,"spread":false},{"title":"NE","children":[{"title":"sdne.py <span style='color:#111;'> 11.27KB </span>","children":null,"spread":false},{"title":"gcn","children":[{"title":"__init__.py <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"layers.py <span style='color:#111;'> 5.75KB </span>","children":null,"spread":false},{"title":"models.py <span style='color:#111;'> 6.21KB </span>","children":null,"spread":false},{"title":"utils.py <span style='color:#111;'> 5.31KB </span>","children":null,"spread":false},{"title":"metrics.py <span style='color:#111;'> 691B </span>","children":null,"spread":false},{"title":"gcnAPI.py <span style='color:#111;'> 6.73KB </span>","children":null,"spread":false},{"title":"gcn.py <span style='color:#111;'> 6.73KB </span>","children":null,"spread":false},{"title":"inits.py <span style='color:#111;'> 810B </span>","children":null,"spread":false},{"title":"train.py <span style='color:#111;'> 3.90KB </span>","children":null,"spread":false}],"spread":true},{"title":"__init__.py <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"hope.py <span style='color:#111;'> 1.61KB </span>","children":null,"spread":false},{"title":"gf.py <span style='color:#111;'> 2.48KB </span>","children":null,"spread":false},{"title":"lap.py <span style='color:#111;'> 1.77KB </span>","children":null,"spread":false},{"title":"graph.py <span style='color:#111;'> 3.37KB </span>","children":null,"spread":false},{"title":"grarep.py <span style='color:#111;'> 2.26KB </span>","children":null,"spread":false},{"title":"__main__.py <span style='color:#111;'> 8.40KB </span>","children":null,"spread":false},{"title":"walker.py <span style='color:#111;'> 5.98KB </span>","children":null,"spread":false},{"title":"node2vec.py <span style='color:#111;'> 1.56KB </span>","children":null,"spread":false},{"title":"line.py <span style='color:#111;'> 10.81KB </span>","children":null,"spread":false},{"title":"classify.py <span style='color:#111;'> 3.10KB </span>","children":null,"spread":false},{"title":"lle.py <span style='color:#111;'> 1.72KB </span>","children":null,"spread":false},{"title":"tadw.py <span style='color:#111;'> 4.27KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"LICENSE <span style='color:#111;'> 1.04KB </span>","children":null,"spread":false},{"title":"README.md <span style='color:#111;'> 6.30KB </span>","children":null,"spread":false},{"title":"gpf.JPG <span style='color:#111;'> 19.66KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明