secml.ml.features

CPreProcess

class secml.ml.features.c_preprocess.CPreProcess(preprocess=None)[source]

Bases: secml.ml.c_module.CModule

Common interface for feature preprocessing algorithms.

Parameters
preprocessCPreProcess or str or None, optional

Features preprocess to be applied to input data. Can be a CPreProcess subclass or a string with the type of the desired preprocessor. If None, input data is used as is.

Attributes
class_type

Defines class type.

logger

Logger for current object.

preprocess

Inner preprocessor (if any).

verbose

Verbosity level of logger output.

Methods

backward(self[, w])

Returns the preprocessor gradient wrt data.

copy(self)

Returns a shallow copy of current class.

create([class_item])

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

create_chain(class_items, kwargs_list)

Creates a chain of preprocessors.

deepcopy(self)

Returns a deep copy of current class.

fit(self, x[, y])

Fit transformation algorithm.

fit_transform(self, x[, y, caching])

Fit preprocessor using data and then transform data.

forward(self, x[, caching])

Forward pass on input x.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class parameters.

get_state(self)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

gradient(self, x[, w])

Compute gradient at x by doing a forward and a backward pass.

inverse_transform(self, x)

Revert data to original form.

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.

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.

transform(self, x)

Apply the transformation algorithm on data.

static create_chain(class_items, kwargs_list)[source]

Creates a chain of preprocessors.

Parameters
class_itemslist of str or class instances

A list of mixed class types or CPreProcess instances. The object created with the first type/instance of the list will be the preprocess of the object created using the second type/instance in the list and so on until the end of the list.

kwargs_listlist of dict

A list of dictionaries, one for each item in class_items, to specify any additional argument for each specific preprocessor.

Returns
CPreProcess

The chain of preprocessors.

fit(self, x, y=None)[source]

Fit transformation algorithm.

Parameters
xCArray

Array to be used for training. Shape of input array depends on the algorithm itself.

yCArray or None, optional

Flat array with the label of each pattern. Can be None if not required by the preprocessing algorithm.

Returns
CPreProcess

Instance of the trained preprocessor.

fit_transform(self, x, y=None, caching=False)[source]

Fit preprocessor using data and then transform data.

This method is equivalent to call fit(data) and transform(data) in sequence, but it’s useful when data is both the training array and the array to be transformed.

Parameters
xCArray

Array to be transformed. Each row must correspond to one single patterns, so each column is a different feature.

yCArray or None, optional

Flat array with the label of each pattern. Can be None if not required by the preprocessing algorithm.

caching: bool

True if preprocessed x should be cached for backward pass

Returns
CArray

Transformed input data.

See also

fit

fit the preprocessor.

transform

transform input data.

inverse_transform(self, x)[source]

Revert data to original form.

Parameters
xCArray

Transformed array to be reverted to original form. Shape of input array depends on the algorithm itself.

Returns
CArray

Original input data.

Warning

Reverting a transformed array is not always possible. See description of each preprocessor for details.

transform(self, x)[source]

Apply the transformation algorithm on data.

Parameters
xCArray

Array to be transformed. Shape of input array depends on the algorithm itself.

Returns
CArray

Transformed input data.