Adaptative Perturbation Pattern Method
A2PM is a gray-box method for the generation of realistic adversarial examples. It benefits from a modular architecture to assign an independent sequence of adaptative perturbation patterns to each class, which analyze specific feature subsets to create valid and coherent data perturbations.
This method was developed to address the diverse constraints of domains with tabular data, such as cybersecurity. It can be advantageous for adversarial attacks against machine learning classifiers, as well as for adversarial training strategies. This Python 3 implementation provides out-of-the-box compatibility with the Scikit-Learn library.
If you use A2PM, please cite the primary research article: https://doi.org/10.3390/fi14040108
Check out the official documentation: https://a2pm.readthedocs.io/en/latest
Explore the public source code repository: https://github.com/vitorinojoao/a2pm
How To Install
The package and its dependencies can be installed using the pip package manager:
pip install a2pm
Alternatively, the repository can be downloaded and the package installed from the local directory:
pip install .
How To Setup
The package can be accessed through the following imports:
from a2pm import A2PMethod
from a2pm.callbacks import BaseCallback, MetricCallback, TimeCallback
from a2pm.patterns import BasePattern, CombinationPattern, IntervalPattern
from a2pm.wrappers import BaseWrapper, KerasWrapper, SklearnWrapper, TorchWrapper
A2PM can be created with a simple base configuration of Interval and/or Combination pattern sequences, which have several possible parameters:
pattern = (
# First pattern to be applied: Interval
{
"type": "interval",
"features": list(range(0, 20)),
"integer_features": list(range(10, 20)),
"ratio": 0.1,
"max_ratio": 0.3,
"missing_value": 0.0,
"probability": 0.6,
},
# Second pattern to be applied: Combination
{
"type": "combination",
"features": list(range(20, 40)),
"locked_features": list(range(30, 40)),
"probability": 0.4,
},
)
method = A2PMethod(pattern)
To support domains with complex constraints, the method is highly configurable:
# General pattern sequence that will be applied to new data classes
pattern = (
# An instantiated pattern
MyCustomPattern(1, 2),
# A pattern configuration
{
"type": MyCustomPattern,
"param_name_1": 3,
"param_name_2": 4,
},
)
# Pre-assigned mapping of data classes to pattern sequences
preassigned_patterns = {
# None to disable the perturbation of this class
"class_label_1": None,
# Specific pattern sequence that will be applied to this class
"class_label_2": (
MyCustomPattern(5, 6),
{
"type": MyCustomPattern,
"param_name_1": 7,
"param_name_2": 8,
},
),
}
method = A2PMethod(pattern, preassigned_patterns)
How To Use
A2PM can be utilized through the ‘fit’, ‘partial_fit’, ‘transform’ and ‘generate’ methods, as well as their respective shortcuts:
# Adapts to new data, and then creates adversarial examples
X_adversarial = method.fit_transform(X, y)
# Encapsulates a Tensorflow/Keras classification model
classifier = KerasWrapper(my_model, my_custom_class_labels)
# Adapts to new data, and then performs an untargeted attack against a classifier
X_adversarial = method.fit_generate(classifier, X, y)
# Adapts to new data, and then performs a targeted attack against a classifier
X_adversarial = method.fit_generate(classifier, X, y, y_target)
To analyze specific aspects of the method, callback functions can be called before the attack starts (iteration 0) and after each attack iteration (iteration 1, 2, …):
X_adversarial = method.fit_generate(
classifier,
X,
y,
y_target,
# Additional configuration
iterations=10,
patience=2,
callback=[
# Time consumption
TimeCallback(verbose=2),
# Evaluation metrics
MetricCallback(classifier, y, my_custom_scorers, verbose=2),
# An instantiated callback
MyCustomCallback(),
# A simple callback function
MyCustomFunction,
],
)
Metadata
Release files for a2pm 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| a2pm-1.2.0.tar.gz | 19.8 kB | Without provenance | Details for a2pm-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| a2pm-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for a2pm-1.2.0-py3-none-any.whl |
Total release size: 45.2 kB
Release files / a2pm-1.2.0.tar.gz
| Download URL | a2pm-1.2.0.tar.gz |
|---|---|
| Size | 19.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69f050c21aa8a5357cdcf9cb9149549a682d931a7ad01a3ad95399762cc95d75
|
|
BLAKE2b-256 checksum How to use checksums |
5786c1ff3f08301cdf9af970d6c44096c6024077e2b9ba75406e5b318f5a24d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Release files / a2pm-1.2.0-py3-none-any.whl
| Download URL | a2pm-1.2.0-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
900ffe954a1e37eab55a7a4547a573c1d2e1eb7e34dd442a7f384570d062daec
|
|
BLAKE2b-256 checksum How to use checksums |
b36875bee5fae78bd4815653b095a50b5c534fd14dd7a9545dea77bb796d840c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Security for a2pm 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.