mindspore_gl.graph.get_laplacian

mindspore_gl.graph.get_laplacian(edge_index, num_nodes, edge_weight=None, normalization='sym')[源代码]

获得laplacian矩阵。

参数:
  • edge_index (Tensor) - 边索引。shape为 \((2, N\_e)\) 其中 \(N\_e\) 是边的数量。

  • num_nodes (int) - 节点数。

  • edge_weight (Tensor, 可选) - 边权重。shape为 \((N\_e)\) 其中 \(N\_e\) 是边的数量。默认值:None。

  • normalization (str, 可选) - 归一化方法。默认值: ‘sym’。

    \((L)\) 为归一化的矩阵, \((D)\) 为度矩阵, \((A)\) 为邻接矩阵, \((I)\) 为单元矩阵。

    1. None :无 \(\mathbf{L} = \mathbf{D} - \mathbf{A}\)

    2. ‘sym’ :对称归一化 \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2}\)

    3. ‘rw’ :随机游走归一化 \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1} \mathbf{A}\)

返回:
  • edge_index (Tensor) - 标准化的边索引。

  • edge_weight (Tensor) - 归一化边权重。

异常:
  • ValueError - 如果 normalization 不是None、’sym’或’rw’。

支持平台:

Ascend GPU

样例:

>>> import mindspore as ms
>>> from mindspore_gl.graph import get_laplacian
>>> edge_index = [[1, 1, 2, 2], [0, 2, 0, 1]]
>>> edge_index = ms.Tensor(edge_index, ms.int32)
>>> num_nodes = 3
>>> edge_weight = ms.Tensor([1, 2, 1, 2], ms.float32)
>>> edge_index, edge_weight = get_laplacian(edge_index, num_nodes, edge_weight, 'sym')
>>> print(edge_index)
[[1 1 2 2 0 1 2]
[0 2 0 1 0 1 2]]
>>> print(edge_weight)
[-0.        -0.6666666 -0.        -0.6666666  1.         1.
1.       ]