aisp 0.2.1__tar.gz → 0.3.0__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.2.1 → aisp-0.3.0}/PKG-INFO +6 -5
- {aisp-0.2.1 → aisp-0.3.0}/README.md +5 -4
- {aisp-0.2.1 → aisp-0.3.0}/aisp/__init__.py +1 -1
- aisp-0.3.0/aisp/base/__init__.py +7 -0
- aisp-0.3.0/aisp/base/_base.py +65 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/base/_classifier.py +3 -15
- aisp-0.3.0/aisp/base/_clusterer.py +76 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/csa/__init__.py +1 -1
- aisp-0.2.1/aisp/csa/_ai_immune_recognition_sys.py → aisp-0.3.0/aisp/csa/_ai_recognition_sys.py +17 -20
- aisp-0.3.0/aisp/ina/__init__.py +14 -0
- aisp-0.3.0/aisp/ina/_ai_network.py +553 -0
- aisp-0.3.0/aisp/ina/_base.py +124 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/nsa/_negative_selection.py +34 -38
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/distance.py +4 -4
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/validation.py +5 -5
- {aisp-0.2.1 → aisp-0.3.0}/aisp.egg-info/PKG-INFO +6 -5
- {aisp-0.2.1 → aisp-0.3.0}/aisp.egg-info/SOURCES.txt +6 -1
- {aisp-0.2.1 → aisp-0.3.0}/aisp.egg-info/top_level.txt +0 -1
- {aisp-0.2.1 → aisp-0.3.0}/pyproject.toml +1 -1
- aisp-0.2.1/aisp/base/__init__.py +0 -5
- {aisp-0.2.1 → aisp-0.3.0}/LICENSE +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/base/mutation.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/csa/_base.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/csa/_cell.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/exceptions.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/nsa/__init__.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/nsa/_base.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/nsa/_ns_core.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/__init__.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/_multiclass.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/metrics.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/sanitizers.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp/utils/types.py +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp.egg-info/dependency_links.txt +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/aisp.egg-info/requires.txt +0 -0
- {aisp-0.2.1 → aisp-0.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: aisp
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0
|
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>
|
@@ -84,10 +84,11 @@ Artificial Immune Systems (AIS) are inspired by the vertebrate immune system, cr
|
|
84
84
|
##### Algorithms implemented:
|
85
85
|
|
86
86
|
> - [x] [**Negative Selection.**](https://ais-package.github.io/docs/aisp-techniques/Negative%20Selection/)
|
87
|
-
> - [x] **Clonal Selection Algorithms.**
|
88
|
-
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
89
|
-
> - [ ] *
|
90
|
-
> - [
|
87
|
+
> - [x] [**Clonal Selection Algorithms.**](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
88
|
+
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/airs/)
|
89
|
+
> - [ ] *Danger Theory.*
|
90
|
+
> - [x] [*Immune Network Theory.*](https://ais-package.github.io/docs/aisp-techniques/Immune%20Network%20Theory)
|
91
|
+
> - [AiNet - Artificial Immune Network para Clustering and Compression](https://ais-package.github.io/docs/aisp-techniques/Immune%20Network%20Theory/ainet)
|
91
92
|
|
92
93
|
</section>
|
93
94
|
|
@@ -49,10 +49,11 @@ 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
|
-
> - [x] **Clonal Selection Algorithms.**
|
53
|
-
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
54
|
-
> - [ ] *
|
55
|
-
> - [
|
52
|
+
> - [x] [**Clonal Selection Algorithms.**](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/)
|
53
|
+
> * [AIRS - Artificial Immune Recognition System](https://ais-package.github.io/docs/aisp-techniques/Clonal%20Selection%20Algorithms/airs/)
|
54
|
+
> - [ ] *Danger Theory.*
|
55
|
+
> - [x] [*Immune Network Theory.*](https://ais-package.github.io/docs/aisp-techniques/Immune%20Network%20Theory)
|
56
|
+
> - [AiNet - Artificial Immune Network para Clustering and Compression](https://ais-package.github.io/docs/aisp-techniques/Immune%20Network%20Theory/ainet)
|
56
57
|
|
57
58
|
</section>
|
58
59
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"""Base class for parameter introspection compatible with the scikit-learn API."""
|
2
|
+
import random
|
3
|
+
|
4
|
+
import numpy as np
|
5
|
+
from numba import njit
|
6
|
+
|
7
|
+
|
8
|
+
class Base:
|
9
|
+
"""
|
10
|
+
Generic base class for models with a common interface.
|
11
|
+
|
12
|
+
Provides the ``get_params`` and ``set_params`` method for compatibility with
|
13
|
+
the scikit-learn API, allowing access to the model's public parameters.
|
14
|
+
"""
|
15
|
+
|
16
|
+
def set_params(self, **params):
|
17
|
+
"""
|
18
|
+
Set the parameters of the instance.
|
19
|
+
|
20
|
+
This method is required to ensure compatibility with scikit-learn functions
|
21
|
+
|
22
|
+
Parameters
|
23
|
+
----------
|
24
|
+
**params
|
25
|
+
set as attributes on the instance.
|
26
|
+
|
27
|
+
Returns
|
28
|
+
-------
|
29
|
+
self
|
30
|
+
"""
|
31
|
+
for key, value in params.items():
|
32
|
+
if not key.startswith("_") and hasattr(self, key):
|
33
|
+
setattr(self, key, value)
|
34
|
+
return self
|
35
|
+
|
36
|
+
def get_params(self, deep: bool = True) -> dict: # pylint: disable=W0613
|
37
|
+
"""
|
38
|
+
Return a dictionary with the object's main parameters.
|
39
|
+
|
40
|
+
This method is required to ensure compatibility with scikit-learn functions.
|
41
|
+
|
42
|
+
Returns
|
43
|
+
-------
|
44
|
+
dict
|
45
|
+
Dictionary containing the object's attributes that do not start with "_".
|
46
|
+
"""
|
47
|
+
return {
|
48
|
+
key: value
|
49
|
+
for key, value in self.__dict__.items()
|
50
|
+
if not key.startswith("_")
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
@njit(cache=True)
|
55
|
+
def set_seed_numba(seed: int):
|
56
|
+
"""
|
57
|
+
Set the seed for random numbers used by functions compiled with Numba.
|
58
|
+
|
59
|
+
Parameters
|
60
|
+
----------
|
61
|
+
seed : int
|
62
|
+
Integer value used to initialize Numba's random number generator.
|
63
|
+
"""
|
64
|
+
np.random.seed(seed)
|
65
|
+
random.seed(seed)
|
@@ -5,15 +5,15 @@ from typing import Optional, Union
|
|
5
5
|
|
6
6
|
import numpy.typing as npt
|
7
7
|
|
8
|
+
from ._base import Base
|
8
9
|
from ..utils import slice_index_list_by_class
|
9
10
|
from ..utils.metrics import accuracy_score
|
10
11
|
|
11
12
|
|
12
|
-
class BaseClassifier(ABC):
|
13
|
+
class BaseClassifier(ABC, Base):
|
13
14
|
"""Base class for classification algorithms.
|
14
15
|
|
15
|
-
Defines the abstract methods ``fit`` and ``predict``, and implements the ``score
|
16
|
-
``get_params`` method.
|
16
|
+
Defines the abstract methods ``fit`` and ``predict``, and implements the ``score`` method.
|
17
17
|
"""
|
18
18
|
|
19
19
|
classes: Union[npt.NDArray, list] = []
|
@@ -106,15 +106,3 @@ class BaseClassifier(ABC):
|
|
106
106
|
A dictionary with the list of array positions(``y``), with the classes as key.
|
107
107
|
"""
|
108
108
|
return slice_index_list_by_class(self.classes, y)
|
109
|
-
|
110
|
-
def get_params(self, deep: bool = True) -> dict: # pylint: disable=W0613
|
111
|
-
"""
|
112
|
-
Return a dictionary with the object's main parameters.
|
113
|
-
|
114
|
-
This method is required to ensure compatibility with scikit-learn functions.
|
115
|
-
"""
|
116
|
-
return {
|
117
|
-
key: value
|
118
|
-
for key, value in self.__dict__.items()
|
119
|
-
if not key.startswith("_")
|
120
|
-
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
"""Base class for clustering algorithms."""
|
2
|
+
|
3
|
+
from abc import ABC, abstractmethod
|
4
|
+
from typing import Optional
|
5
|
+
|
6
|
+
import numpy.typing as npt
|
7
|
+
|
8
|
+
from ._base import Base
|
9
|
+
|
10
|
+
|
11
|
+
class BaseClusterer(ABC, Base):
|
12
|
+
"""Abstract base class for clustering algorithms.
|
13
|
+
|
14
|
+
This class defines the core interface for clustering models. It enforces
|
15
|
+
the implementation of the `fit` and `predict` methods in all derived classes,
|
16
|
+
and provides a default implementation for `fit_predict` and `get_params`.
|
17
|
+
"""
|
18
|
+
|
19
|
+
@abstractmethod
|
20
|
+
def fit(self, X: npt.NDArray, verbose: bool = True) -> "BaseClusterer":
|
21
|
+
"""
|
22
|
+
Train the model using the input data X.
|
23
|
+
|
24
|
+
This abstract method is implemented by the class that inherits it.
|
25
|
+
|
26
|
+
Parameters
|
27
|
+
----------
|
28
|
+
X : npt.NDArray
|
29
|
+
Input data used for training the model.
|
30
|
+
verbose : bool, default=True
|
31
|
+
Flag to enable or disable detailed output during training.
|
32
|
+
|
33
|
+
Returns
|
34
|
+
-------
|
35
|
+
self : BaseClusterer
|
36
|
+
Returns the instance of the class that implements this method.
|
37
|
+
"""
|
38
|
+
|
39
|
+
@abstractmethod
|
40
|
+
def predict(self, X: npt.NDArray) -> Optional[npt.NDArray]:
|
41
|
+
"""
|
42
|
+
Generate predictions based on the input data X.
|
43
|
+
|
44
|
+
This abstract method is implemented by the class that inherits it.
|
45
|
+
|
46
|
+
Parameters
|
47
|
+
----------
|
48
|
+
X : npt.NDArray
|
49
|
+
Input data for which predictions will be generated.
|
50
|
+
|
51
|
+
Returns
|
52
|
+
-------
|
53
|
+
predictions : Optional[npt.NDArray]
|
54
|
+
Predicted cluster labels for each input sample, or None if prediction is not possible.
|
55
|
+
"""
|
56
|
+
|
57
|
+
def fit_predict(self, X, verbose: bool = True):
|
58
|
+
"""Fit the clustering model to the data and return cluster labels.
|
59
|
+
|
60
|
+
This is a convenience method that combines `fit` and `predict`
|
61
|
+
into a single call.
|
62
|
+
|
63
|
+
Parameters
|
64
|
+
----------
|
65
|
+
X : npt.NDArray
|
66
|
+
Input data for which predictions will be generated.
|
67
|
+
verbose : bool, default=True
|
68
|
+
Flag to enable or disable detailed output during training.
|
69
|
+
|
70
|
+
Returns
|
71
|
+
-------
|
72
|
+
predictions : Optional[npt.NDArray]
|
73
|
+
Predicted cluster labels for each input sample, or None if prediction is not possible.
|
74
|
+
"""
|
75
|
+
self.fit(X, verbose)
|
76
|
+
return self.predict(X)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
CSAs are inspired by the process of antibody proliferation upon detecting an antigen, during which
|
4
4
|
the generated antibodies undergo mutations in an attempt to enhance pathogen recognition.
|
5
5
|
"""
|
6
|
-
from .
|
6
|
+
from ._ai_recognition_sys import AIRS
|
7
7
|
|
8
8
|
__author__ = 'João Paulo da Silva Barros'
|
9
9
|
__all__ = ['AIRS']
|
aisp-0.2.1/aisp/csa/_ai_immune_recognition_sys.py → aisp-0.3.0/aisp/csa/_ai_recognition_sys.py
RENAMED
@@ -11,7 +11,7 @@ import numpy.typing as npt
|
|
11
11
|
from scipy.spatial.distance import pdist
|
12
12
|
from tqdm import tqdm
|
13
13
|
|
14
|
-
|
14
|
+
from ..base import set_seed_numba
|
15
15
|
from ._cell import Cell
|
16
16
|
from ..utils.sanitizers import sanitize_param, sanitize_seed, sanitize_choice
|
17
17
|
from ..utils.distance import hamming, compute_metric_distance, get_metric_code
|
@@ -178,6 +178,7 @@ class AIRS(BaseAIRS):
|
|
178
178
|
self.seed: Optional[int] = sanitize_seed(seed)
|
179
179
|
if self.seed is not None:
|
180
180
|
np.random.seed(self.seed)
|
181
|
+
set_seed_numba(self.seed)
|
181
182
|
|
182
183
|
self._feature_type: FeatureType = "continuous-features"
|
183
184
|
|
@@ -219,8 +220,6 @@ class AIRS(BaseAIRS):
|
|
219
220
|
AIRS
|
220
221
|
Returns the instance itself.
|
221
222
|
"""
|
222
|
-
progress = None
|
223
|
-
|
224
223
|
self._feature_type = detect_vector_data_type(X)
|
225
224
|
|
226
225
|
super()._check_and_raise_exceptions_fit(X, y)
|
@@ -234,18 +233,17 @@ class AIRS(BaseAIRS):
|
|
234
233
|
|
235
234
|
self.classes = np.unique(y)
|
236
235
|
sample_index = self._slice_index_list_by_class(y)
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
236
|
+
progress = tqdm(
|
237
|
+
total=len(y),
|
238
|
+
postfix="\n",
|
239
|
+
disable=not verbose,
|
240
|
+
bar_format="{desc} ┇{bar}┇ {n}/{total} memory cells for each aᵢ",
|
241
|
+
)
|
243
242
|
pool_cells_classes = {}
|
244
243
|
for _class_ in self.classes:
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
)
|
244
|
+
progress.set_description_str(
|
245
|
+
f"Generating the memory cells for the {_class_} class:"
|
246
|
+
)
|
249
247
|
|
250
248
|
x_class = X[sample_index[_class_]]
|
251
249
|
# Calculating the similarity threshold between antigens
|
@@ -294,15 +292,14 @@ class AIRS(BaseAIRS):
|
|
294
292
|
if self._affinity(c_candidate.vector, c_match.vector) < sufficiently_similar:
|
295
293
|
pool_c.remove(c_match)
|
296
294
|
|
297
|
-
|
298
|
-
progress.update(1)
|
295
|
+
progress.update(1)
|
299
296
|
pool_cells_classes[_class_] = pool_c
|
300
297
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
298
|
+
progress.set_description(
|
299
|
+
f"\033[92m✔ Set of memory cells for classes ({', '.join(map(str, self.classes))}) "
|
300
|
+
f"successfully generated\033[0m"
|
301
|
+
)
|
302
|
+
progress.close()
|
306
303
|
self._cells_memory = pool_cells_classes
|
307
304
|
return self
|
308
305
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"""Module (ina) Immune Network Algorithm.
|
2
|
+
|
3
|
+
This module implements algorithms based on Network Theory Algorithms proposed by Jerne.
|
4
|
+
|
5
|
+
Classes
|
6
|
+
-------
|
7
|
+
AiNet
|
8
|
+
Artificial Immune Network implementation for clustering.
|
9
|
+
"""
|
10
|
+
|
11
|
+
from ._ai_network import AiNet
|
12
|
+
|
13
|
+
__author__ = 'João Paulo da Silva Barros'
|
14
|
+
__all__ = ['AiNet']
|