aisp 0.3.2__tar.gz → 0.3.21__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.
Files changed (36) hide show
  1. {aisp-0.3.2 → aisp-0.3.21}/PKG-INFO +1 -1
  2. {aisp-0.3.2 → aisp-0.3.21}/aisp/base/mutation.py +2 -2
  3. {aisp-0.3.2 → aisp-0.3.21}/aisp/csa/_ai_recognition_sys.py +10 -8
  4. {aisp-0.3.2 → aisp-0.3.21}/aisp/ina/_ai_network.py +13 -5
  5. {aisp-0.3.2 → aisp-0.3.21}/aisp/nsa/_binary_negative_selection.py +1 -1
  6. {aisp-0.3.2 → aisp-0.3.21}/aisp/nsa/_negative_selection.py +4 -4
  7. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/distance.py +4 -4
  8. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/types.py +3 -3
  9. {aisp-0.3.2 → aisp-0.3.21}/aisp.egg-info/PKG-INFO +1 -1
  10. {aisp-0.3.2 → aisp-0.3.21}/pyproject.toml +1 -1
  11. {aisp-0.3.2 → aisp-0.3.21}/LICENSE +0 -0
  12. {aisp-0.3.2 → aisp-0.3.21}/README.md +0 -0
  13. {aisp-0.3.2 → aisp-0.3.21}/aisp/__init__.py +0 -0
  14. {aisp-0.3.2 → aisp-0.3.21}/aisp/base/__init__.py +0 -0
  15. {aisp-0.3.2 → aisp-0.3.21}/aisp/base/_base.py +0 -0
  16. {aisp-0.3.2 → aisp-0.3.21}/aisp/base/_classifier.py +0 -0
  17. {aisp-0.3.2 → aisp-0.3.21}/aisp/base/_clusterer.py +0 -0
  18. {aisp-0.3.2 → aisp-0.3.21}/aisp/csa/__init__.py +0 -0
  19. {aisp-0.3.2 → aisp-0.3.21}/aisp/csa/_base.py +0 -0
  20. {aisp-0.3.2 → aisp-0.3.21}/aisp/csa/_cell.py +0 -0
  21. {aisp-0.3.2 → aisp-0.3.21}/aisp/exceptions.py +0 -0
  22. {aisp-0.3.2 → aisp-0.3.21}/aisp/ina/__init__.py +0 -0
  23. {aisp-0.3.2 → aisp-0.3.21}/aisp/ina/_base.py +0 -0
  24. {aisp-0.3.2 → aisp-0.3.21}/aisp/nsa/__init__.py +0 -0
  25. {aisp-0.3.2 → aisp-0.3.21}/aisp/nsa/_base.py +0 -0
  26. {aisp-0.3.2 → aisp-0.3.21}/aisp/nsa/_ns_core.py +0 -0
  27. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/__init__.py +0 -0
  28. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/_multiclass.py +0 -0
  29. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/metrics.py +0 -0
  30. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/sanitizers.py +0 -0
  31. {aisp-0.3.2 → aisp-0.3.21}/aisp/utils/validation.py +0 -0
  32. {aisp-0.3.2 → aisp-0.3.21}/aisp.egg-info/SOURCES.txt +0 -0
  33. {aisp-0.3.2 → aisp-0.3.21}/aisp.egg-info/dependency_links.txt +0 -0
  34. {aisp-0.3.2 → aisp-0.3.21}/aisp.egg-info/requires.txt +0 -0
  35. {aisp-0.3.2 → aisp-0.3.21}/aisp.egg-info/top_level.txt +0 -0
  36. {aisp-0.3.2 → aisp-0.3.21}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aisp
