【GNN】图神经网络的简单应用以及MATLAB仿真

1.软件版本

MATLAB2019a

2.本算法理论知识

        在图神经网络中,图的各个节点将被认为是目标对象,每一个目标对象通过各自的特征信息来关联其他目标的特征。然后通过顶点包含的信息以及其邻域的信息,如图1所示

       在图1中,定义局部变换函数和局部输出函数,那么顶点v的状态向量和对应的输出可以表示为:

       其中,分别表示为顶点v的属性,关联边的属性,邻接顶点的状态和属性。那么,对于图中所有的全局状态x和全局输出o可以表示为如下公式:

      

 其中,函数表示为全局变换函数;函数表示为全局输出函数。

 根据文献1可知,

,在GNN中,全局状态变量的迭代更新方式可以表示为:

              

 对于任意个节点v其局部状态变量的迭代

 更新方式可以表示为:

 公式表明状态变量是通过由计算单元构成的编码网络计算得到。

 3.部分源码

% Mutagenesis example
clc;
clear;
close all;
warning off;
rng(1);

addpath 'GNN_1.1.c-master\comparisonNet\'
addpath 'GNN_1.1.c-master\datasets\'
addpath 'GNN_1.1.c-master\experiments\'
addpath 'GNN_1.1.c-master\initialization\'
addpath 'GNN_1.1.c-master\isomorphism\'
addpath 'GNN_1.1.c-master\MLP\'
addpath 'GNN_1.1.c-master\neuralNetworks\'
addpath 'GNN_1.1.c-master\private\'
addpath 'GNN_1.1.c-master\systemModels\'
addpath 'GNN_1.1.c-master\utils\'
addpath 'GNN_1.1.c-master\database\'
addpath 'GNN_1.1.c-master\'
startSession
% Create a 10-fold cross validation data set
makeMutagenicDataset
global multidata
% Train the GNN by only 1 data set
dataSet = multidata(1);

dataSet.trainSet

Configure('GNN.config')
learn

plotTrainingResults;
% Test
% test
close all;

t1=learning.history.forwardItHistory;
t2=learning.history.backwardItHistory;
KK=32;
for i = 1:length(t1);
    if i<=KK
       t1b(i)=mean(t1(1:i)); 
       t2b(i)=mean(t2(1:i)); 
    else
       t1b(i)=mean(t1(i-KK:i));  
       t2b(i)=mean(t2(i-KK:i));  
    end
end
figure;
plot(t1b,'b-o'); 
hold on
plot(t2b,'r-*'); 
hold off
legend('Forward iterations', 'Backward iterations');
xlim([0,250]);    
xlabel('训练次数');


    

    
figure;
plot([1:size(learning.history.trainErrorHistory,2)],learning.history.trainErrorHistory,'b');
hold on
t=[learning.config.stepsForValidation:learning.config.stepsForValidation:...
    learning.config.stepsForValidation*(size(learning.history.validationErrorHistory,2))];
t(end)=learning.current.nSteps-1;  
xlim([0,250]);    
xlabel('训练次数');    
ylabel('训练误差');      
    
    
    

4.仿真

5.参考文献

[1]Scarselli F , Gori M , Tsoi A C , et al. The Graph Neural Network Model[J].IEEE Transactionon Neural Networks, 2009, 20(1):61-80.A05-75

猜你喜欢

转载自blog.csdn.net/ccsss22/article/details/124675169
今日推荐