Fractional Graph Neural Networks API Reference

GNN layers and models with fractional calculus integration.

GNN Layers

Fractional Graph Neural Network Layers

This module provides Graph Neural Network layers with fractional calculus integration, supporting multiple backends (PyTorch, JAX, NUMBA) and various graph operations.

class hpfracc.ml.gnn_layers.BaseFractionalGNNLayer(in_channels, out_channels, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None)[source]

Bases: ABC

Base class for fractional GNN layers

This abstract class defines the interface for all fractional GNN layers, ensuring consistency across different backends and implementations.

Parameters:
__init__(in_channels, out_channels, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None)[source]
Parameters:
abstract _initialize_layer()[source]

Initialize the specific layer implementation

abstract forward(x, edge_index, edge_weight=None, **kwargs)[source]

Forward pass through the layer

Parameters:
  • x (Any)

  • edge_index (Any)

  • edge_weight (Any | None)

Return type:

Any

apply_fractional_derivative(x)[source]

Apply fractional derivative to input features

Parameters:

x (Any)

Return type:

Any

_torch_fractional_derivative(x, alpha)[source]

PyTorch implementation of fractional derivative

Parameters:
Return type:

Any

_jax_fractional_derivative(x, alpha)[source]

JAX implementation of fractional derivative

Parameters:
Return type:

Any

_numba_fractional_derivative(x, alpha)[source]

NUMBA implementation of fractional derivative

Parameters:
Return type:

Any

class hpfracc.ml.gnn_layers.FractionalGraphConv(in_channels, out_channels, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None)[source]

Bases: BaseFractionalGNNLayer

Fractional Graph Convolutional Layer

This layer applies fractional derivatives to node features before performing graph convolution operations.

Parameters:
_initialize_layer()[source]

Initialize the graph convolution layer

_initialize_weights()[source]

Initialize layer weights using Xavier initialization

forward(x, edge_index, edge_weight=None, **kwargs)[source]

Forward pass through the fractional graph convolution layer

Parameters:
  • x (Any) – Node feature matrix [num_nodes, in_channels]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • edge_weight (Any | None) – Optional edge weights [num_edges]

Returns:

Updated node features [num_nodes, out_channels]

Return type:

Any

_torch_forward(x, edge_index, edge_weight=None, **kwargs)[source]

PyTorch implementation of forward pass

Parameters:
  • x (Any)

  • edge_index (Any)

  • edge_weight (Any | None)

Return type:

Any

_jax_forward(x, edge_index, edge_weight=None, **kwargs)[source]

JAX implementation of forward pass

Parameters:
  • x (Any)

  • edge_index (Any)

  • edge_weight (Any | None)

Return type:

Any

_numba_forward(x, edge_index, edge_weight=None, **kwargs)[source]

NUMBA implementation of forward pass

Parameters:
  • x (Any)

  • edge_index (Any)

  • edge_weight (Any | None)

Return type:

Any

_jax_scatter_add(out, row, col, edge_weight=None)[source]

JAX implementation of scatter add operation

Parameters:
Return type:

Any

_numba_scatter_add(out, row, col, edge_weight=None)[source]

NUMBA implementation of scatter add operation

Parameters:
Return type:

Any

_jax_activation(x)[source]

JAX implementation of activation function

Parameters:

x (Any)

Return type:

Any

_numba_activation(x)[source]

NUMBA implementation of activation function

Parameters:

x (Any)

Return type:

Any

train(mode=True)[source]

Set the layer in training mode.

Parameters:

mode (bool)

eval()[source]

Set the layer in evaluation mode.

reset_parameters()[source]

Reset layer parameters to initial values.

parameters()[source]

Return an iterator over module parameters.

named_parameters()[source]

Return an iterator over module parameters, yielding both the name and the parameter.

state_dict()[source]

Return a dictionary containing a whole state of the module.

load_state_dict(state_dict)[source]

Load state dictionary.

class hpfracc.ml.gnn_layers.FractionalGraphAttention(in_channels, out_channels, heads=8, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None, **kwargs)[source]

