SecML
v0.15

User Guide

  • 1. Machine Learning
    • 1.1. Training of Classifiers and Visualization of Results
      • 1.1.1. Creation and visualization of a simple 2D dataset
      • 1.1.2. Training of classifiers
      • 1.1.3. Visualization of the decision regions of the classifiers
      • 1.1.4. Training other classifiers
    • 1.2. Neural Networks with PyTorch
      • 1.2.1. Classifying blobs
  • 2. Adversarial Machine Learning
    • 2.1. Evasion Attacks against Machine Learning
      • 2.1.1. Crafting Adversarial Examples
      • 2.1.2. Security evaluation of a classifier
    • 2.2. Transferability of Evasion Attacks
      • 2.2.1. Generation of the Adversarial Examples
      • 2.2.2. Analysis of Transferability
    • 2.3. Poisoning Attacks against Machine Learning models
      • 2.3.1. Generation of Poisoning Samples
    • 2.4. Evasion and Poisoning Attacks on MNIST dataset
      • 2.4.1. Training of the classifier
      • 2.4.2. Evasion attack with MNIST dataset
      • 2.4.3. Poisoning attack with MNIST dataset
    • 2.5. Evasion Attacks against Neural Networks on MNIST dataset
      • 2.5.1. Crafting Evasion Attacks
    • 2.6. Evasion Attacks on ImageNet
      • 2.6.1. Load the pretrained model
      • 2.6.2. Load and classify an image
      • 2.6.3. Run the attack
    • 2.7. Deep Neural Rejection
      • 2.7.1. Dataset creation
      • 2.7.2. Training DNR
      • 2.7.3. Attacking DNR
      • 2.7.4. Plotting attack results
    • 2.8. Using cleverhans within SecML
      • 2.8.1. Training the model
      • 2.8.2. Preparing the attacks
      • 2.8.3. Running the attacks
    • 2.9. Testing attacks against RobustBench models
      • 2.9.1. Load RobustBench models inside SecML
      • 2.9.2. Computing evasion attacks
    • 2.10. Using Foolbox attack classes within SecML
      • 2.10.1. Training the model
      • 2.10.2. Crafting the Adversarial Examples
        • 2.10.2.1. Projected Gradient Descent (L2)
        • 2.10.2.2. Carlini-Wagner Attack
      • 2.10.3. Using the generic wrapper
      • 2.10.4. Crafting Adversarial Example on the MNIST Dataset
  • 3. Explaining Machine Learning
    • 3.1. Feature-based explanations
      • 3.1.1. Training of the classifier
      • 3.1.2. Compute the explanations
      • 3.1.3. Visualize results
    • 3.2. Prototype-based explanation
      • 3.2.1. Training of the classifier
      • 3.2.2. Compute the influential training prototypes
      • 3.2.3. Visualize results
  • 4. Applications
    • 4.1. Evasion Attacks on ImageNet (Computer Vision)
      • 4.1.1. Load data
      • 4.1.2. Run the attack
      • 4.1.3. Visualize and check the attack optimization
    • 4.2. Android Malware Detection
      • 4.2.1. Training and testing the detector
      • 4.2.2. Explaining the decisions
      • 4.2.3. Crafting Adversarial Examples
      • 4.2.4. Security Evaluation

Core & Data Structures

  • secml.core
    • CCreator
    • attr_utils
    • constants
    • decorators
    • exceptions
    • type_utils
  • secml.array
    • CArray
    • array_utils
  • secml.data
    • secml.data.loader
      • CDataLoader
      • CDataLoaderCIFAR
      • CDataLoaderICubWorld
      • CDataLoaderImgClients
      • CDataLoaderImgFolders
      • CDataLoaderLFW
      • CDataLoaderMNIST
      • CDataLoaderPyTorch
      • CDataLoaderSkLearn
      • CDataLoaderSvmLight
      • CDataLoaderTorchDataset
      • loader_utils
    • secml.data.selection
      • CPrototypesSelector
      • CPSBorder
      • CPSCenter
      • CPSKMedians
      • CPSRandom
      • CPSSpanning
    • secml.data.splitter
      • CDataSplitter
      • CDataSplitterKFold
      • CDataSplitterLabelKFold
      • CDataSplitterOpenWorldKFold
      • CDataSplitterShuffle
      • CDataSplitterStratifiedKFold
      • CTrainTestSplit
      • CChronologicalSplitter
    • CDataset
    • CDatasetHeader
    • CDatasetPyTorch
    • data_utils

