Package with techniques of artificial immune systems.
Project description
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 |
| tqdm | ≥ 4.64.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:
💡 Tip: Binder may take a few minutes to load the environment, especially on the first launch.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aisp-0.5.4.tar.gz.
File metadata
- Download URL: aisp-0.5.4.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00d235a30928af6d9952d2148638cc1802d99032670eb79675600c41e1ef91f0
|
|
| MD5 |
09fbc03f5d7dc73df27557eef6ee0829
|
|
| BLAKE2b-256 |
6405a9e0cb57fc2ba16282522ddd4c1922b4f231d71f461752d60be9db859b99
|
File details
Details for the file aisp-0.5.4-py3-none-any.whl.
File metadata
- Download URL: aisp-0.5.4-py3-none-any.whl
- Upload date:
- Size: 58.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c264dc1e1f25ac4917ac45cfb017b43d951c18efc13a0145450a9855b386de22
|
|
| MD5 |
c10b012ff024fc784805b407134b2153
|
|
| BLAKE2b-256 |
17caf10b9997ac6643f0337d6174a455d0667435cc231cff2558f8bdb5f64260
|