Skip to main content
Version: 0.5.x

AIRS

Artificial Immune Recognition System (AIRS)

Inheritance

This class extends BaseClassifier

Module: aisp.csa
Import: from aisp.csa import AIRS


Overview

The Artificial Immune Recognition System (AIRS) is a classification algorithm inspired by the clonal selection process of the biological immune system. This implementation is based on the simplified AIRS2 version described in 1. The algorithm has been adapted to support both real-valued (continuous) and binary feature datasets.

note

This implementation is inspired by AIRS2, a simplified version of the original AIRS algorithm. Introducing adaptations to handle continuous and binary datasets.

Based on Algorithm 16.5 from Brabazon et al. 1

Related and noteworthy works: access here 2.


Example

import numpy as np
from aisp.csa import AIRS

np.random.seed(1)
# Generating training data
a = np.random.uniform(high=0.5, size=(50, 2))
b = np.random.uniform(low=0.51, size=(50, 2))
x_train = np.vstack((a, b))
y_train = [0] * 50 + [1] * 50
# AIRS Instance
airs = AIRS(n_resources=5, rate_clonal=5, rate_hypermutation=0.65, seed=1)
airs = airs.fit(x_train, y_train, verbose=False)
x_test = [
[0.15, 0.45], # Expected: Class 0
[0.85, 0.65], # Esperado: Classe 1
]
y_pred = airs.predict(x_test)
print(y_pred)

Output:

[0 1]

Constructor Parameters

NameTypeDefaultDescription
n_resourcesfloat10Total amount of available resources.
rate_clonalint10Maximum number of possible clones of a class. This quantity is multiplied by (cell_stimulus * rate_hypermutation) to define the number of clones.
rate_mc_initfloat0.2Percentage of samples used to initialize memory cells.
rate_hypermutationfloat0.75The rate of mutated clones derived from rate_clonal as a scalar factor.
affinity_threshold_scalarfloat0.75Normalized affinity threshold.
kint3The number of K nearest neighbors that will be used to choose a label in the prediction.
max_itersint100Maximum number of iterations in the refinement process of the ARB set exposed to aᵢ.
resource_amplifiedfloat1.0Resource consumption amplifier is multiplied with the incentive to subtract resources.
metricstr"euclidean"Distance metric used to compute affinity between cells and samples.
seedintNoneSeed for random generation.
pfloat2This parameter stores the value of p used in the Minkowski distance.

Attributes

NameTypeDefaultDescription
cells_memoryOptional[Dict[str | int, list[BCell]]]-Dictionary of trained memory cells, organized by class.

Public Methods

fit

def fit(
self,
X: Union[npt.NDArray, list],
y: Union[npt.NDArray, list],
verbose: bool = True,
) -> AIRS:
...

Fit the model to the training data using the AIRS.

The function fit(...), performs the training according to X and y, using the method AIRS.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Training input samples. Each row corresponds to a samples and column to feature.
yUnion[npt.NDArray, list]-Target vector of shape (n_samples,). Must contain the same number of samples as X.
verboseboolTrueIf True, prints training progress information.

Returns

TypeDescription
SelfReturns the instance itself.

Raises

ExceptionDescription
TypeErrorIf X or y are not ndarrays or have incompatible shapes.

predict

def predict(self, X: Union[npt.NDArray, list]) -> npt.NDArray:
...

Predict class labels based on the memory cells created during training.

This method uses the trained memory cells to perform classification of the input data using the k-nearest neighbors approach.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Input samples. Must have the same number of features used during training.

Returns

TypeDescription
npt.NDArrayAn ndarray of the form C (n_samples), containing the predicted classes for X.

Raises

ExceptionDescription
TypeErrorIf X is not a ndarray or list.
FeatureDimensionMismatchIf the number of features in X does not match the expected number.
ModelNotFittedErrorIf the mode has not yet been adjusted and does not have defined memory cells, it is not able to predictions

Extended Example

Complete usage examples are available in the Jupyter Notebooks:


References

Footnotes

  1. Brabazon, A., O'Neill, M., & McGarraghy, S. (2015). Natural Computing Algorithms. In Natural Computing Series. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-662-43631-8 2

  2. AZZOUG, Aghiles. Artificial Immune Recognition System V2. Available at: https://github.com/AghilesAzzoug/Artificial-Immune-System