mindspore_gl.nn.ChebConv

class mindspore_gl.nn.ChebConv(in_channels: int, out_channels: int, k: int = 3, bias: bool = True)[source]

Chebyshev Spectral Graph Convolution layer. From the paper Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering paper.

\[ \begin{align}\begin{aligned}\mathbf{X}^{\prime} = {\sigma}(\sum_{k=1}^{K} \mathbf{\beta}^{k} \cdot \mathbf{T}^{k} (\mathbf{\hat{L}}) \cdot X)\\\mathbf{\hat{L}} = 2 \mathbf{L} / {\lambda}_{max} - \mathbf{I}\end{aligned}\end{align} \]

\(\mathbf{T}^{k}\) is computed recursively by

\[\mathbf{T}^{k}(\mathbf{\hat{L}}) = 2 \mathbf{\hat{L}}\mathbf{T}^{k-1} - \mathbf{T}^{k-2}\]

where \(\mathbf{k}\) is 1 or 2

\[ \begin{align}\begin{aligned}\mathbf{T}^{0} (\mathbf{\hat{L}}) = \mathbf{I}\\\mathbf{T}^{1} (\mathbf{\hat{L}}) = \mathbf{\hat{L}}\end{aligned}\end{align} \]
Parameters
  • in_channels (int) – Input node feature size.

  • out_channels (int) – Output node feature size.

  • k (int, optional) – Chebyshev filter size. Default: 3.

  • bias (bool, optional) – Whether use bias. Default: True.

Inputs:
  • x (Tensor) - The input node features. The shape is \((N, D_{in})\) where \(N\) is the number of nodes, and \(D_{in}\) should be equal to in_channels in Args.

  • edge_weight (Tensor) - Edge weights. The shape is \((N\_e,)\) where \(N\_e\) is the number of edges.

  • g (Graph) - The input graph.

Outputs:
  • Tensor, output node features with shape of \((N, D_{out})\), where \((D_{out})\) should be the same as out_size in Args.

Raises
  • TypeError – If in_channels or out_channels or k is not an int.

  • TypeError – If bias is not a bool.

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore as ms
>>> from mindspore_gl.nn import ChebConv
>>> from mindspore_gl import GraphField
>>> from mindspore_gl.utils import norm
>>> n_nodes = 2
>>> feat_size = 4
>>> edge_index = [[0, 1], [1, 0]]
>>> edge_index = ms.Tensor(edge_index, ms.int32)
>>> ones = ms.ops.Ones()
>>> feat = ones((n_nodes, feat_size), ms.float32)
>>> edge_index, edge_weight = norm(edge_index, n_nodes)
>>> feat = ones((n_nodes, feat_size), ms.float32)
>>> checonv = ChebConv(in_channels=feat_size, out_channels=4, k=3)
>>> res = checonv(feat, edge_weight, *graph_field.get_graph())
>>> print(res.shape)
(2, 4)