pygip.utils.metrics

Classes

AttackMetric()

ComputationMetric()

DefenseMetric()

GraphNeuralNetworkMetric([fidelity, ...])

Graph Neural Network Metric Class.

MetricBase()

class pygip.utils.metrics.AttackMetric[source]

Bases: MetricBase

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

Compute and return all metric results.

update(preds, labels, target_outputs=None, surrogate_outputs=None)[source]

Update internal metric state.

class pygip.utils.metrics.ComputationMetric[source]

Bases: object

update()[source]
class pygip.utils.metrics.DefenseMetric[source]

Bases: MetricBase

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

Compute and return all metric results.

update(preds, labels, target_outputs=None, surrogate_outputs=None)[source]

Update internal metric state.

update_defense_task(defense_preds, defense_labels)[source]
update_defense_wm(wm_preds, wm_labels)[source]
update_surrogate_task(surrogate_preds, surrogate_labels)[source]
update_surrogate_wm(wm_preds, wm_labels)[source]
update_target(target_preds, target_labels)[source]
class pygip.utils.metrics.GraphNeuralNetworkMetric(fidelity=0, accuracy=0, model=None, graph=None, features=None, mask=None, labels=None, query_labels=None)[source]

Bases: object

Graph Neural Network Metric Class.

This class evaluates two metrics, fidelity and accuracy, for a given GNN model on a specified graph and features.

static calculate_surrogate_fidelity(target_model, surrogate_model, data, mask=None)[source]

Calculate fidelity between target and surrogate model predictions.

Parameters:
  • target_model – Original model

  • surrogate_model – Extracted surrogate model

  • data – Input graph data

  • mask – Optional mask for evaluation on specific nodes

Returns:

Fidelity score (percentage of matching predictions)

Return type:

float

evaluate()[source]

Main function to update fidelity and accuracy scores.

evaluate_helper(model, graph, features, labels, mask)[source]

Helper function to evaluate the model’s performance.

static evaluate_surrogate_extraction(target_model, surrogate_model, data, train_mask=None, val_mask=None, test_mask=None)[source]

Comprehensive evaluation of surrogate extraction attack.

Parameters:
  • target_model – Original model

  • surrogate_model – Extracted surrogate model

  • data – Input graph data

  • train_mask – Mask for training nodes

  • val_mask – Mask for validation nodes

  • test_mask – Mask for test nodes

Returns:

Dictionary containing fidelity scores for different data splits

Return type:

dict

class pygip.utils.metrics.MetricBase[source]

Bases: ABC

_abc_impl = <_abc_data object>
abstract compute()[source]

Compute and return all metric results.

static compute_auc(preds, labels)[source]
static compute_default_metrics(preds, labels)[source]
static compute_fidelity(output1, output2)[source]
print()[source]
abstract reset()[source]

Reset internal state.

abstract update(preds, labels, **kwargs)[source]

Update internal metric state.