Machine Learning

  • secml.ml
    • secml.ml.classifiers
      • secml.ml.classifiers.multiclass
        • CClassifierMulticlass
        • CClassifierMulticlassOVA
        • CClassifierMulticlassOVO
      • secml.ml.classifiers.secure
        • CClassifierSecSVM
      • secml.ml.classifiers.reject
        • CClassifierReject
        • CClassifierRejectThreshold
        • CClassifierDNR
      • secml.ml.classifiers.loss
        • CLoss
        • CLossCrossEntropy
        • CLossEpsilonInsensitive
        • CLossHinge
        • CLossLogistic
        • CLossSquare
        • CSoftmax
      • secml.ml.classifiers.regularizer
        • CRegularizer
        • CRegularizerElasticNet
        • CRegularizerL1
        • CRegularizerL2
      • CClassifier
      • CClassifierLinear
      • CClassifierSkLearn
      • CClassifierDecisionTree
      • CClassifierKNN
      • CClassifierLogistic
      • CClassifierNearestCentroid
      • CClassifierRandomForest
      • CClassifierRidge
      • CClassifierSGD
      • CClassifierSVM
      • CClassifierDNN
      • CClassifierPyTorch
      • clf_utils
    • secml.ml.features
      • secml.ml.features.normalization
        • CNormalizer
        • CNormalizerLinear
        • CNormalizerMeanStd
        • CNormalizerMinMax
        • CNormalizerUnitNorm
        • CNormalizerDNN
      • secml.ml.features.reduction
        • CReducer
        • CLDA
        • CPCA
      • CPreProcess
    • secml.ml.kernels
      • CKernel
      • CKernelChebyshevDistance
      • CKernelEuclidean
      • CKernelHistIntersect
      • CKernelLaplacian
      • CKernelLinear
      • CKernelPoly
      • CKernelRBF
    • secml.ml.peval
      • secml.ml.peval.metrics
        • CMetric
        • CMetricAccuracy
        • CMetricAUC
        • CMetricAUCWMW
        • CMetricConfusionMatrix
        • CMetricF1
        • CMetricMAE
        • CMetricMSE
        • CMetricPartialAUC
        • CMetricPrecision
        • CMetricRecall
        • CRoc
        • CMetricTestError
        • CMetricTPRatFPR
        • CMetricFNRatFPR
        • CMetricTHatFPR
        • CMetricTPRatTH
        • CMetricFNRatTH
      • CPerfEvaluator
      • CPerfEvaluatorXVal
      • CPerfEvaluatorXValMulticlass
    • secml.ml.stats
      • CDensityEstimation
      • CDistributionGaussian
  • secml.adv
    • secml.adv.attacks
      • secml.adv.attacks.evasion
        • CAttackEvasion
        • CAttackEvasionPGD
        • CAttackEvasionPGDLS
        • CAttackEvasionPGDExp
        • CAttackEvasionCleverhans
        • secml.adv.attacks.evasion.foolbox
          • CAttackEvasionFoolbox
          • CFoolboxBasicIterative
          • CFoolboxL2CarliniWagner
          • CFoolboxL2DDN
          • CFoolboxDeepfool
          • CFoolboxEAD
          • CFoolboxFGM
          • CFoolboxPGD
      • secml.adv.attacks.poisoning
        • CAttackPoisoning
        • CAttackPoisoningLogisticRegression
        • CAttackPoisoningRidge
        • CAttackPoisoningSVM
      • CAttack
    • secml.adv.seceval
      • CSecEval
      • CSecEvalData
  • secml.optim
    • secml.optim.function
      • CFunction
      • CFunctionLinear
      • CFunctionQuadratic
      • CFunctionRosenbrock
      • CFunctionThreeHumpCamel
      • CFunctionBeale
      • CFunctionMcCormick
    • secml.optim.optimizers
      • secml.optim.optimizers.line_search
        • CLineSearch
        • CLineSearchBisect
        • CLineSearchBisectProj
      • COptimizer
      • COptimizerPGD
      • COptimizerPGDLS
      • COptimizerPGDExp
      • COptimizerScipy
    • secml.optim.constraints
      • CConstraint
      • CConstraintBox
      • CConstraintL1
      • CConstraintL2
  • secml.model_zoo
    • load_model

Explanation

  • secml.explanation
    • CExplainer
    • CExplainerGradient
    • CExplainerGradientInput
    • CExplainerIntegratedGradients
    • CExplainerInfluenceFunctions

