mindspore_gl.graph.norm

查看源文件
mindspore_gl.graph.norm(edge_index, num_nodes, edge_weight=None, normalization='sym', lambda_max=None, batch=None)[源代码]

图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}\)

  • lambda_max (int, float) - 图的Lambda值。默认值:None

  • batch (Tensor) - 批处理向量。默认值:None

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

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

异常:
  • ValueError - 如果 normalization 不是 None'sym''rw'

支持平台:

Ascend GPU

样例:

>>> import mindspore as ms
>>> from mindspore_gl.graph import norm
>>> edge_index = [[1, 1, 2, 2], [0, 2, 0, 1]]
>>> edge_index = ms.Tensor(edge_index, ms.int32)
>>> num_nodes = 3
>>> edge_index, edge_weight = norm(edge_index, num_nodes)
>>> print(edge_index)
[[1 1 2 2 0 1 2]
[0 2 0 1 0 1 2]]
>>> print(edge_weight)
[-0.        -0.4999999 -0.        -0.4999999  1.         1.
1.       ]