Bases: BaseFractionalGNNLayer

Fractional Graph Attention Layer

This layer applies fractional derivatives to node features and uses attention mechanisms for graph convolution.

Parameters:
__init__(in_channels, out_channels, heads=8, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None, **kwargs)[source]
Parameters:
_initialize_layer()[source]

Initialize the graph attention layer

forward(x, edge_index, edge_weight=None, **kwargs)[source]

Forward pass through the fractional graph attention layer

Parameters:
  • x (Any) – Node feature matrix [num_nodes, in_channels]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • edge_weight (Any | None) – Optional edge weights [num_edges]

Returns:

Updated node features [num_nodes, out_channels]

Return type:

Any

_aggregate_attention(query, attended_values, row, col)[source]

Aggregate attention-weighted values

Parameters:
Return type:

Any

_apply_activation(x)[source]

Apply activation function

Parameters:

x (Any)

Return type:

Any

_jax_activation(x)[source]

JAX implementation of activation function

Parameters:

x (Any)

Return type:

Any

_numba_activation(x)[source]

NUMBA implementation of activation function

Parameters:

x (Any)

Return type:

Any

_apply_dropout(x, **kwargs)[source]

Apply dropout

Parameters:

x (Any)

Return type:

Any

train(mode=True)[source]

Set the layer in training mode.

Parameters:

mode (bool)

eval()[source]

Set the layer in evaluation mode.

reset_parameters()[source]

Reset layer parameters to initial values.

parameters()[source]

Return an iterator over module parameters.

named_parameters()[source]

Return an iterator over module parameters, yielding both the name and the parameter.

state_dict()[source]

Return a dictionary containing a whole state of the module.

load_state_dict(state_dict)[source]

Load state dictionary.

class hpfracc.ml.gnn_layers.FractionalGraphPooling(in_channels, out_channels=None, pooling_ratio=0.5, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None, **kwargs)[source]

Bases: BaseFractionalGNNLayer

Fractional Graph Pooling Layer

This layer applies fractional derivatives to node features and performs hierarchical pooling operations on graphs.

Parameters:
__init__(in_channels, out_channels=None, pooling_ratio=0.5, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, bias=True, backend=None, **kwargs)[source]
Parameters:
_initialize_layer()[source]

Initialize the pooling layer

forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the fractional graph pooling layer

Parameters:
  • x (Any) – Node feature matrix [num_nodes, in_channels]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • batch (Any | None) – Batch assignment vector [num_nodes]

Returns:

Tuple of (pooled_features, pooled_edge_index, pooled_batch)

Return type:

Tuple[Any, Any, Any]

train(mode=True)[source]

Set the layer in training mode.

Parameters:

mode (bool)

eval()[source]

Set the layer in evaluation mode.

reset_parameters()[source]

Reset layer parameters to initial values.

parameters()[source]

Return an iterator over module parameters.

named_parameters()[source]

Return an iterator over module parameters, yielding both the name and the parameter.

state_dict()[source]

Return a dictionary containing a whole state of the module.

load_state_dict(state_dict)[source]

Load state dictionary.

GNN Models

Complete Fractional Graph Neural Network Architectures

This module provides complete GNN architectures with fractional calculus integration, including various model types and configurations for different graph learning tasks.

class hpfracc.ml.gnn_models.BaseFractionalGNN(input_dim, hidden_dim, output_dim, num_layers=3, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]

Bases: ABC

Base class for fractional Graph Neural Networks

This abstract class defines the interface for all fractional GNN models, ensuring consistency across different architectures and backends.

Parameters:
__init__(input_dim, hidden_dim, output_dim, num_layers=3, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]
Parameters:
abstract _build_network()[source]

Build the specific network architecture

abstract forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the network

Parameters:
  • x (Any)

  • edge_index (Any)

  • batch (Any | None)

Return type:

Any

get_backend_info()[source]

Get information about the current backend

Return type:

Dict[str, Any]

parameters()[source]

Collect learnable parameters from sub-layers for testing/optimizers

Return type:

List[Any]

