pygip.models.attack.base

Classes

BaseAttack(dataset[, attack_node_fraction, ...])

Abstract base class for attack models.

class pygip.models.attack.base.BaseAttack(dataset, attack_node_fraction=None, model_path=None, device=None)[source]

Bases: ABC

Abstract base class for attack models.

This class provides a common interface for various attack strategies on graph-based machine learning models. It handles device management, dataset loading, and compatibility checks to ensure that the attack can be executed on the given dataset and model API type.

supported_api_types

A set of strings representing the supported API types (e.g., ‘pyg’, ‘dgl’).

Type:

set

supported_datasets

A set of strings representing the names of supported dataset classes.

Type:

set

device

The computing device (CPU or GPU) to be used for the attack.

Type:

torch.device

dataset

The dataset object containing graph data and metadata.

Type:

Dataset

graph_dataset

The raw graph dataset from the underlying library.

graph_data

The primary graph data structure.

num_nodes

The number of nodes in the graph.

Type:

int

num_features

The number of features per node.

Type:

int

num_classes

The number of classes for node classification.

Type:

int

attack_node_fraction

The fraction of nodes to be targeted by the attack.

Type:

float, optional

model_path

The path to a pre-trained target model.

Type:

str, optional

_abc_impl = <_abc_data object>
_check_dataset_compatibility()[source]

Checks if the dataset is compatible with the attack.

Raises:

ValueError – If the dataset’s API type or class name is not in the list of supported types.

_load_model(model_path)[source]

Load a pre-trained model.

_train_attack_model()[source]

Train the attack model.

_train_target_model()[source]

Train the target model if not provided.

abstract attack()[source]

Execute the attack.

supported_api_types = {}
supported_datasets = {}