mindspore_gl.graph.norm
- mindspore_gl.graph.norm(edge_index, num_nodes, edge_weight=None, normalization='sym', lambda_max=None, batch=None)[source]
graph laplacian normalization.
- Parameters
edge_index (Tensor) – Edge index. The shape is
where is the number of edges.num_nodes (int) – Number of nodes.
edge_weight (Tensor) – Edge weights. The shape is
where is the number of edges. Default:None
.normalization (str) –
Normalization method. Default:
'sym'
. is normalized matrix, is degree matrix, is adjaceny matrix, is unit matrix.None
: No normalization'sym'
: Symmetric normalization'rw'
: Random-walk normalization
lambda_max (int, float) – Lambda value of graph. Default:
None
.batch (Tensor) – Batch vector. Default:
None
.
- 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 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. ]