class hpfracc.ml.gnn_models.FractionalGCN(input_dim, hidden_dim, output_dim, num_layers=3, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]

Bases: BaseFractionalGNN

Fractional Graph Convolutional Network

A GNN architecture that uses fractional graph convolution layers for node classification, graph classification, and other tasks.

Parameters:
_build_network()[source]

Build the GCN architecture

forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the fractional GCN

Parameters:
  • x (Any) – Node feature matrix [num_nodes, input_dim]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • batch (Any | None) – Batch assignment vector [num_nodes]

Returns:

Node embeddings [num_nodes, output_dim]

Return type:

Any

class hpfracc.ml.gnn_models.FractionalGAT(input_dim, hidden_dim, output_dim, num_layers=3, num_heads=8, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]

Bases: BaseFractionalGNN

Fractional Graph Attention Network

A GNN architecture that uses fractional graph attention layers for enhanced graph representation learning.

Parameters:
__init__(input_dim, hidden_dim, output_dim, num_layers=3, num_heads=8, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]
Parameters:
_build_network()[source]

Build the GAT architecture

forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the fractional GAT

Parameters:
  • x (Any) – Node feature matrix [num_nodes, input_dim]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • batch (Any | None) – Batch assignment vector [num_nodes]

Returns:

Node embeddings [num_nodes, output_dim]

Return type:

Any

class hpfracc.ml.gnn_models.FractionalGraphSAGE(input_dim, hidden_dim, output_dim, num_layers=3, num_samples=25, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]

Bases: BaseFractionalGNN

Fractional GraphSAGE Network

A GNN architecture that uses fractional graph convolution layers with neighbor sampling for scalable graph learning.

Parameters:
__init__(input_dim, hidden_dim, output_dim, num_layers=3, num_samples=25, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]
Parameters:
_build_network()[source]

Build the GraphSAGE architecture

forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the fractional GraphSAGE

Parameters:
  • x (Any) – Node feature matrix [num_nodes, input_dim]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • batch (Any | None) – Batch assignment vector [num_nodes]

Returns:

Node embeddings [num_nodes, output_dim]

Return type:

Any

class hpfracc.ml.gnn_models.FractionalGraphUNet(input_dim, hidden_dim, output_dim, num_layers=4, pooling_ratio=0.5, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]

Bases: BaseFractionalGNN

Fractional Graph U-Net

A hierarchical GNN architecture that uses fractional calculus for multi-scale graph representation learning.

Parameters:
__init__(input_dim, hidden_dim, output_dim, num_layers=4, pooling_ratio=0.5, fractional_order=0.5, method='RL', use_fractional=True, activation='relu', dropout=0.1, backend=None)[source]
Parameters:
_build_network()[source]

Build the Graph U-Net architecture

forward(x, edge_index, batch=None, **kwargs)[source]

Forward pass through the fractional Graph U-Net

Parameters:
  • x (Any) – Node feature matrix [num_nodes, input_dim]

  • edge_index (Any) – Graph connectivity [2, num_edges]

  • batch (Any | None) – Batch assignment vector [num_nodes]

Returns:

Node embeddings [num_nodes, output_dim]

Return type:

Any

class hpfracc.ml.gnn_models.FractionalGNNFactory[source]

Bases: object

Factory class for creating fractional GNN models

This class provides a convenient interface for creating different types of fractional GNN architectures with consistent configurations.

static create_model(model_type, input_dim, hidden_dim, output_dim, **kwargs)[source]

Create a fractional GNN model of the specified type

Parameters:
  • model_type (str) – Type of GNN model (‘gcn’, ‘gat’, ‘sage’, ‘unet’)

  • input_dim (int) – Input feature dimension

  • hidden_dim (int) – Hidden layer dimension

  • output_dim (int) – Output dimension

  • **kwargs – Additional arguments for the model

Returns:

Configured fractional GNN model

Return type:

BaseFractionalGNN

static get_available_models()[source]

Get list of available model types

Return type:

List[str]

static get_model_info(model_type)[source]

Get information about a specific model type

Parameters:

model_type (str)

Return type:

Dict[str, Any]