BernProp(K, is_source_domain=True, bias=True, **kwargs)

Bases: MessagePassing

K-order Bernstein polynomial approximation.

Parameters:
  • K (int) –

    Order of the polynomial filter. Determines the complexity of the spectral filter.

  • is_source_domain (bool, default: True ) –

    Whether this layer is used for source domain. If True, temperature parameters are learnable. If False, they are fixed to a linear interpolation from 1 to 0. Default: True.

  • bias (bool, default: True ) –

    Whether to add bias. Currently not used but kept for compatibility. Default: True.

  • **kwargs (optional, default: {} ) –

    Additional keyword arguments passed to the MessagePassing parent class.

Notes

This class implements a graph neural network layer that performs spectral domain adaptation. It uses a polynomial filter approach with learnable temperature parameters to adapt the spectral characteristics of the graph.

The layer computes a polynomial filter of order K and applies it to the graph signal through message passing operations. The filter coefficients are determined by learnable temperature parameters that differ between source and target domains.

Attributes:
  • K (int) –

    Order of the polynomial filter.

  • is_source_domain (bool) –

    Whether this layer is for source domain.

  • cached_terms ((Tensor, optional)) –

    Cached polynomial terms for filter computation.

  • cached_coefs ((Tensor, optional)) –

    Cached polynomial coefficients.

  • temp (Parameter) –

    Learnable temperature parameters for the filter.

__repr__()

String representation of the layer.

Returns:
  • str

    String representation showing the class name, filter order K, and temperature parameters.

forward(x, edge_index, edge_weight=None)

Forward pass of the DGSD layer.

Parameters:
  • x (Tensor) –

    Node feature matrix of shape [num_nodes, num_features].

  • edge_index (LongTensor) –

    Graph connectivity in COO format with shape [2, num_edges].

  • edge_weight (Tensor, default: None ) –

    Edge weights of shape [num_edges]. If None, all edges are assumed to have weight 1. Default: None.

Returns:
  • Tensor

    Updated node features after spectral domain adaptation.

Notes

This method implements the spectral domain adaptation by:

  • Computing the symmetric normalized Laplacian

  • Adding self-loops with appropriate weights

  • Propagating messages through the graph using polynomial filters

  • Combining the results using binomial coefficients and temperature parameters

get_filter()

Compute the spectral filter using cached terms and coefficients.

Returns:
  • Tensor

    The computed spectral filter H.

Notes

This method requires cached_terms and cached_coefs to be set before calling. The filter is computed as a weighted sum of polynomial terms.

message(x_j, norm)

Message function for message passing.

Parameters:
  • x_j (Tensor) –

    Source node features of shape [num_edges, num_features].

  • norm (Tensor) –

    Normalized edge weights of shape [num_edges].

Returns:
  • Tensor

    Messages of shape [num_edges, num_features].

reset_parameters()

Reset the learnable parameters of the layer.

Notes
  • For source domain layers, temperature parameters are initialized to 1.

  • For target domain layers, temperature parameters are set to a linear interpolation from 1 to 0 over K+1 values.

DGSDABase(features, hidden, classes, dprate=0.0, K=15)

Bases: Module

Base class for DGSDA.

Parameters:
  • features (int) –

    Input feature dimension.

  • hidden (int) –

    Hidden layer dimension.

  • classes (int) –

    Number of output classes.

  • dprate (float, default: 0.0 ) –

    Dropout rate for propagation layers. Default: 0.0.

  • K (int, default: 15 ) –

    Order of the polynomial filter for propagation layers. Default: 15.

Notes

This class implements a domain generalization model using spectral domain adaptation. It uses separate propagation layers for source and target domains to adapt the spectral characteristics of the graph data.

The model consists of:

  • Linear transformation layers

  • Bernoulli propagation layers with polynomial filters

  • Domain-specific propagation paths

forward(data, is_source_domain=True)

Forward pass of the DGSDA model.

Parameters:
  • data (Data) –

    Input graph data containing node features and edge indices.

  • is_source_domain (bool, default: True ) –

    Whether the input is from source domain. Determines which propagation layer to use. Default: True.

Returns:
  • Tensor

    Model predictions for node classification.

Notes

The forward pass consists of:

  • Domain-specific feature propagation

  • Dropout regularization

  • Final linear classification

  • Final propagation step

get_props(x, edge_index, is_source_domain=True)

Apply domain-specific feature propagation.

Parameters:
  • x (Tensor) –

    Node features of shape [num_nodes, num_features].

  • edge_index (LongTensor) –

    Graph connectivity in COO format with shape [2, num_edges].

  • is_source_domain (bool, default: True ) –

    Whether to use source domain propagation layer. If True, uses prop1; if False, uses prop2. Default: True.

Returns:
  • Tensor

    Propagated node features.

Notes

This method implements the domain-specific feature processing:

  • Initial dropout and ReLU activation

  • Domain-specific propagation using Bernoulli polynomial filters

  • Separate propagation paths for source and target domains

reset_parameters()

Reset the learnable parameters of the model.

Notes

Currently only resets the first propagation layer (prop1).