-
Notifications
You must be signed in to change notification settings - Fork 5
BNSA
The BNSA (Binary Negative Selection Algorithm) class has the purpose of classifying and identifying anomalies through the self and not self methods.
Attributes:
-
N (
int): Number of detectors. Defaults to100. -
aff_thresh (
float): The variable represents the percentage of dissimilarity between the T cell and the own samples. The default value is 10% (0.1), while a value of 1.0 represents 100% dissimilarity. -
max_discards (
int): This parameter indicates the maximum number of detector discards in sequence, which aims to avoid a possible infinite loop if a radius is defined that it is not possible to generate non-self detectors. Defaults to100. -
seed (
int): Seed for the random generation of values in the detectors. Defaults toNone.
Other variables initiated:
-
detectors (
dict): This variable stores a list of detectors by class. -
classes (
npt.NDArray): list of output classes.
The fit(...) function generates the detectors for non-fits with respect to the samples:
def fit(self, X: npt.NDArray, y: npt.NDArray):In it, training is performed according to X and y, using the negative selection method(NegativeSelect).
The input parameters are:
-
X: array with the characteristics of the samples with N samples (rows) and N characteristics (columns). -
y: array with the output classes arranged in N samples that are related toX. -
verbose: boolean with default valueTrue, determines if the feedback from the detector generation will be printed.
Returns the instance of the class.
The predict(...) function performs class prediction using the generated detectors:
def predict(self, X: npt.NDArray) -> npt.NDArray:The input parameter is:
-
X: array with the characteristics for the prediction, with N samples (Rows) and N columns.
Returns:
-
C: prediction array, with the output classes for the given characteristics. -
None: if there are no detectors.
The function score(...) calculates the accuracy of the trained model by making predictions and computing accuracy.
def score(self, X: npt.NDArray, y: list) -> float:It returns the accuracy as a float type.
The function __slice_index_list_by_class(...), separates the indices of the lines according to the output class, to go through the sample array, only in the positions that the output is the class that is being trained:
def __slice_index_list_by_class(self, y: npt.NDArray) -> dict:Returns a dictionary with the classes as key and the indices in X of the samples.
A classe BNSA tem a finalidade de classificação e identificação de anomalias através do método self e not self .
Attributes:
-
N (
int): Quantidade de detectores. Defaults to100. -
aff_thresh (
float): A variável representa a porcentagem de não similaridade entre a célula T e as amostras próprias. O valor padrão é de 10% (0.1), enquanto que o valor de 1.0 representa 100% de não similaridade. -
max_discards (
int): Este parâmetro indica o número máximo de descartes de detectores em sequência, que tem como objetivo evitar um possível loop infinito caso seja definido um raio que não seja possível gerar detectores do não-próprio. Defaults to100. -
seed (
int): Semente para a geração randômica dos valores nos detectores. Defaults toNone.
Outras variáveis iniciadas:
-
detectors (
dict): Esta variável armazena uma lista de detectores por classe. -
classes (
npt.NDArray): lista de classes de saída.
A função fit(...) gera os detectores para os não próprios com relação às amostras:
def fit(self, X: npt.NDArray, y: npt.NDArray):Nela é realizado o treinamento de acordo com X e y, usando o método de seleção negativa(NegativeSelect).
Os parâmetros de entrada são:
-
X: array com as características das amostras com N amostras (linhas) e N características (colunas), normalizados para valores entre [0, 1]. -
y: array com as classes de saídas disposto em N amostras que são relacionadas aoX. -
verbose: booleano com valor defaultTrue, determina se o feedback da geração dos detectores será printado.
Retorna a instância da classe.
A função predict(...) realiza a previsão das classes utilizando os detectores gerados:
def predict(self, X: npt.NDArray) -> npt.NDArray:O parâmetro de entrada:
-
X: array com as características para a previsão, com N amostras (Linhas) e N colunas.
Retorna:
-
C: Um array de previsão com as classes de saída para as características informadas. -
None: se não houver detectores.
A função "score(...)" calcula a precisão do modelo treinado por meio da realização de previsões e do cálculo da acurácia.
def score(self, X: npt.NDArray, y: list) -> float:retorna a acurácia, do tipo float.
A função __slice_index_list_by_class(...), separa os índices das linhas conforme a classe de saída, para percorrer o array de amostra, apenas nas posições que a saída for a classe que está sendo treinada:
def __slice_index_list_by_class(self, y: npt.NDArray) -> dict:Retorna um dicionario com as classes como chave e os índices em X das amostras.