国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

儋州網(wǎng)站建設(shè)網(wǎng)站查詢域名解析

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

目錄

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

概述

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

數(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個(gè)圖,每個(gè)圖中的節(jié)點(diǎn)的特征維度是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%用作訓(xùn)練集,其余用作測(cè)試集
mini-batch操作,取5個(gè)graph打包成一個(gè)大的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

在這里插入圖片描述
在每個(gè)mini-batch里面,batched graph是由dgl.batch對(duì)graph進(jìn)行打包的

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é)點(diǎn)的'h'特征的平均值來表征整個(gè)圖  readoutmodel = GCN(dataset.dim_nfeats, 16, dataset.gclasses)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

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

訓(xùn)練

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

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

參考

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

http://aloenet.com.cn/news/42995.html

相關(guān)文章:

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