Visualization

  • secml.figure
    • CFigure
    • CPlot

Utilities

  • secml.parallel
    • parfor
  • secml.utils
    • CLog
    • c_file_manager
    • pickle_utils
    • download_utils
    • dict_utils
    • list_utils
    • mixed_utils
  • secml.settings
  • secml.testing
    • CUnitTest

References

  • UPDATE GUIDES
    • From 0.8.* to 0.9
      • 1. Configuration file
      • 2. Deprecations
  • CHANGELOG
    • v0.14.1 (22/04/2021)
      • Fixed (3 changes)
      • Removed & Deprecated (1 change)
      • Documentation (2 changes)
    • v0.14 (23/03/2021)
      • Requirements (5 changes)
      • Added (3 changes)
      • Improved (3 changes)
      • Fixed (8 changes)
      • Removed & Deprecated (2 changes)
      • Documentation (10 changes)
    • v0.13 (24/07/2020)
      • Requirements (1 change)
      • Added (4 changes)
      • Improved (12 changes)
      • Changed (6 changes)
      • Fixed (10 changes)
      • Removed & Deprecated (2 changes)
      • Documentation (10 changes)
    • v0.12 (11/03/2020)
      • Added (7 changes)
      • Improved (8 changes)
      • Changed (3 changes)
      • Fixed (10 changes)
      • Removed & Deprecated (5 changes)
      • Documentation (5 changes)
    • v0.11.2 (07/01/2020)
      • Requirements (1 change)
      • Fixed (7 changes)
      • Documentation (2 changes)
    • v0.11.1 (18/12/2019)
      • Fixed (3 changes)
    • v0.11 (02/12/2019)
      • Requirements (2 changes)
      • Added (5 changes)
      • Improved (6 changes)
      • Changed (2 changes)
      • Fixed (8 changes)
      • Removed & Deprecated (4 changes)
      • Documentation (4 changes)
    • v0.10 (29/10/2019)
      • Requirements (1 change)
      • Added (4 changes)
      • Improved (6 changes)
      • Changed (4 changes)
      • Fixed (4 changes)
      • Removed & Deprecated (5 changes)
      • Documentation (5 changes)
    • v0.9 (11/10/2019)
      • Improved (1 change)
      • Changed (1 change)
      • Fixed (1 change)
      • Documentation (2 changes)
      • Deprecations (3 changes)
    • v0.8.1 (05/09/2019)
      • Documentation (2 changes)
    • v0.8 (06/08/2019)
  • ROADMAP

Developer's Guide

  • Contributing
    • Submitting a bug report or feature request
      • Bug report
      • Feature request
  • Code Contributions
    • Development Installation
      • Editable Installation
    • Merge request checklist
    • Coding guidelines
      • Code style
      • Documentation style
      • Packages
      • Modules
      • Classes
      • Tests
  • Extending SecML
    • Abstract Base Classes
    • Creating new extensions
      • CClassifier
        • Standard classifiers (CClassifier)
        • DNN backends (CClassifierDNN)
SecML
  • »
  • secml.optim »
  • secml.optim.optimizers »
  • secml.optim.optimizers.line_search
  • Edit on GitHub

secml.optim.optimizers.line_search¶

CLineSearch¶

class secml.optim.optimizers.line_search.c_line_search.CLineSearch(fun, constr=None, bounds=None, eta=0.0001, max_iter=20)[source]¶

Bases: secml.core.c_creator.CCreator

Abstract class that implements line-search optimization algorithms.

Line-search algorithms optimize the objective function along a given direction in the feasible domain, potentially subject to constraints. The search is normally stopped when the objective improves at a satisfying level, to keep the search fast.

Parameters
funCFunction

The function to use for the optimization.

constrCConstraintL1 or CConstraintL2 or None, optional

A distance constraint. Default None.

boundsCConstraintBox or None, optional

A box constraint. Default None.

etascalar, optional

Minimum resolution of the line-search grid. Default 1e-4.

max_iterint, optional

Maximum number of iterations of the line search. Default 20.

Attributes
class_type

Defines class type.

logger

Logger for current object.

verbose

Verbosity level of logger output.

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, **kwargs)

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.

minimize(self, x, d, **kwargs)

Line search.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

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.

abstract minimize(self, x, d, **kwargs)[source]¶

Line search.

Parameters
xCArray

The input point.

dCArray

The descent direction along which fun(x) is minimized.

kwargsdict

Additional parameters required to evaluate fun(x, **kwargs).

