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:
_MEABaseAttack-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:
_MEABaseAttack-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:
_MEABaseAttack-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:
_MEABaseAttack-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:
_MEABaseAttack-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:
_MEABaseAttack-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:
BaseAttackBase 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]
- _train_surrogate(g, x, train_idx, y_train, epochs=200, lr=0.01)[source]¶
- Return type:
Tuple[Module,float]
-
features:
Tensor¶
-
graph:
DGLGraph¶
-
labels:
Tensor¶
- supported_api_types = {'dgl'}¶
-
test_mask:
Tensor¶
-
train_mask:
Tensor¶
- 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.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]]