raise DGLError("dgl.heterograph no longer supports graph construction from a SciPy "
data = getM4Ldata(data_file_path)
data_dict = {
('Gene', 'bag-labled', 'Disease') : data['GvsD'],
('Gene', 'bag-instance', 'Isofrom') :data['GvsI'],
('Gene', 'Gene-LncRNA', 'LncRNA') : data['GvsL'],
('Gene', 'Gene-MiRNA', 'MiRNA') : data['GvsM']
}
G = dgl.heterograph(data_dict)
在使用dgl.heterograph()方法创建异质信息网络时,报各种错误。可以进入官网查看参数信息(https://docs.dgl.ai/en/latest/generated/dgl.heterograph.html#dgl.heterograph)。
发现传入参数已经变换了,只能传入一维的tensor, 我的dgl版本是0.5.1,若想使用以前方式,重新下载,改为0.4.1以前即可
那么使用邻接矩阵创建异质图呢?
将numpy数据转为scipy数据,然后就可以直接构建异质图了
import dgl
import dgl.function as fn
import torch as th
import torch.nn as nn
import torch.nn.functional as F
from dgl import DGLGraph
import scipy.io
import scipy.sparse as sp
data_file_path = r'.\data\IsofromDataForDeepM4L.mat'
gcn_msg = fn.copy_src(src='h', out='m')
gcn_reduce = fn.sum(msg='m', out='h')
def getM4Ldata(data_file_path):
data = scipy.io.loadmat(data_file_path)
return data
data = getM4Ldata(data_file_path)
#print(list(data.keys()))
#['__header__', '__version__', '__globals__', 'GvsD', 'GvsI', 'GvsL', 'GvsM']
def build_Up_HINM4L(data_file_path):
data = getM4Ldata(data_file_path)
data_dict = {
('Gene', 'bag-labled', 'Disease') : sp.csr_matrix(data['GvsD']),
('Gene', 'bag-instance', 'Isofrom') : sp.csr_matrix(data['GvsI']),
('Gene', 'Gene-LncRNA', 'LncRNA') : sp.csr_matrix(data['GvsL']),
('Gene', 'Gene-MiRNA', 'MiRNA') : sp.csr_matrix(data['GvsM'])
}
G = dgl.heterograph(data_dict)
'''
data_dict = {
('user', 'follows', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2])),
('user', 'follows', 'topic'): (torch.tensor([1, 1]), torch.tensor([1, 2])),
('user', 'plays', 'game'): (torch.tensor([0, 3]), torch.tensor([3, 4]))
}
da=dgl.heterograph(data_dict)
'''
return G
Graph = build_Up_HINM4L(data_file_path)
print(Graph)
其中data为cell数据,具体看下图(里面包含多个邻接矩阵数据):
输出结果是: