tapas.attacks.closest_distance.LocalNeighbourhoodAttack
- class tapas.attacks.closest_distance.LocalNeighbourhoodAttack(distance: tapas.attacks.distances.DistanceMetric = <tapas.attacks.distances.HammingDistance object>, radius: float = 1, criterion='accuracy', label: typing.Optional[str] = None)
Bases:
tapas.attacks.base_classes.TrainableThresholdAttackAttack that makes a decision based on records similar to the target record, specifically all records within a sphere of a given radius, for a specific choice of distance.
For membership inference attacks, the score is the fraction of all records that are within distance radius of the target record.
For attribute inference attacks, the score is the fraction of all records within the sphere which have a given value for the sensitive attribute.
- __init__(distance: tapas.attacks.distances.DistanceMetric = <tapas.attacks.distances.HammingDistance object>, radius: float = 1, criterion='accuracy', label: typing.Optional[str] = None)
Create the attack with chosen parameters.
- Parameters
distance (DistanceMetric) – Distance to use between records for the attack.
radius (float) –
criterion (tuple) – Criterion to select the threshold (see TrainableThresholdAttack for details).
(optional) (label) –
Methods
__init__([distance, radius, criterion, label])Create the attack with chosen parameters.
attack(datasets)Make a prediction for each dataset.
attack_score(datasets)Compute the decision score for this attack.
train(threat_model[, num_samples])Train this attack: train the score, then choose a threshold meeting the target criterion.
Attributes
A label to describe this attack in reports.
- attack(datasets: list[Dataset])
Make a prediction for each dataset.
This computes attack_score for each dataset, then decides that the target user is in the training dataset if and only if the score is higher than self._threshold.
- Parameters
datasets (a list of synthetic datasets.) –
- Returns
predictions
- Return type
np.array of booleans.
- attack_score(datasets: list[Dataset])
Compute the decision score for this attack.
- Parameters
datasets (a list of synthetic datasets.) –
- Returns
scores – For attribute inference attacks, if the number k of possible values is > 2, this is of size len(datasets) x k, where entry (i,j) is for dataset i and value j. Otherwise, this is an array of len(dataset) scores, with a score per dataset.
- Return type
a np.array of scores.
- property label
A label to describe this attack in reports.
- train(threat_model: tapas.threat_models.attacker_knowledge.LabelInferenceThreatModel, num_samples: Optional[int] = None, **attack_score_kwargs)
Train this attack: train the score, then choose a threshold meeting the target criterion.
- Parameters
threat_model (LabelInferenceThreatModel) – The threat model from which to generate labelled samples.
num_samples (int (default, None).) – Number of training samples to generate to select the threshold. If None, use all pre-generated training samples (only do this if you have already generated datasets).
(optionally) –
arguments (additional keyword) –
_train_attack_score. (passed to) –