secml_malware.attack.blackbox.ga package
Submodules
secml_malware.attack.blackbox.ga.c_base_genetic_engine module
- class secml_malware.attack.blackbox.ga.c_base_genetic_engine.CGeneticAlgorithm(problem: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem, is_debug: bool = False)
Bases:
secml.adv.attacks.evasion.c_attack_evasion.CAttackEvasion
The genetic optimizer.
- f_eval()
Returns the number of function evaluations made during the attack.
- grad_eval()
Returns the number of gradient evaluations made during the attack.
- objective_function(x)
Objective function.
- Parameters
x (CArray or CDataset) –
- Returns
f_obj
- Return type
float or CArray of floats
- objective_function_gradient(x)
Gradient of the objective function.
- run(x, y, ds_init=None) Tuple[secml.array.c_array.CArray, secml.array.c_array.CArray, secml.data.c_dataset.CDataset, Any]
Runs the genetic algorithms.
- Parameters
x (CArray) – input sample to perturb
y (CArray) – original class
ds_init (CDataset, optional, default None) – the initialization point. Default is None
- Returns
CArray – y_pred : the predicted label after the attack
CArray – scores : the scores after the attack
CDataset – adv_ds : the CDataset containing the adversarial points
CArray – f_obj : the mean value for the objective function
- classmethod write_adv_to_file(x_adv: secml.array.c_array.CArray, path: str)
Write the adversarial malware as a file on disk
- Parameters
x_adv (CArray) – The adversarial malware to dump
path (str) – The path where to save the executable
- secml_malware.attack.blackbox.ga.c_base_genetic_engine.random_mutation(individual, indpb)
Apply the mutation operator, that perturb randomly each entry of the individual, with a given probability. The mutation is applied in-place.
- Parameters
individual – the individual to mutate
indpb (float) – the probability of altering a single entry
- Returns
the mutated individual, the mutatio is in-place
- Return type
tuple