Skip to main content

Package with techniques of artificial immune systems.

Project description

Artificial Immune Systems Package

Artificial Immune Systems Package

A Python package for Artificial Immune Systems algorithms


Language

Documentation


Introduction

AISP is a python package that implements artificial immune systems techniques, distributed under the GNU Lesser General Public License v3.0 (LGPLv3).

The package started in 2022 as a research package at the Federal Institute of Northern Minas Gerais - Salinas campus (IFNMG - Salinas).

Artificial Immune Systems (AIS) are inspired by the vertebrate immune system, creating metaphors that apply the ability to detect and catalog pathogens, among other features of this system.

What can you do with AISP?

AISP provides implementations of bio-inspired algorithms for:

  • Anomaly detection: Identify abnormal patterns in data.
  • Classification: Classify data with multiple classes.
  • Optimization: Find optimal solutions for objective functions.
  • Clustering: Group data without supervision.

Implemented Algorithms

Negative Selection (aisp.nsa)

  • BNSA - Binary Negative Selection Algorithm
  • RNSA - Real-Valued Negative Selection Algorithm

Clonal Selection (aisp.csa)

  • AIRS - Artificial Immune Recognition System
  • CLONALG - Clonal Selection Algorithm

Immune Network Theory (aisp.ina)

  • AiNet - Artificial Immune Network for clustering and data compression

Module in Development

Danger Theory (aisp.dta)

  • DCA - Dendritic Cell Algorithm (planned)

API overview

All algorithms follow a simple and consistent interface:

  • fit(X, y, verbose: bool = True): trains the model for classification tasks.
  • fit(X, verbose: bool = True): trains the model for clustering tasks.
  • predict(X): makes predictions based on new data.
  • optimize(max_iters: int =..., n_iter_no_change: int =..., verbose: bool = True): run the optimization algorithms

Installation

The module requires installation of python 3.10 or higher.

Dependencies

Packages Version
numpy ≥ 1.22.4
scipy ≥ 1.8.1
numba ≥ 0.59.0

User installation

The simplest way to install AISP is using pip:

pip install aisp

Quick Start

Below are minimal examples demonstrating how to use AISP for different tasks.

Classification with RNSA

import numpy as np
from aisp.nsa import RNSA

# Generating training data
np.random.seed(1)
class_a = np.random.uniform(high=0.5, size=(50, 2))
class_b = np.random.uniform(low=0.51, size=(50, 2))
x_train = np.vstack((class_a, class_b))
y_train = ['a'] * 50 + ['b'] * 50

# Training the model
model = RNSA(N=150, r=0.3, seed=1)
model.fit(x_train, y_train, verbose=False)

# Predict
x_test = [
    [0.15, 0.45],  # Expected: 'a'
    [0.85, 0.65],  # Expected: 'b'
]

y_pred = model.predict(x_test)
print(y_pred)

Clustering with AiNet

import numpy as np
from aisp.ina import AiNet

np.random.seed(1)
# Generating training data
a = np.random.uniform(high=0.4, size=(50, 2))
b = np.random.uniform(low=0.6, size=(50, 2))
x_train = np.vstack((a, b))

# Training the model
model = AiNet(
    N=150,
    mst_inconsistency_factor=1,
    seed=1,
    affinity_threshold=0.85,
    suppression_threshold=0.7
)

model.fit(x_train, verbose=False)

# Predict cluster labels
x_test = [
    [0.15, 0.45],
    [0.85, 0.65],
]

y_pred = model.predict(x_test)
print(y_pred)

Optimization with CLONALG

import numpy as np
from aisp.csa import Clonalg

# Define search space
bounds = {'low': -5.12, 'high': 5.12}

# Objective function (Rastrigin)
def rastrigin(x):
    x = np.clip(x, bounds['low'], bounds['high'])
    return 10 * len(x) + np.sum(x**2 - 10 * np.cos(2 * np.pi * x))

# Initialize optimizer
model = Clonalg(problem_size=2, rate_hypermutation=0.5, bounds=bounds, seed=1)
model.register('affinity_function', rastrigin)

# Run optimization
population = model.optimize(100, 50, False)

print(model.best_solution, model.best_cost) # Best solution

Examples

Explore the example notebooks available in the AIS-Package/aisp repository. These notebooks demonstrate how to utilize the package's functionalities in various scenarios, including applications of the RNSA, BNSA and AIRS algorithms on datasets such as Iris, Geyser, and Mushrooms.

You can run the notebooks directly in your browser without any local installation using Binder:

Launch on Binder

💡 Tip: Binder may take a few minutes to load the environment, especially on the first launch.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aisp-0.5.5.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aisp-0.5.5-py3-none-any.whl (58.7 kB view details)

Uploaded Python 3

File details

Details for the file aisp-0.5.5.tar.gz.

File metadata

  • Download URL: aisp-0.5.5.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for aisp-0.5.5.tar.gz
Algorithm Hash digest
SHA256 b510810f88157a7b8b22783def6fb7a4483500a1b5fc5edad9c680194e7719c0
MD5 d0d385164194f2fa97eee7a1be28aa61
BLAKE2b-256 bcdbb0d906758b07c6fe83c2fd0c5044e2a6e1f093508137a76eef63d37d938a

See more details on using hashes here.

File details

Details for the file aisp-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: aisp-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 58.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for aisp-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a68891cf4e702eef7fba6d5476e8ca32bf7a8aeeef40b11fab8a05037d3d26ae
MD5 5ef419d3022fbdf74d5ead7fa6462268
BLAKE2b-256 a8173e2178c36312a0bad77cdef31a0dbab6a062443e33a9b23d1f982da363a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page