Backbones#

Convolutional Cell Convolutional Network (CCCN) model.

class topobenchmarkx.nn.backbones.cell.cccn.CCCN(in_channels, n_layers=2, dropout=0.0, last_act=False)[source]#

CCCN model.

Parameters:
in_channelsint

Number of input channels.

n_layersint, optional

Number of layers (default: 2).

dropoutfloat, optional

Dropout rate (default: 0).

last_actbool, optional

If True, the last activation function is applied (default: False).

forward(x, Ld, Lu)[source]#

Forward pass.

Parameters:
xtorch.Tensor

Input tensor.

Ldtorch.Tensor

Domain adjacency matrix.

Lutorch.Tensor

Label adjacency matrix.

Returns:
torch.Tensor

Output tensor.

class topobenchmarkx.nn.backbones.cell.cccn.CW(F_in, F_out)[source]#

Layer of the CCCN model.

Parameters:
F_inint

Number of input channels.

F_outint

Number of output channels.

forward(xe, Lu, Ld)[source]#

Forward pass.

Parameters:
xetorch.Tensor

Input tensor.

Lutorch.Tensor

Domain adjacency matrix.

Ldtorch.Tensor

Label adjacency matrix.

Returns:
torch.Tensor

Output tensor.

Class implementing the EDGNN model.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.EDGNN(num_features, input_dropout=0.2, dropout=0.2, activation='relu', MLP_num_layers=2, MLP2_num_layers=-1, MLP3_num_layers=-1, All_num_layers=2, edconv_type='EquivSet', restart_alpha=0.5, aggregate='add', normalization='None', AllSet_input_norm=False)[source]#

EDGNN model.

Parameters:
num_featuresint

Number of input features.

input_dropoutfloat, optional

Dropout rate for input features. Defaults to 0.2.

dropoutfloat, optional

Dropout rate for hidden layers. Defaults to 0.2.

activationstr, optional

Activation function. Defaults to ‘relu’.

MLP_num_layersint, optional

Number of layers in MLP. Defaults to 2.

MLP2_num_layersint, optional

Number of layers in the second MLP. Defaults to -1.

MLP3_num_layersint, optional

Number of layers in the third MLP. Defaults to -1.

All_num_layersint, optional

Number of layers in the EDConv. Defaults to 2.

edconv_typestr, optional

Type of EDConv. Defaults to ‘EquivSet’.

restart_alphafloat, optional

Restart alpha. Defaults to 0.5.

aggregatestr, optional

Aggregation method. Defaults to ‘add’.

normalizationstr, optional

Normalization method. Defaults to ‘None’.

AllSet_input_normbool, optional

Whether to normalize input features. Defaults to False.

forward(x, edge_index)[source]#

Forward pass.

Parameters:
xTensor

Input features.

edge_indexLongTensor

Edge index.

Returns:
Tensor

Output features.

None

None object needed for compatibility.

reset_parameters()[source]#

Reset parameters.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.EquivSetConv(in_features, out_features, mlp1_layers=1, mlp2_layers=1, mlp3_layers=1, aggr='add', alpha=0.5, dropout=0.0, normalization='None', input_norm=False)[source]#

Class implementing the Equivariant Set Convolution.

Parameters:
in_featuresint

Number of input features.

out_featuresint

Number of output features.

mlp1_layersint, optional

Number of layers in the first MLP. Defaults to 1.

mlp2_layersint, optional

Number of layers in the second MLP. Defaults to 1.

mlp3_layersint, optional

Number of layers in the third MLP. Defaults to 1.

aggrstr, optional

Aggregation method. Defaults to ‘add’.

alphafloat, optional

Alpha value. Defaults to 0.5.

dropoutfloat, optional

Dropout rate. Defaults to 0.0.

normalizationstr, optional

Normalization method. Defaults to ‘None’.

input_normbool, optional

Whether to normalize input features. Defaults to False.

forward(X, vertex, edges, X0)[source]#

Forward pass.

Parameters:
XTensor

Input features.

vertexLongTensor

Vertex index.

edgesLongTensor

Edge index.

X0Tensor

Initial features.

Returns:
Tensor

Output features.

reset_parameters()[source]#

Reset parameters.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.JumpLinkConv(in_features, out_features, mlp_layers=2, aggr='add', alpha=0.5)[source]#

Class implementing the JumpLink Convolution.

Parameters:
in_featuresint

Number of input features.

out_featuresint

Number of output features.

mlp_layersint, optional

Number of layers in the MLP. Defaults to 2.

aggrstr, optional

Aggregation method. Defaults to ‘add’.

alphafloat, optional

Alpha value. Defaults to 0.5.

forward(X, vertex, edges, X0, beta=1.0)[source]#

Forward pass.

Parameters:
XTensor

Input features.

vertexLongTensor

Vertex index.

edgesLongTensor

Edge index.

X0Tensor

Initial features.

betafloat, optional

Beta value. Defaults to 1.0.

Returns:
Tensor

Output features.

reset_parameters()[source]#

Reset parameters.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.MLP(in_channels, hidden_channels, out_channels, num_layers, dropout=0.5, Normalization='bn', InputNorm=False)[source]#

Class implementing a multi-layer perceptron.

Adapted from CUAI/CorrectAndSmooth

Parameters:
in_channelsint

Number of input features.

hidden_channelsint

Number of hidden features.

out_channelsint

Number of output features.

num_layersint

Number of layers.

dropoutfloat, optional

Dropout rate. Defaults to 0.5.

Normalizationstr, optiona

Normalization method. Defaults to ‘bn’.

InputNormbool, optional

Whether to normalize input features. Defaults to False.

flops(x)[source]#

