a2pm

Adaptative Perturbation Pattern Method

https://github.com/vitorinojoao/a2pm

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Adaptative Perturbation Pattern Method

Basic Info
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 4 years ago · Last pushed almost 3 years ago
Metadata Files
Readme License Citation

README.rst

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 `_

.. figure:: https://raw.githubusercontent.com/vitorinojoao/a2pm/main/images/a2pm.png
   :alt: A2PMFigure

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:

.. code:: python

   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:

.. code:: python

   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:

.. code:: python

   # 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:

.. code:: python

   # 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, ...):

.. code:: python

   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,
       ],
   )

Owner

  • Name: João Vitorino
  • Login: vitorinojoao
  • Kind: user
  • Location: Porto, Portugal

Researcher @cybergecad

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this method, please cite the primary research article."
type: software
license: MIT
title: "Adaptative Perturbation Pattern Method"
authors:
  - family-names: "Vitorino"
    given-names: "João"
    orcid: "https://orcid.org/0000-0002-4968-3653"
doi: 10.3390/fi14040108
url: "https://github.com/vitorinojoao/a2pm"
preferred-citation:
  type: article
  title: "Adaptative Perturbation Patterns: Realistic Adversarial Learning for Robust Intrusion Detection"
  authors:
    - family-names: "Vitorino"
      given-names: "João"
      orcid: "https://orcid.org/0000-0002-4968-3653"
    - family-names: "Oliveira"
      given-names: "Nuno"
      orcid: "https://orcid.org/0000-0002-5030-7751"
    - family-names: "Praça"
      given-names: "Isabel"
      orcid: "https://orcid.org/0000-0002-2519-9859"
  doi: "10.3390/fi14040108"
  journal: "Future Internet"
  year: 2022
  month: 3
  volume: 14
  issue: 4
  start: 108

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Committers

Last synced: about 3 years ago

All Time
  • Total Commits: 10
  • Total Committers: 1
  • Avg Commits per committer: 10.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
vitorinojoao j****o@o****m 10

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 78 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 4
  • Total maintainers: 1
pypi.org: a2pm

Adaptative Perturbation Pattern Method

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 78 Last month
Rankings
Dependent packages count: 9.6%
Dependent repos count: 21.9%
Downloads: 23.2%
Average: 23.3%
Forks count: 29.9%
Stargazers count: 32.0%
Maintainers (1)
Last synced: 7 months ago

Dependencies

docs/source/requirements.txt pypi
  • numpy ==1.19.5
  • scikit-learn ==0.24.2
  • sphinx ==4.5.0
  • sphinx_rtd_theme ==1.0.0
setup.py pypi
  • numpy >=1.17.5,<2
requirements.txt pypi