from torch_geometric.datasets import Planetoid from torch_geometric.utils import to_scipy_sparse_matrix dataset = Planetoid(root='', name='Cora') # 将数据保存在data文件夹下 data = dataset[0] adj = to_scipy_sparse_matrix(data.edge_index) #将数据变成邻接矩阵的形式 features = data.x labels ...
# get adj adj = to_scipy_sparse_matrix(edge_index).todense() adj = torch.tensor(adj).to(device) 提取度矩阵: deg = degree(edge_index[0], dataset.num_nodes) deg = torch.diag_embed(deg) deg_inv_sqrt = torch.pow(deg, -0.5) deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0 ...
Fixed bug in to_scipy_sparse_matrix() when CUDA is set as default torch device (#9146) Fixed the MetaPath2Vec model in case the last node is isolated (#9145) Ensured backward compatibility in MessagePassing via torch.load() (#9105) Prevented model compilation on custom MessagePassing.propag...
to_dense_adj, to_scipy_sparse_matrix, )class UnpoolInfo(NamedTuple): edge_index: Tensor cluster: Tensor batch: Tensorclass ClusterPooling(torch.nn.Module): r"""The cluster pooling operator from the `"Edge-Based Graph Component Pooling" <paper url>`_ paper.:...
matmul(x) # Sparse-dense matrix multiplication adj = adj.matmul(adj) # Sparse-sparse matrix multiplication # Creating SparseTensor instances: adj = SparseTensor.from_dense(mat) adj = SparseTensor.eye(100, 100) adj = SparseTensor.from_scipy(mat) MessagePassing接口可以使用Tensor类或新的Sparse...
adj = nx.to_scipy_sparse_array(G).tocoo() File "F:\anaconda\envs\ai\lib\site-packages\networkx\convert_matrix.py", line 921, in to_scipy_sparse_array A = sp.sparse.coo_array((d, (r, c)), shape=(nlen, nlen), dtype=dtype) AttributeError: module 'scipy.sparse' has no attribu...
def matrix_U(N): u = lambda n, N: np.cos(2 * np.pi / N * n * np.arange(N)) - 1j * np.sin(2 * np.pi / N * n * np.arange(N)) U = np.empty((N, 0)) for n in range(N): U = np.c_[U, u(n, N)] return U def fourier_transform(v): N = v.shape[0]...
You can create a scipy matrix for each individual attention head: adjs = [] for i in range(attention_score.size(1)): adj = torch_geometric.utils.to_scipy_sparse_matrix(indices, attention_score[:, i]) adjs.append(adj) 👍 4 pinkfloyd06 commented Jun 25, 2021 Thanks, it helps ...
data.pos: Node position matrix with shape[num_nodes, num_dimensions] 一个简单的例子:(无向图以双向存储) importtorchfromtorch_geometric.dataimportDataedge_index=torch.tensor([[0,1,1,2],[1,0,2,1]],dtype=torch.long)x=torch.tensor([[-1],[0],[1]],dtype=torch.float)data=Data(x=x,ed...
import geopy.distance # to compute distances between stations import glob import numpy as np import os import pandas as pd import scipy.sparse as sp fromsklearn.preprocessing import StandardScaler import torch import torch.nn as nn import torch.nn.functional as F ...