aisp 0.1.31__py3-none-any.whl → 0.1.32__py3-none-any.whl
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/NSA/_negative_selection.py +28 -24
- {aisp-0.1.31.dist-info → aisp-0.1.32.dist-info}/METADATA +1 -1
- aisp-0.1.32.dist-info/RECORD +8 -0
- aisp-0.1.31.dist-info/RECORD +0 -8
- {aisp-0.1.31.dist-info → aisp-0.1.32.dist-info}/LICENSE +0 -0
- {aisp-0.1.31.dist-info → aisp-0.1.32.dist-info}/WHEEL +0 -0
- {aisp-0.1.31.dist-info → aisp-0.1.32.dist-info}/top_level.txt +0 -0
aisp/NSA/_negative_selection.py
CHANGED
@@ -3,7 +3,7 @@ import numpy.typing as npt
|
|
3
3
|
from tqdm import tqdm
|
4
4
|
from typing import Dict, Literal, Optional, Union
|
5
5
|
from collections import namedtuple
|
6
|
-
from scipy.spatial.distance import
|
6
|
+
from scipy.spatial.distance import cdist
|
7
7
|
|
8
8
|
from ._base import Base
|
9
9
|
|
@@ -421,8 +421,7 @@ class RNSA(Base):
|
|
421
421
|
[self.__distance(detector, line)
|
422
422
|
for detector in detectores]
|
423
423
|
)
|
424
|
-
C = np.append(
|
425
|
-
C, [max(average_distance, key=average_distance.get)])
|
424
|
+
C = np.append(C, [max(average_distance, key=average_distance.get)])
|
426
425
|
return C
|
427
426
|
|
428
427
|
def __checks_valid_detector(self, X: npt.NDArray = None, vector_x: npt.NDArray = None,
|
@@ -960,11 +959,12 @@ class BNSA(Base):
|
|
960
959
|
is_valid_detector: bool = True
|
961
960
|
# Gera um vetor candidato a detector aleatoriamente com valores 0 e 1.
|
962
961
|
vector_x = np.random.choice([False, True], size=X.shape[1])
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
962
|
+
# Calcula a distância entre o candidato e as amostras da classe.
|
963
|
+
distances = cdist(np.expand_dims(vector_x, axis=0),
|
964
|
+
X[sample_index[_class_]], metric='hamming')
|
965
|
+
# Verifica se alguma das distâncias está abaixo ou igual ao limiar
|
966
|
+
is_valid_detector = not np.any(distances <= self.aff_thresh)
|
967
|
+
|
968
968
|
# Se o detector for válido, adicione a lista dos válidos.
|
969
969
|
if is_valid_detector:
|
970
970
|
discard_count = 0
|
@@ -1057,13 +1057,18 @@ class BNSA(Base):
|
|
1057
1057
|
for _class_ in self.classes:
|
1058
1058
|
# Lista para armazenar as taxas de similaridade entre a amostra e os detectores.
|
1059
1059
|
similarity_sum: float = 0
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1060
|
+
|
1061
|
+
# Calcula a distância de Hamming entre a linha e todos os detectores
|
1062
|
+
distances = cdist(np.expand_dims(line, axis=0),
|
1063
|
+
self.detectors[_class_], metric='hamming')
|
1064
|
+
|
1065
|
+
# Verificar se alguma distância está abaixo ou igual ao limiar
|
1066
|
+
if np.any(distances <= self.aff_thresh):
|
1067
|
+
class_found = False
|
1068
|
+
else:
|
1069
|
+
# Somar todas as distâncias
|
1070
|
+
similarity_sum = np.sum(distances)
|
1071
|
+
|
1067
1072
|
# Se a amostra passar por todos os detectores de uma classe, adiciona a classe como
|
1068
1073
|
# possível previsão e sua media de similaridade.
|
1069
1074
|
if class_found:
|
@@ -1086,19 +1091,18 @@ class BNSA(Base):
|
|
1086
1091
|
for _class_ in self.classes:
|
1087
1092
|
# Atribua-a o rotulo a classe com à maior distância em relação ao detector mais próximo.
|
1088
1093
|
if self.no_label_sample_selection == 'nearest_difference':
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
class_differences[_class_] =
|
1094
|
+
difference_min: float = cdist( np.expand_dims(line, axis=0),
|
1095
|
+
self.detectors[_class_], metric='hamming'
|
1096
|
+
).min()
|
1097
|
+
class_differences[_class_] = difference_min
|
1093
1098
|
# Ou com base na maior distância com relação à média da distancias dos detectores
|
1094
1099
|
else:
|
1095
|
-
difference_sum: float = 0
|
1096
|
-
|
1097
|
-
|
1100
|
+
difference_sum: float = cdist( np.expand_dims(line, axis=0),
|
1101
|
+
self.detectors[_class_], metric='hamming'
|
1102
|
+
).sum()
|
1098
1103
|
class_differences[_class_] = difference_sum / self.N
|
1099
1104
|
|
1100
|
-
C = np.append(
|
1101
|
-
C, [max(class_differences, key=class_differences.get)])
|
1105
|
+
C = np.append(C, [max(class_differences, key=class_differences.get)])
|
1102
1106
|
|
1103
1107
|
return C
|
1104
1108
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
aisp/NSA/__init__.py,sha256=cmHx6ydTfhFAOfgCjDcKDJRfH5Sz41LHqVRlDZgVL58,141
|
2
|
+
aisp/NSA/_base.py,sha256=HjdF4ZnophMY_Ooj2ERjhVoWwqe8Q4rPQ-UxHlfIeNY,9557
|
3
|
+
aisp/NSA/_negative_selection.py,sha256=bYbkorRTY3V7_gS0L1QnYxpoy-KGsGDxwhza0RjhcKM,55330
|
4
|
+
aisp-0.1.32.dist-info/LICENSE,sha256=fTqV5eBpeAZO0_jit8j4Ref9ikBSlHJ8xwj5TLg7gFk,7817
|
5
|
+
aisp-0.1.32.dist-info/METADATA,sha256=0SxlcxhAKPH1XSkIENEp2zIxu_YKvq-yqSLu-dISNsI,7999
|
6
|
+
aisp-0.1.32.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
7
|
+
aisp-0.1.32.dist-info/top_level.txt,sha256=Q5aJi_rAVT5UNS1As0ZafoyS5dwNibnoyOYV7RWUB9s,5
|
8
|
+
aisp-0.1.32.dist-info/RECORD,,
|
aisp-0.1.31.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
aisp/NSA/__init__.py,sha256=cmHx6ydTfhFAOfgCjDcKDJRfH5Sz41LHqVRlDZgVL58,141
|
2
|
-
aisp/NSA/_base.py,sha256=HjdF4ZnophMY_Ooj2ERjhVoWwqe8Q4rPQ-UxHlfIeNY,9557
|
3
|
-
aisp/NSA/_negative_selection.py,sha256=pWYgiyd0Jr0w1FIt6StQ_HEQr5-UjF4mVI0QJIcXeHM,54974
|
4
|
-
aisp-0.1.31.dist-info/LICENSE,sha256=fTqV5eBpeAZO0_jit8j4Ref9ikBSlHJ8xwj5TLg7gFk,7817
|
5
|
-
aisp-0.1.31.dist-info/METADATA,sha256=hKXEal6xERzXfr3b7HX1VP43xq73f3tR1A1YAsIRics,7999
|
6
|
-
aisp-0.1.31.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
7
|
-
aisp-0.1.31.dist-info/top_level.txt,sha256=Q5aJi_rAVT5UNS1As0ZafoyS5dwNibnoyOYV7RWUB9s,5
|
8
|
-
aisp-0.1.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|