secml.adv.attacks

CAttack

class secml.adv.attacks.c_attack.CAttack(classifier)[source]

Bases: secml.core.c_creator.CCreator

Generic interface class for adversarial attacks.

Parameters
classifierCClassifier

Target classifier.

Attributes
class_type

Defines class type.

classifier

Returns classifier

f_eval

Returns the number of function evaluations made during the attack.

f_opt

Returns the value of the objective function evaluated on the optimal point founded by the attack.

f_seq

Returns a CArray containing the values of the objective function evaluations made by the attack.

grad_eval

Returns the number of gradient evaluations made during the attack.

logger

Logger for current object.

verbose

Verbosity level of logger output.

x_opt

Returns the optimal point founded by the attack.

x_seq

Returns a CArray (number of iteration * number of features) containing the values of the attack point path.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(path)

Loads object from file.

load_state(self, path)

Sets the object state from file.

run(self, x, y[, ds_init])

Run attack on the dataset x,y (with multiple attack points).

save(self, path)

Save class object to file.

save_state(self, path)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

property classifier

Returns classifier

abstract property f_eval

Returns the number of function evaluations made during the attack.

property f_opt

Returns the value of the objective function evaluated on the optimal point founded by the attack.

Warning

Due to a known issue, if more then one sample is passed to .run(), this property will only return the data relative to the last optimized one. This behavior will change in a future version.

property f_seq

Returns a CArray containing the values of the objective function evaluations made by the attack.

Warning

Due to a known issue, if more then one sample is passed to .run(), this property will only return the data relative to the last optimized one. This behavior will change in a future version.

abstract property grad_eval

Returns the number of gradient evaluations made during the attack.

abstract run(self, x, y, ds_init=None)[source]

Run attack on the dataset x,y (with multiple attack points).

Parameters
xCArray

Initial samples.

yint or CArray

The true label of x.

ds_initCDataset or None, optional.

Dataset for warm start.

Returns
y_predpredicted labels for all samples by the targeted classifier
scoresscores for all samples by targeted classifier
adv_dsmanipulated attack samples (for subsequents warm starts)
f_optfinal value of the objective function
property x_opt

Returns the optimal point founded by the attack.

Warning

Due to a known issue, if more then one sample is passed to .run(), this property will only return the data relative to the last optimized one. This behavior will change in a future version.

property x_seq

Returns a CArray (number of iteration * number of features) containing the values of the attack point path.

Warning

Due to a known issue, if more then one sample is passed to .run(), this property will only return the data relative to the last optimized one. This behavior will change in a future version.