3
- Version: 0.3.2
3
+ Version: 0.3.21
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>
@@ -122,8 +122,8 @@ def clone_and_mutate_ranged(
122
122
  position_mutations = np.random.permutation(n_features)[:n_mutations]
123
123
  for j in range(n_mutations):
124
124
  idx = position_mutations[j]
125
- min_limit = bounds[idx, 0]
126
- max_limit = bounds[idx, 1]
125
+ min_limit = bounds[0][idx]
126
+ max_limit = bounds[1][idx]
127
127
  clone[idx] = np.random.uniform(min_limit, max_limit)
128
128
  clone_set[i] = clone
129
129
 
@@ -111,13 +111,13 @@ class AIRS(BaseAIRS):
111
111
  Way to calculate the distance between the detector and the sample:
112
112
 
113
113
  * ``'Euclidean'`` ➜ The calculation of the distance is given by the expression:
114
- √( (x₁ x₂)² + (y₁ y₂)² + ... + (yn yn)²).
114
+ √( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²).
115
115
 
116
116
  * ``'minkowski'`` ➜ The calculation of the distance is given by the expression:
117
- ( |X₁ Y₁|p + |X₂ Y₂|p + ... + |Xn Yn|p) ¹/ₚ.
117
+ ( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ.
118
118
 
119
119
  * ``'manhattan'`` ➜ The calculation of the distance is given by the expression:
120
- ( |x₁ x₂| + |y₁ y₂| + ... + |yn yn|).
120
+ ( |x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|).
121
121
 
122
122
  seed : int
123
123
  Seed for the random generation of detector values. Defaults to None.
@@ -139,7 +139,7 @@ class AIRS(BaseAIRS):
139
139
 
140
140
  References
141
141
  ----------
142
- .. [1] Brabazon, A., ONeill, M., & McGarraghy, S. (2015). Natural Computing Algorithms. In
142
+ .. [1] Brabazon, A., O'Neill, M., & McGarraghy, S. (2015). Natural Computing Algorithms. In
143
143
  Natural Computing Series. Springer Berlin Heidelberg.
144
144
  https://doi.org/10.1007/978-3-662-43631-8
145
145
 
@@ -195,6 +195,7 @@ class AIRS(BaseAIRS):
195
195
  self.affinity_threshold = 0.0
196
196
  self.classes = []
197
197
  self._bounds: Optional[npt.NDArray[np.float64]] = None
198
+ self._n_features: Optional[int] = None
198
199
 
199
200
  @property
200
201
  def cells_memory(self) -> Optional[Dict[str, list[Cell]]]:
@@ -235,6 +236,7 @@ class AIRS(BaseAIRS):
235
236
  self._bounds = np.vstack([np.min(X, axis=0), np.max(X, axis=0)])
236
237
 
237
238
  self.classes = np.unique(y)
239
+ self._n_features = X.shape[1]
238
240
  sample_index = self._slice_index_list_by_class(y)
239
241
  progress = tqdm(
240
242
  total=len(y),
@@ -330,11 +332,11 @@ class AIRS(BaseAIRS):
330
332
  An ndarray of the form ``C`` [``N samples``], containing the predicted classes for
331
333
  ``X``. or ``None``: If there are no detectors for the prediction.
332
334
  """
333
- if self._all_class_cell_vectors is None:
335
+ if self._all_class_cell_vectors is None or self._n_features is None:
334
336
  return None
335
337
 
336
338
  super()._check_and_raise_exceptions_predict(
337
- X, len(self._cells_memory[self.classes[0]][0].vector), self._feature_type
339
+ X, self._n_features, self._feature_type
338
340
  )
339
341
 
340
342
  c: list = []
@@ -380,7 +382,7 @@ class AIRS(BaseAIRS):
380
382
 
381
383
  References
382
384
  ----------
383
- .. [1] Brabazon, A., ONeill, M., & McGarraghy, S. (2015).
385
+ .. [1] Brabazon, A., O'Neill, M., & McGarraghy, S. (2015).
384
386
  Natural Computing Algorithms. Natural Computing Series.
385
387
  Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-662-43631-8
386
388
  """
@@ -441,7 +443,7 @@ class AIRS(BaseAIRS):
441
443
  distances = pdist(antigens_list, metric="hamming")
442
444
  else:
443
445
  metric_kwargs = {'p': self.p} if self.metric == 'minkowski' else {}
444
- distances = pdist(antigens_list, metric=self.metric, **metric_kwargs)
446
+ distances = pdist(antigens_list, metric=self.metric, **metric_kwargs) # type: ignore
445
447
 
446
448
  n = antigens_list.shape[0]
447
449
  sum_affinity = np.sum(1.0 - (distances / (1.0 + distances)))
@@ -29,7 +29,7 @@ class AiNet(BaseAiNet):
29
29
  clustering and data compression tasks. The aiNet algorithm uses principles from immune
30
30
  network theory, clonal selection, and affinity maturation to compress high-dimensional
31
31
  datasets. [1]_
32
- For clustering, the class uses SciPys implementation of the **Minimum Spanning Tree**
32
+ For clustering, the class uses SciPy's implementation of the **Minimum Spanning Tree**
33
33
  (MST) to remove the most distant nodes and separate the groups. [2]_
34
34
 
35
35
  Parameters
@@ -58,13 +58,13 @@ class AiNet(BaseAiNet):
58
58
  Way to calculate the distance between the detector and the sample:
59
59
 
60
60
  * ``'Euclidean'`` ➜ The calculation of the distance is given by the expression:
61
- √( (x₁ x₂)² + (y₁ y₂)² + ... + (yn yn)²).
61
+ √( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²).
62
62
 
63
63
  * ``'minkowski'`` ➜ The calculation of the distance is given by the expression:
64
- ( |X₁ Y₁|p + |X₂ Y₂|p + ... + |Xn Yn|p) ¹/ₚ.
64
+ ( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ.
65
65
 
66
66
  * ``'manhattan'`` ➜ The calculation of the distance is given by the expression:
67
- ( |x₁ x₂| + |y₁ y₂| + ... + |yn yn|).
67
+ ( |x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|).
68
68
 
69
69
  seed : Optional[int]
70
70
  Seed for the random generation of detector values. Defaults to None.
@@ -455,7 +455,7 @@ class AiNet(BaseAiNet):
455
455
  """
456
456
  u = np.reshape(u, (1, -1))
457
457
  v = np.atleast_2d(v)
458
- distances = cdist(u, v, metric=self.metric, **self._metric_params)[0]
458
+ distances = cdist(u, v, metric=self.metric, **self._metric_params)[0] # type: ignore
459
459
 
460
460
  return 1 - (distances / (1 + distances))
461
461
 
@@ -523,6 +523,8 @@ class AiNet(BaseAiNet):
523
523
  ------
524
524
  ValueError
525
525
  If the Minimum Spanning Tree (MST) has not yet been created
526
+ If Population of antibodies is empty
527
+ If MST statistics (mean or std) are not available.
526
528
 
527
529
  Updates
528
530
  -------
@@ -534,6 +536,12 @@ class AiNet(BaseAiNet):
534
536
  if self._mst_structure is None:
535
537
  raise ValueError("The Minimum Spanning Tree (MST) has not yet been created.")
536
538
 
539
+ if self._population_antibodies is None or len(self._population_antibodies) == 0:
540
+ raise ValueError("Population of antibodies is empty")
541
+
542
+ if self._mst_mean_distance is None or self._mst_std_distance is None:
543
+ raise ValueError("MST statistics (mean or std) are not available.")
544
+
537
545
  if mst_inconsistency_factor is not None:
538
546
  self.mst_inconsistency_factor = mst_inconsistency_factor
539
547
 
@@ -237,4 +237,4 @@ class BNSA(BaseNSA):
237
237
  else:
238
238
  class_differences[_class_] = distances.sum() / self.N
239
239
 
240
- c.append(max(class_differences, key=class_differences.get))
240
+ c.append(max(class_differences, key=class_differences.get)) # type: ignore
@@ -40,11 +40,11 @@ class RNSA(BaseNSA):
40
40
  Way to calculate the distance between the detector and the sample:
41
41
 
42
42
  + ``'Euclidean'`` ➜ The calculation of the distance is given by the expression:
43
- √( (x₁ x₂)² + (y₁ y₂)² + ... + (yn yn)²).
43
+ √( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²).
44
44
  + ``'minkowski'`` ➜ The calculation of the distance is given by the expression:
45
- ( |X₁ Y₁|p + |X₂ Y₂|p + ... + |Xn Yn|p) ¹/ₚ.
45
+ ( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ.
46
46
  + ``'manhattan'`` ➜ The calculation of the distance is given by the expression:
47
- ( |x₁ x₂| + |y₁ y₂| + ... + |yn yn|) .
47
+ ( |x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|) .
48
48
  max_discards : int, default=1000
49
49
  This parameter indicates the maximum number of consecutive detector discards, aimed at
50
50
  preventing a possible infinite loop in case a radius is defined that cannot generate
@@ -260,7 +260,7 @@ class RNSA(BaseNSA):
260
260
  average_distance[_class_] = np.average(
261
261
  [self.__distance(detector, line) for detector in detectores]
262
262
  )
263
- c.append(max(average_distance, key=average_distance.get))
263
+ c.append(max(average_distance, key=average_distance.get)) # type: ignore
264
264
  return np.array(c)
265
265
 
266
266
  def __checks_valid_detector(
@@ -40,7 +40,7 @@ def hamming(u: npt.NDArray[np.bool_], v: npt.NDArray[np.bool_]) -> float64:
40
40
  def euclidean(u: npt.NDArray[np.float64], v: npt.NDArray[np.float64]) -> float64:
41
41
  """Calculate the normalized Euclidean distance between two points.
42
42
 
43
- √( (x₁ x₂)² + (y₁ y₂)² + ... + (yn yn)²)
43
+ √( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²)
44
44
 
45
45
  Parameters
46
46
  ----------
@@ -61,7 +61,7 @@ def euclidean(u: npt.NDArray[np.float64], v: npt.NDArray[np.float64]) -> float64
61
61
  def cityblock(u: npt.NDArray[float64], v: npt.NDArray[float64]) -> float64:
62
62
  """Calculate the normalized Manhattan distance between two points.
63
63
 
64
- (|x₁ x₂| + |y₁ y₂| + ... + |yn yn|) / n
64
+ (|x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|) / n
65
65
 
66
66
  Parameters
67
67
  ----------
@@ -86,7 +86,7 @@ def cityblock(u: npt.NDArray[float64], v: npt.NDArray[float64]) -> float64:
86
86
  def minkowski(u: npt.NDArray[float64], v: npt.NDArray[float64], p: float = 2.0) -> float64:
87
87
  """Calculate the normalized Minkowski distance between two points.
88
88
 
89
- (( |X₁ Y₁|p + |X₂ Y₂|p + ... + |Xn Yn|p) ¹/ₚ.) / n
89
+ (( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ.) / n
90
90
 
91
91
  Parameters
92
92
  ----------
@@ -124,7 +124,7 @@ def compute_metric_distance(
124
124
  u: npt.NDArray[float64],
125
125
  v: npt.NDArray[float64],
126
126
  metric: int,
127
- p: float64 = 2.0
127
+ p: float = 2.0
128
128
  ) -> float64:
129
129
  """Calculate the distance between two points by the chosen metric.
130
130
 
@@ -12,11 +12,11 @@ FeatureType : Literal["binary-features", "continuous-features", "ranged-features
12
12
  MetricType : Literal["manhattan", "minkowski", "euclidean"]
13
13
  Specifies the distance metric to use for calculations. Possible values:
14
14
  - "manhattan": The calculation of the distance is given by the expression:
15
- √( (x₁ x₂)² + (y₁ y₂)² + ... + (yn yn)²).
15
+ √( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²).
16
16
  - "minkowski": The calculation of the distance is given by the expression:
17
- ( |X₁ Y₁|p + |X₂ Y₂|p + ... + |Xn Yn|p) ¹/ₚ.
17
+ ( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ.
18
18
  - "euclidean": The calculation of the distance is given by the expression:
19
- ( |x₁ x₂| + |y₁ y₂| + ... + |yn yn|).
19
+ ( |x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|).
20
20
  """
21
21
 
22
22
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aisp
3
- Version: 0.3.2
3
+ Version: 0.3.21
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>
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "aisp"
8
- version = "0.3.2"
8
+ version = "0.3.21"
9
9
  authors = [
10
10
  { name="João Paulo da Silva Barros", email="jpsilvabarr@gmail.com" },
11
11
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes