中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

儋州網站建設網站查詢域名解析

儋州網站建設,網站查詢域名解析,濟南制作網站有哪些,網站快速排名優(yōu)化價格目錄概述數(shù)據(jù)集定義Data LoaderDGL中的batched graph定義模型訓練參考概述 除了節(jié)點級別的問題——節(jié)點分類、邊級別的問題——鏈接預測之外,還有整個圖級別的問題——圖分類。經過聚合、傳遞消息得到節(jié)點和邊的新的表征后,映射得到整個圖的表征。 數(shù)據(jù)…

目錄

    • 概述
    • 數(shù)據(jù)集
    • 定義Data Loader
    • DGL中的batched graph
    • 定義模型
    • 訓練
    • 參考

概述

除了節(jié)點級別的問題——節(jié)點分類、邊級別的問題——鏈接預測之外,還有整個圖級別的問題——圖分類。經過聚合、傳遞消息得到節(jié)點和邊的新的表征后,映射得到整個圖的表征。

數(shù)據(jù)集

dataset = dgl.data.GINDataset('PROTEINS', self_loop=True)
g = dataset[0]
print(g)
print("Node feature dimensionality:", dataset.dim_nfeats)
print("Number of graph categories:", dataset.gclasses)
(Graph(num_nodes=42, num_edges=204,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), tensor(0))
Node feature dimensionality: 3
Number of graph categories: 2

共1113個圖,每個圖中的節(jié)點的特征維度是3,圖的類別數(shù)是2.

定義Data Loader

from torch.utils.data.sampler import SubsetRandomSamplerfrom dgl.dataloading import GraphDataLoadernum_examples = len(dataset)
num_train = int(num_examples * 0.8)train_sampler = SubsetRandomSampler(torch.arange(num_train))
test_sampler = SubsetRandomSampler(torch.arange(num_train, num_examples))train_dataloader = GraphDataLoader(dataset, sampler=train_sampler, batch_size=5, drop_last=False
)
test_dataloader = GraphDataLoader(dataset, sampler=test_sampler, batch_size=5, drop_last=False
)

取80%用作訓練集,其余用作測試集
mini-batch操作,取5個graph打包成一個大的batched graph

it = iter(train_dataloader)
batch = next(it)
print(batch)
[Graph(num_nodes=259, num_edges=1201,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), tensor([0, 1, 0, 0, 0])]

DGL中的batched graph

在這里插入圖片描述
在每個mini-batch里面,batched graph是由dgl.batch對graph進行打包的

batched_graph, labels = batch
print("Number of nodes for each graph element in the batch:",batched_graph.batch_num_nodes(),
)
print("Number of edges for each graph element in the batch:",batched_graph.batch_num_edges(),
)# Recover the original graph elements from the minibatch
graphs = dgl.unbatch(batched_graph)
print("The original graphs in the minibatch:")
print(graphs)
Number of nodes for each graph element in the batch: tensor([ 55,  16, 116,  31,  41])
Number of edges for each graph element in the batch: tensor([209,  70, 584, 153, 185])
The original graphs in the minibatch:
[Graph(num_nodes=55, num_edges=209,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), Graph(num_nodes=16, num_edges=70,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), Graph(num_nodes=116, num_edges=584,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), Graph(num_nodes=31, num_edges=153,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={}), Graph(num_nodes=41, num_edges=185,ndata_schemes={'label': Scheme(shape=(), dtype=torch.int64), 'attr': Scheme(shape=(3,), dtype=torch.float32)}edata_schemes={})]

定義模型

class GCN(nn.Module):def __init__(self, in_feats, h_feats, num_classes):super(GCN, self).__init__()self.conv1 = GraphConv(in_feats, h_feats)self.conv2 = GraphConv(h_feats, num_classes)def forward(self, g, in_feat):h = self.conv1(g, in_feat)h = F.relu(h)h = self.conv2(g, h)g.ndata["h"] = hreturn dgl.mean_nodes(g, "h")#取所有節(jié)點的'h'特征的平均值來表征整個圖  readoutmodel = GCN(dataset.dim_nfeats, 16, dataset.gclasses)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

一個batched graph中,不同的圖是完全分開的,即沒有邊連接兩個圖,所有消息傳遞函數(shù)仍然具有相同的結果(和沒有打包之前相比)。
其次,將對每個圖分別執(zhí)行readout功能。假設批次大小為B,要聚合的特征維度為D,則讀取出的形狀為(B, D)。

訓練

for epoch in range(20):num_correct = 0num_trains = 0for batched_graph, labels in train_dataloader:pred = model(batched_graph, batched_graph.ndata['attr'].float())loss = F.cross_entropy(pred, labels)num_trains += len(labels)num_correct += (pred.argmax(1)==labels).sum().item()optimizer.zero_grad()loss.backward()optimizer.step()print('train accuracy: ', num_correct/num_trains)num_correct = 0
num_tests = 0
for batched_graph, labels in test_dataloader:pred = model(batched_graph, batched_graph.ndata['attr'].float())num_correct += (pred.argmax(1)==labels).sum().item()num_tests += len(labels)print("Test accuracy: ", num_correct/num_tests)
train accuracy:  0.7404494382022472
train accuracy:  0.7426966292134831
train accuracy:  0.7471910112359551
train accuracy:  0.7539325842696629
train accuracy:  0.7584269662921348
train accuracy:  0.7674157303370787
train accuracy:  0.7629213483146068
train accuracy:  0.7617977528089888
train accuracy:  0.7584269662921348
train accuracy:  0.7707865168539326
train accuracy:  0.7629213483146068
train accuracy:  0.7651685393258427
train accuracy:  0.7629213483146068
train accuracy:  0.7561797752808989
train accuracy:  0.7606741573033707
train accuracy:  0.7584269662921348
train accuracy:  0.7617977528089888
train accuracy:  0.7707865168539326
train accuracy:  0.7629213483146068
train accuracy:  0.7539325842696629Test accuracy:  0.26905829596412556

效果非常一般 明顯過擬合 應該和沒有邊特征,節(jié)點特征信息不足有關。

參考

https://docs.dgl.ai/tutorials/blitz/5_graph_classification.html

http://www.risenshineclean.com/news/42995.html

相關文章:

  • node.js 做網站全媒體運營師報名費多少錢
  • 建站公司網站用什么好色目人
  • 天津網站建設報價登錄百度app
  • 做淘寶的批發(fā)網站有哪些百度sem
  • 日語網站建設需要注意什么seo快速排名網站優(yōu)化
  • 安徽省建設法治協(xié)會網站google play官網入口
  • 自然志wordpress百度網盤seo優(yōu)化
  • 網絡營銷推廣方法結論紹興網站快速排名優(yōu)化
  • 門戶網站做壓力測試搜索引擎的工作原理是什么?
  • python做網站入門寧波網站建設
  • 做網頁一個頁面多少錢重慶seo職位
  • 網站交互功能萬網是什么網站
  • 旅游電商網站建設方案優(yōu)速網站建設優(yōu)化seo
  • wordpress 菜單 圖片汕頭網站建設方案優(yōu)化
  • 建設網站前期準備工作河南品牌網絡推廣外包
  • wordpress 主題設計百度seo自動優(yōu)化
  • 網站建設經驗總結百度今日小說搜索風云榜
  • 湘潭企業(yè)網站建設微信推廣多少錢一次
  • 靜態(tài)網站開發(fā)預期效果經典軟文
  • 怎么幫公司做網站建設如何創(chuàng)建公司網站
  • 找工程承包app排名優(yōu)化seo
  • 建設銀行個人官方網站百度應用app下載
  • 多語言網站怎么實現(xiàn)的推廣公眾號的9種方法
  • 網站的內連接如何做天津百度推廣公司
  • 網站域名備案seo網址大全
  • 在日本怎樣做網站網站建設詳細方案
  • 上海新聞官網東莞百度seo電話
  • 網站上做的圖片不清晰是怎么回事推廣技術
  • 做網站美工工資多少地推團隊如何收費
  • 一般的web網站開發(fā)平臺是色盲測試圖免費測試