mindspore_gl.graph.get_laplacian

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

Get laplacian matrix.

Parameters
  • edge_index (Tensor) – Edge index. The shape is \((2, N\_e)\) where \(N\_e\) is the number of edges.

  • num_nodes (int) – Number of nodes.

  • edge_weight (Tensor, optional) – Edge weights. The shape is \((N\_e)\) where \(N\_e\) is the number of edges. Default: None.

  • normalization (str, optional) –

    Normalization method. Default: ‘sym’. \((L)\) is normalized matrix, \((D)\) is degree matrix, \((A)\) is adjaceny matrix, \((I)\) is unit matrix.

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

    2. ’sym’: Symmetric normalization \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2}\)

    3. ’rw’: Random-walk normalization \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1} \mathbf{A}\)

Returns

  • edge_index (Tensor) - normalized edge_index.

  • edge_weight (Tensor) - normalized edge_weight.

Raises

ValueError – if normalization not is None or ‘sym’ or ‘rw’.

Supported Platforms:

Ascend GPU

Examples

>>> 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.       ]