pygip.models.attack.mea package

Submodules

pygip.models.attack.mea.MEA module

class pygip.models.attack.mea.MEA.ModelExtractionAttack0(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-0: Random-node label-only extraction on the original graph.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA.ModelExtractionAttack1(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-1: Degree-based sampling of query nodes on the original graph.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA.ModelExtractionAttack2(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-2: Data-free extraction on a synthetic graph with random features.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA.ModelExtractionAttack3(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-3: Shadow-graph extraction. Train on a subgraph induced by a set of target nodes and their neighbors (potential nodes).

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA.ModelExtractionAttack4(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-4: Cosine-similarity neighbor expansion. Start from random seeds and expand candidates by feature similarity to form the training subgraph.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA.ModelExtractionAttack5(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: _MEABase

Attack-5: Variant of the shadow-graph attack that samples two candidate lists and trains on their union. If attack_6 index files are present (historical name), they will be used; otherwise we fall back to generated indices.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

features: Tensor
graph: DGLGraph
labels: Tensor
test_mask: Tensor
train_mask: Tensor
class pygip.models.attack.mea.MEA._MEABase(dataset, attack_x_ratio, attack_a_ratio, model_path=None)[source]

Bases: BaseAttack

Base class for MEA family attacks. This class handles the target model training, metric bookkeeping, and utility helpers. Subclasses only need to decide which training indices and which graph to use for the surrogate.

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

Subclasses must implement this method to 1) build a graph g_att and features x_att for training, 2) pick a list of training indices idx_train of length attack_node_num, 3) query the target for labels on idx_train and train a surrogate, and then return filled metrics objects.

Return type:

Tuple[AttackMetric, AttackCompMetric]

_compute_metrics(surrogate, metric, metric_comp)[source]
_load_model(model_path)[source]

Load a pre-trained model.

_query_target(g, x)[source]
Return type:

Tuple[Tensor, float]

_train_surrogate(g, x, train_idx, y_train, epochs=200, lr=0.01)[source]
Return type:

Tuple[Module, float]

_train_target_model()[source]

Train the target model if not provided.

attack(*args, **kwargs)[source]

Execute the attack.

features: Tensor
graph: DGLGraph
labels: Tensor
supported_api_types = {'dgl'}
test_mask: Tensor
train_mask: Tensor
pygip.models.attack.mea.MEA._as_tensor(x, device)[source]
pygip.models.attack.mea.MEA._safe_dir()[source]
Return type:

str

pygip.models.attack.mea.MEA.add_self_loops(g)[source]

Return a copy of g with self-loops added to every node.

Return type:

DGLGraph

pygip.models.attack.mea.MEA.erdos_renyi_graph(num_nodes, p=0.05)[source]
Return type:

DGLGraph

pygip.models.attack.mea.MEA.load_attack2_generated_graph(dataset_name, default_nodes)[source]

Try to load an attack-2 pre-generated graph. If files are missing, fall back to an on-the-fly Erdos–Rényi graph with random features. Returns (graph, features, selected_indices).

Return type:

Tuple[DGLGraph, Tensor, Optional[List[int]]]

pygip.models.attack.mea.MEA.load_attack3_shadow_indices(dataset_name, g, k)[source]

Try to load shadow graph indices from disk; if not found, generate heuristically.

Return type:

Tuple[List[int], List[int]]

pygip.models.attack.mea.MEA.random_shadow_indices(g, k, extra=2)[source]

Heuristic shadow graph index generator. Returns two sets: target_nodes (size k) and potential_nodes (neighbors around target nodes).

Return type:

Tuple[List[int], List[int]]

pygip.models.attack.mea.MEA.subgraph_from_nodes(g, node_idx)[source]

Induce a subgraph that contains only edges whose endpoints are both in node_idx.

Return type:

DGLGraph

Module contents