Calculate FLOPs.

Parameters:
xTensor

Input features.

Returns:
int

FLOPs.

forward(x)[source]#

Forward pass.

Parameters:
xTensor

Input features.

Returns:
Tensor

Output features.

reset_parameters()[source]#

Reset parameters.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.MeanDegConv(in_features, out_features, init_features=None, mlp1_layers=1, mlp2_layers=1, mlp3_layers=2)[source]#

Class implementing the Mean Degree Convolution.

Parameters:
in_featuresint

Number of input features.

out_featuresint

Number of output features.

init_featuresint, optional

Number of initial features. Defaults to None.

mlp1_layersint, optional

Number of layers in the first MLP. Defaults to 1.

mlp2_layersint, optional

Number of layers in the second MLP. Defaults to 1.

mlp3_layersint, optional

Number of layers in the third MLP. Defaults to 2.

forward(X, vertex, edges, X0)[source]#

Forward pass.

Parameters:
XTensor

Input features.

vertexLongTensor

Vertex index.

edgesLongTensor

Edge index.

X0Tensor

Initial features.

Returns:
Tensor

Output features.

reset_parameters()[source]#

Reset parameters.

class topobenchmarkx.nn.backbones.hypergraph.edgnn.PlainMLP(in_channels, hidden_channels, out_channels, num_layers, dropout=0.5)[source]#

Class implementing a multi-layer perceptron without normalization.

Adapted from CUAI/CorrectAndSmooth.

Parameters:
in_channelsint

Number of input features.

hidden_channelsint

Number of hidden features.

out_channelsint

Number of output features.

num_layersint

Number of layers.

dropoutfloat, optional

Dropout rate. Defaults to 0.5.

forward(x)[source]#

Forward pass.

Parameters:
xTensor

Input features.

Returns:
Tensor

Output features.

reset_parameters()[source]#

Reset parameters.

Implementation of the Simplicial Complex Convolutional Neural Network (SCCNN) for complex classification.

class topobenchmarkx.nn.backbones.simplicial.sccnn.SCCNNCustom(in_channels_all, hidden_channels_all, conv_order, sc_order, aggr_norm=False, update_func=None, n_layers=2)[source]#

SCCNN implementation for complex classification.

Note: In this task, we can consider the output on any order of simplices for the classification task, which of course can be amended by a readout layer.

Parameters:
in_channels_alltuple of int

Dimension of input features on (nodes, edges, faces).

hidden_channels_alltuple of int

Dimension of features of hidden layers on (nodes, edges, faces).

conv_orderint

Order of convolutions, we consider the same order for all convolutions.

sc_orderint

Order of simplicial complex.

aggr_normbool, optional

Whether to normalize the aggregation (default: False).

update_funcstr, optional

Update function for the simplicial complex convolution (default: None).

n_layersint, optional

Number of layers (default: 2).

forward(x_all, laplacian_all, incidence_all)[source]#

Forward computation.

Parameters:
x_alltuple(tensors)

Tuple of feature tensors (node, edge, face).

laplacian_alltuple(tensors)

Tuple of Laplacian tensors (graph laplacian L0, down edge laplacian L1_d, upper edge laplacian L1_u, face laplacian L2).

incidence_alltuple(tensors)

Tuple of order 1 and 2 incidence matrices.

Returns:
tuple(tensors)

Tuple of final hidden state tensors (node, edge, face).

class topobenchmarkx.nn.backbones.simplicial.sccnn.SCCNNLayer(in_channels, out_channels, conv_order, sc_order, aggr_norm: bool = False, update_func=None, initialization: str = 'xavier_normal')[source]#

Layer of a Simplicial Complex Convolutional Neural Network.

Parameters:
in_channelstuple of int

Dimensions of input features on nodes, edges, and faces.

out_channelstuple of int

Dimensions of output features on nodes, edges, and faces.

conv_orderint

Convolution order of the simplicial filters.

sc_orderint

SC order.

aggr_normbool, optional

Whether to normalize the aggregated message by the neighborhood size (default: False).

update_funcstr, optional

Activation function used in aggregation layers (default: None).

initializationstr, optional

Initialization method for the weights (default: “xavier_normal”).

aggr_norm_func(conv_operator, x)[source]#

Perform aggregation normalization.

Parameters:
conv_operatortorch.sparse

Convolution operator.

xtorch.Tensor

Feature tensor.

Returns:
torch.Tensor

Normalized feature tensor.

chebyshev_conv(conv_operator, conv_order, x)[source]#

Perform Chebyshev convolution.

Parameters:
conv_operatortorch.sparse

Convolution operator.

conv_orderint

Order of the convolution.

xtorch.Tensor

Feature tensor.

Returns:
torch.Tensor

Output tensor.

forward(x_all, laplacian_all, incidence_all)[source]#

Forward computation.

Parameters:
x_alltuple of tensors

Tuple of input feature tensors (node, edge, face).

laplacian_alltuple of tensors

Tuple of Laplacian tensors (graph laplacian L0, down edge laplacian L1_d, upper edge laplacian L1_u, face laplacian L2).

incidence_alltuple of tensors

Tuple of order 1 and 2 incidence matrices.

Returns:
torch.Tensor

Output tensor for each 0-cell.

torch.Tensor

Output tensor for each 1-cell.

torch.Tensor

Output tensor for each 2-cell.

reset_parameters(gain: float = 1.414)[source]#

Reset learnable parameters.

Parameters:
gainfloat

Gain for the weight initialization.

update(x)[source]#

Update embeddings on each cell (step 4).

Parameters:
xtorch.Tensor

Input tensor.

Returns:
torch.Tensor

Updated tensor.