aisp 0.1.42__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aisp-0.1.42 → aisp-0.2.1}/PKG-INFO +14 -16
- {aisp-0.1.42 → aisp-0.2.1}/README.md +8 -15
- {aisp-0.1.42 → aisp-0.2.1}/aisp/base/_classifier.py +6 -2
- aisp-0.2.1/aisp/base/mutation.py +130 -0
- aisp-0.2.1/aisp/csa/__init__.py +9 -0
- aisp-0.2.1/aisp/csa/_ai_immune_recognition_sys.py +498 -0
- aisp-0.2.1/aisp/csa/_base.py +104 -0
- aisp-0.2.1/aisp/csa/_cell.py +61 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/exceptions.py +17 -1
- {aisp-0.1.42 → aisp-0.2.1}/aisp/nsa/_base.py +3 -3
- {aisp-0.1.42 → aisp-0.2.1}/aisp/nsa/_negative_selection.py +43 -45
- aisp-0.2.1/aisp/utils/types.py +31 -0
- aisp-0.2.1/aisp/utils/validation.py +47 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp.egg-info/PKG-INFO +14 -16
- {aisp-0.1.42 → aisp-0.2.1}/aisp.egg-info/SOURCES.txt +8 -1
- aisp-0.2.1/aisp.egg-info/requires.txt +10 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp.egg-info/top_level.txt +1 -0
- {aisp-0.1.42 → aisp-0.2.1}/pyproject.toml +13 -2
- aisp-0.1.42/aisp.egg-info/requires.txt +0 -4
- {aisp-0.1.42 → aisp-0.2.1}/LICENSE +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/__init__.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/base/__init__.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/nsa/__init__.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/nsa/_ns_core.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/utils/__init__.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/utils/_multiclass.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/utils/distance.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/utils/metrics.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp/utils/sanitizers.py +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/aisp.egg-info/dependency_links.txt +0 -0
- {aisp-0.1.42 → aisp-0.2.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: aisp
|
3
|
-
Version: 0.1
|
3
|
+
Version: 0.2.1
|
4
4
|
Summary: Package with techniques of artificial immune systems.
|
5
5
|
Author-email: João Paulo da Silva Barros <jpsilvabarr@gmail.com>
|
6
6
|
Maintainer-email: Alison Zille Lopes <alisonzille@gmail.com>
|
@@ -26,6 +26,11 @@ Requires-Dist: numpy>=1.22.4
|
|
26
26
|
Requires-Dist: numba>=0.59.0
|
27
27
|
Requires-Dist: scipy>=1.8.1
|
28
28
|
Requires-Dist: tqdm>=4.64.1
|
29
|
+
Provides-Extra: dev
|
30
|
+
Requires-Dist: build>=1.2.2.post1; extra == "dev"
|
31
|
+
Requires-Dist: ipykernel>=6.29.5; extra == "dev"
|
32
|
+
Requires-Dist: twine>=5.1.1; extra == "dev"
|
33
|
+
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
29
34
|
Dynamic: license-file
|
30
35
|
|
31
36
|
<div align = center>
|
@@ -79,7 +84,8 @@ Artificial Immune Systems (AIS) are inspired by the vertebrate immune system, cr
|
|
79
84
|
##### Algorithms implemented:
|
80
85
|
|
81
86
|
> - [x] [**Negative Selection.**](https://ais-package.github.io/docs/aisp-techniques/Negative%20Selection/)
|
82
|
-
> - [
|
87
|
+
> - [x] **Clonal Selection Algorithms.**
|
88
|
+
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
83
89
|
> - [ ] *Dendritic Cells.*
|
84
90
|
> - [ ] *Immune Network Theory.*
|
85
91
|
|
@@ -126,22 +132,14 @@ pip install aisp
|
|
126
132
|
|
127
133
|
---
|
128
134
|
|
129
|
-
|
135
|
+
Explore the example notebooks available in the [AIS-Package/aisp repository](https://github.com/AIS-Package/aisp/tree/main/examples).
|
136
|
+
These notebooks demonstrate how to utilize the package's functionalities in various scenarios, including applications of the RNSA,
|
137
|
+
BNSA and AIRS algorithms on datasets such as Iris, Geyser, and Mushrooms.
|
130
138
|
|
131
|
-
|
139
|
+
You can run the notebooks directly in your browser without any local installation using Binder:
|
132
140
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
##### **Negative Selection:**
|
137
|
-
|
138
|
-
+ **RNSA** Application of negative selection techniques for classification using the Iris family flower database and Old Faithful Geyser:
|
139
|
-
+ [iris_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/RNSA/iris_dataBase_example_en.ipynb)
|
140
|
-
+ [geyser_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/RNSA/geyser_dataBase_example_en.ipynb)
|
141
|
-
+ **BNSA**
|
142
|
-
+ [mushrooms_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/BNSA/mushrooms_dataBase_example_en.ipynb)
|
143
|
-
|
144
|
-
---
|
141
|
+
[](https://mybinder.org/v2/gh/AIS-Package/aisp/HEAD?labpath=%2Fexamples)
|
145
142
|
|
143
|
+
> 💡 **Tip**: Binder may take a few minutes to load the environment, especially on the first launch.
|
146
144
|
</section>
|
147
145
|
</section>
|
@@ -49,7 +49,8 @@ Artificial Immune Systems (AIS) are inspired by the vertebrate immune system, cr
|
|
49
49
|
##### Algorithms implemented:
|
50
50
|
|
51
51
|
> - [x] [**Negative Selection.**](https://ais-package.github.io/docs/aisp-techniques/Negative%20Selection/)
|
52
|
-
> - [
|
52
|
+
> - [x] **Clonal Selection Algorithms.**
|
53
|
+
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
53
54
|
> - [ ] *Dendritic Cells.*
|
54
55
|
> - [ ] *Immune Network Theory.*
|
55
56
|
|
@@ -96,22 +97,14 @@ pip install aisp
|
|
96
97
|
|
97
98
|
---
|
98
99
|
|
99
|
-
|
100
|
+
Explore the example notebooks available in the [AIS-Package/aisp repository](https://github.com/AIS-Package/aisp/tree/main/examples).
|
101
|
+
These notebooks demonstrate how to utilize the package's functionalities in various scenarios, including applications of the RNSA,
|
102
|
+
BNSA and AIRS algorithms on datasets such as Iris, Geyser, and Mushrooms.
|
100
103
|
|
101
|
-
|
104
|
+
You can run the notebooks directly in your browser without any local installation using Binder:
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
##### **Negative Selection:**
|
107
|
-
|
108
|
-
+ **RNSA** Application of negative selection techniques for classification using the Iris family flower database and Old Faithful Geyser:
|
109
|
-
+ [iris_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/RNSA/iris_dataBase_example_en.ipynb)
|
110
|
-
+ [geyser_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/RNSA/geyser_dataBase_example_en.ipynb)
|
111
|
-
+ **BNSA**
|
112
|
-
+ [mushrooms_dataBase_example](https://github.com/AIS-Package/aisp/blob/main/examples/BNSA/mushrooms_dataBase_example_en.ipynb)
|
113
|
-
|
114
|
-
---
|
106
|
+
[](https://mybinder.org/v2/gh/AIS-Package/aisp/HEAD?labpath=%2Fexamples)
|
115
107
|
|
108
|
+
> 💡 **Tip**: Binder may take a few minutes to load the environment, especially on the first launch.
|
116
109
|
</section>
|
117
110
|
</section>
|
@@ -16,10 +16,10 @@ class BaseClassifier(ABC):
|
|
16
16
|
``get_params`` method.
|
17
17
|
"""
|
18
18
|
|
19
|
-
classes:
|
19
|
+
classes: Union[npt.NDArray, list] = []
|
20
20
|
|
21
21
|
@abstractmethod
|
22
|
-
def fit(self, X: npt.NDArray, y: npt.NDArray, verbose: bool = True):
|
22
|
+
def fit(self, X: npt.NDArray, y: npt.NDArray, verbose: bool = True) -> "BaseClassifier":
|
23
23
|
"""
|
24
24
|
Train the model using the input data X and corresponding labels y.
|
25
25
|
|
@@ -83,6 +83,10 @@ class BaseClassifier(ABC):
|
|
83
83
|
if len(y) == 0:
|
84
84
|
return 0
|
85
85
|
y_pred = self.predict(X)
|
86
|
+
|
87
|
+
if y_pred is None:
|
88
|
+
return 0
|
89
|
+
|
86
90
|
return accuracy_score(y, y_pred)
|
87
91
|
|
88
92
|
def _slice_index_list_by_class(self, y: npt.NDArray) -> dict:
|
@@ -0,0 +1,130 @@
|
|
1
|
+
"""
|
2
|
+
The functions perform utilize Numba decorators for Just-In-Time compilation.
|
3
|
+
|
4
|
+
Contains functions that generate sets of mutated clones from continuous or binary vectors,
|
5
|
+
simulating the clonal expansion process in artificial immune systems.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import numpy as np
|
9
|
+
import numpy.typing as npt
|
10
|
+
from numba import njit, types
|
11
|
+
|
12
|
+
|
13
|
+
@njit([(types.float64[:], types.int64)], cache=True)
|
14
|
+
def clone_and_mutate_continuous(
|
15
|
+
vector: npt.NDArray[np.float64],
|
16
|
+
n: int
|
17
|
+
) -> npt.NDArray[np.float64]:
|
18
|
+
"""
|
19
|
+
Generate a set of mutated clones from a cell represented by a continuous vector.
|
20
|
+
|
21
|
+
This function creates `n` clones of the input vector and applies random mutations to each of
|
22
|
+
them, simulating the process of clonal expansion in artificial immune systems. Each clone
|
23
|
+
will have a random number of mutations applied in distinct positions of the original vector.
|
24
|
+
|
25
|
+
Parameters
|
26
|
+
----------
|
27
|
+
vector : npt.NDArray[np.float64]
|
28
|
+
The original immune cell with continuous values to be cloned and mutated.
|
29
|
+
n : int
|
30
|
+
The number of mutated clones to be generated.
|
31
|
+
|
32
|
+
Returns
|
33
|
+
-------
|
34
|
+
clone_set : npt.NDArray
|
35
|
+
An Array(n, len(vector)) containing the `n` mutated clones of the original vector.
|
36
|
+
"""
|
37
|
+
n_features = vector.shape[0]
|
38
|
+
clone_set = np.empty((n, n_features), dtype=np.float64)
|
39
|
+
for i in range(n):
|
40
|
+
n_mutations = np.random.randint(1, n_features)
|
41
|
+
clone = vector.copy()
|
42
|
+
position_mutations = np.random.permutation(n_features)[:n_mutations]
|
43
|
+
for j in range(n_mutations):
|
44
|
+
idx = position_mutations[j]
|
45
|
+
clone[idx] = np.float64(np.random.random())
|
46
|
+
clone_set[i] = clone
|
47
|
+
|
48
|
+
return clone_set
|
49
|
+
|
50
|
+
|
51
|
+
@njit([(types.boolean[:], types.int64)], cache=True)
|
52
|
+
def clone_and_mutate_binary(
|
53
|
+
vector: npt.NDArray[np.bool_],
|
54
|
+
n: int
|
55
|
+
) -> npt.NDArray[np.bool_]:
|
56
|
+
"""
|
57
|
+
Generate a set of mutated clones from a cell represented by a binary vector.
|
58
|
+
|
59
|
+
This function creates `n` clones of the input vector and applies random mutations to each of
|
60
|
+
them, changing some bits randomly. The process simulates clonal expansion in artificial
|
61
|
+
immune systems with discrete representations.
|
62
|
+
|
63
|
+
Parameters
|
64
|
+
----------
|
65
|
+
vector : npt.NDArray[np.bool_]
|
66
|
+
The original immune cell with binary values to be cloned and mutated.
|
67
|
+
n : int
|
68
|
+
The number of mutated clones to be generated.
|
69
|
+
|
70
|
+
Returns
|
71
|
+
-------
|
72
|
+
clone_set : npt.NDArray[np.bool_]
|
73
|
+
An Array(n, len(vector)) containing the `n` mutated clones of the original vector.
|
74
|
+
"""
|
75
|
+
n_features = vector.shape[0]
|
76
|
+
clone_set = np.empty((n, n_features), dtype=np.bool_)
|
77
|
+
for i in range(n):
|
78
|
+
n_mutations = np.random.randint(1, n_features)
|
79
|
+
clone = vector.copy()
|
80
|
+
position_mutations = np.random.permutation(n_features)[:n_mutations]
|
81
|
+
for j in range(n_mutations):
|
82
|
+
idx = position_mutations[j]
|
83
|
+
clone[idx] = np.bool_(np.random.randint(0, 2))
|
84
|
+
clone_set[i] = clone
|
85
|
+
|
86
|
+
return clone_set
|
87
|
+
|
88
|
+
|
89
|
+
@njit([(types.float64[:], types.int64, types.float64[:, :])], cache=True)
|
90
|
+
def clone_and_mutate_ranged(
|
91
|
+
vector: npt.NDArray[np.float64],
|
92
|
+
n: int,
|
93
|
+
bounds: npt.NDArray[np.float64]
|
94
|
+
) -> npt.NDArray[np.float64]:
|
95
|
+
"""
|
96
|
+
Generate a set of mutated clones from a cell represented by custom ranges per dimension.
|
97
|
+
|
98
|
+
This function creates `n` clones of the input vector and applies random mutations to each of
|
99
|
+
them, simulating the process of clonal expansion in artificial immune systems. Each clone
|
100
|
+
will have a random number of mutations applied in distinct positions of the original vector.
|
101
|
+
|
102
|
+
Parameters
|
103
|
+
----------
|
104
|
+
vector : npt.NDArray[np.bool_]
|
105
|
+
The original immune cell with binary values to be cloned and mutated.
|
106
|
+
n : int
|
107
|
+
The number of mutated clones to be generated.
|
108
|
+
bounds : np.ndarray
|
109
|
+
Array (n_features, 2) with min and max per dimension.
|
110
|
+
|
111
|
+
Returns
|
112
|
+
-------
|
113
|
+
clone_set : npt.NDArray
|
114
|
+
An Array(n, len(vector)) containing the `n` mutated clones of the original vector.
|
115
|
+
"""
|
116
|
+
n_features = vector.shape[0]
|
117
|
+
clone_set = np.empty((n, n_features), dtype=np.float64)
|
118
|
+
|
119
|
+
for i in range(n):
|
120
|
+
n_mutations = np.random.randint(1, n_features)
|
121
|
+
clone = vector.copy()
|
122
|
+
position_mutations = np.random.permutation(n_features)[:n_mutations]
|
123
|
+
for j in range(n_mutations):
|
124
|
+
idx = position_mutations[j]
|
125
|
+
min_limit = bounds[idx, 0]
|
126
|
+
max_limit = bounds[idx, 1]
|
127
|
+
clone[idx] = np.random.uniform(min_limit, max_limit)
|
128
|
+
clone_set[i] = clone
|
129
|
+
|
130
|
+
return clone_set
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"""Module (CSA) Clonal Selection Algorithm.
|
2
|
+
|
3
|
+
CSAs are inspired by the process of antibody proliferation upon detecting an antigen, during which
|
4
|
+
the generated antibodies undergo mutations in an attempt to enhance pathogen recognition.
|
5
|
+
"""
|
6
|
+
from ._ai_immune_recognition_sys import AIRS
|
7
|
+
|
8
|
+
__author__ = 'João Paulo da Silva Barros'
|
9
|
+
__all__ = ['AIRS']
|