CLineSearchBisect¶

class secml.optim.optimizers.line_search.c_line_search_bisect.CLineSearchBisect(fun, constr=None, bounds=None, eta=0.0001, eta_min=0.1, eta_max=None, max_iter=20)[source]¶

Bases: secml.optim.optimizers.line_search.c_line_search.CLineSearch

Binary line search.

Parameters
funCFunction

The function to use for the optimization.

constrCConstraintL1 or CConstraintL2 or None, optional

A distance constraint. Default None.

boundsCConstraintBox or None, optional

A box constraint. Default None.

etascalar, optional

Minimum resolution of the line-search grid. Default 1e-4.

eta_minscalar or None, optional

Initial step of the line search. Gets multiplied or divided by 2 at each step until convergence. If None, will be set equal to eta. Default 0.1.

eta_maxscalar or None, optional

Maximum step of the line search. Default None.

max_iterint, optional

Maximum number of iterations of the line search. Default 20.

Attributes
class_type‘bisect’

Defines class type.

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, **kwargs)

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.

minimize(self, x, d[, fx, tol])

Bisect line search (on discrete grid).

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

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 eta_max¶
property eta_min¶
minimize(self, x, d, fx=None, tol=0.0001, **kwargs)[source]¶

Bisect line search (on discrete grid).

The function fun( x + a*eta*d ) with a = {0, 1, 2, … } is minimized along the descent direction d.

If fun(x) >= 0 -> step_min = step else step_max = step

If eta_max is not None, it runs a bisect line search in [x + eta_min*d, x + eta_max*d]; otherwise, it runs an exponential line search in `[x + eta*d, …, x + eta_min*d, …]

Parameters
xCArray

The input point.

dCArray

The descent direction along which fun(x) is minimized.

fxint or float or None, optional

The current value of fun(x) (if available).

tolfloat, optional

Tolerance for convergence to the local minimum.

kwargsdict

Additional parameters required to evaluate fun(x, **kwargs).

Returns
x’CArray

Point x’ = x + eta * d that approximately solves min f(x + eta*d).

fx’: int or float or None, optional

The value f(x’).

property n_iter¶

CLineSearchBisectProj¶

class secml.optim.optimizers.line_search.c_line_search_bisect_proj.CLineSearchBisectProj(fun, constr=None, bounds=None, eta=0.0001, eta_min=0.1, eta_max=None, max_iter=20)[source]¶

Bases: secml.optim.optimizers.line_search.c_line_search_bisect.CLineSearchBisect

Binary line search including projections.

Parameters
funCFunction

The function to use for the optimization.

constrCConstraintL1 or CConstraintL2 or None, optional

A distance constraint. Default None.

boundsCConstraintBox or None, optional

A box constraint. Default None.

etascalar, optional

Minimum resolution of the line-search grid. Default 1e-4.

eta_minscalar or None, optional

Initial step of the line search. Gets multiplied or divided by 2 at each step until convergence. If None, will be set equal to eta. Default 0.1.

eta_maxscalar or None, optional

Maximum step of the line search. Default None.

max_iterint, optional

Maximum number of iterations of the line search. Default 20.

Attributes
class_type‘bisect-proj’

Defines class type.

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, **kwargs)

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.

minimize(self, x, d[, fx, tol])

Exponential line search (on discrete grid).

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

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.

minimize(self, x, d, fx=None, tol=0.0001, **kwargs)[source]¶

Exponential line search (on discrete grid).

The function fun( x + a*eta*d ) with a = {0, 1, 2, … } is minimized along the descent direction d.

If fun(x) >= 0 -> step_min = step else step_max = step

If eta_max is not None, it runs a bisect line search in [x + eta_min*d, x + eta_max*d]; otherwise, it runs an exponential line search in `[x + eta*d, …, x + eta_min*d, …]

Parameters
xCArray

The input point.

dCArray

The descent direction along which fun(x) is minimized.

fxint or float or None, optional

The current value of fun(x) (if available).

tolfloat, optional

Tolerance for convergence to the local minimum.

kwargsdict

Additional parameters required to evaluate fun(x, **kwargs).

Returns
x’CArray

Point x’ = x + eta * d that approximately solves min f(x + eta*d).

fx’: int or float or None, optional

The value f(x’).

Previous Next

© Copyright 2021, PRALab - Pattern Recognition and Applications Lab & Pluribus One s.r.l.. Revision b4242011.

Built with Sphinx using a theme provided by Read the Docs.