Graphadv

Latest version: v0.1.1

Safety actively analyzes 619516 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.1.1

Quick Start
+ Targeted Attack
python
from graphadv.attack.targeted import Nettack
attacker = Nettack(adj, x, labels, idx_train, seed=None)
reset for next attack
attacker.reset()
By default, the number of perturbations is set to the degree of nodes, you can change it by `n_perturbations=`
attacker.attack(target, direct_attack=True, structure_attack=True, feature_attack=False)

get the edge flips
>>> attacker.edge_flips
get the attribute flips
>>> attacker.attr_flips
get the perturbed adjacency matrix
>>> attacker.A
get the perturbed attribute matrix
>>> attacker.X


+ Untargeted Attack
python
from graphadv.attack.untargeted import Metattack
attacker = Metattack(adj, x, labels,
idx_train, idx_unlabeled=idx_unlabeled,
lr=0.01, cora and cora_ml lr=0.1 citeseer lr=0.01
lambda_=1.0,
device="GPU", seed=None)
reset for next attack
attacker.reset()
By default, the number of perturbations is set to the degree of nodes, you can change it by `n_perturbations=`
`n_perturbations` can be integer (number of edges) or float scalar (>=0, <=1, the ratio of edges)
attacker.attack(0.05, structure_attack=True, feature_attack=False)

get the edge flips
>>> attacker.edge_flips
get the attribute flips
>>> attacker.attr_flips
get the perturbed adjacency matrix
>>> attacker.A
get the perturbed attribute matrix
>>> attacker.X


+ Defense
+ `JaccardDetection` for binary node attributes
+ `CosinDetection` for continuous node attributes

python
from graphadv.defense import JaccardDetection, CosinDetection
defender = JaccardDetection(adj, x)
defender.reset()
defender.fit()

get the modified adjacency matrix
>>> defender.A
get the modified attribute matrix
>>> defender.X

More examples please refer to the [examples](https://github.com/EdisonLeeeee/GraphAdv/blob/master/examples) directory.

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.