Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/about-us.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The AISP, or Artificial Immune Systems Package, had its origins in a research pr
name='Alison Zille Lopes'
date='2022'
githubUrl='https://github.com/alisonzille'
lattesUrl='http://lattes.cnpq.br/3294097090760981'
lattesUrl='https://lattes.cnpq.br/3294097090760981'
/>

</div>
Expand All @@ -44,7 +44,7 @@ The AISP, or Artificial Immune Systems Package, had its origins in a research pr
date='2022-2023'
description="I was tasked with implementing version 0.1, which features the BNSA and RNSA negative selection classes, including fixed and variable radius versions."
githubUrl='https://github.com/Joao-Paulo-Silva'
lattesUrl='http://lattes.cnpq.br/2561057724411407'
lattesUrl='https://lattes.cnpq.br/2561057724411407'
/>

</div>
18 changes: 12 additions & 6 deletions docs/advanced-guides/Core/negative-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ last_update:

The functions perform detector checks and utilize Numba decorators for Just-In-Time compilation

### Function check_detector_bnsa_validity(...):
## Function check_detector_bnsa_validity(...)

```python
def check_detector_bnsa_validity(
Expand All @@ -20,18 +20,19 @@ def check_detector_bnsa_validity(

Checks the validity of a candidate detector (vector_x) against samples from a class (x_class) using the Hamming distance. A detector is considered INVALID if its distance to any sample in ``x_class`` is less than or equal to ``aff_thresh``.


**Parameters**:

* x_class (``npt.NDArray``): Array containing the class samples. Expected shape: (n_samples, n_features).
* vector_x (``npt.NDArray``): Array representing the detector. Expected shape: (n_features,).
* aff_thresh (``float``): Affinity threshold.

**returns**:

* True if the detector is valid, False otherwise.

---

### Function bnsa_class_prediction(...):
## Function bnsa_class_prediction(...)

```python
def bnsa_class_prediction(
Expand All @@ -40,21 +41,23 @@ def bnsa_class_prediction(
aff_thresh: float
) -> int:
```
Defines the class of a sample from the non-self detectors.

Defines the class of a sample from the non-self detectors.

**Parameters**:

* features (``npt.NDArray``): binary sample to be classified (shape: [n_features]).
* class_detectors (``npt.NDArray``): Array containing the detectors of all classes
(shape: [n_classes, n_detectors, n_features]).
* aff_thresh (``float``): Affinity threshold that determines whether a detector recognizes the sample as non-self.

**returns**:

* int: Index of the predicted class. Returns -1 if it is non-self for all classes.

---

### Function check_detector_rnsa_validity(...):
## Function check_detector_rnsa_validity(...)

```python
def check_detector_rnsa_validity(
Expand All @@ -65,16 +68,19 @@ def check_detector_rnsa_validity(
p: float
) -> bool:
```

Checks the validity of a candidate detector (vector_x) against samples from a class (x_class) using the Hamming distance. A detector is considered INVALID if its distance to any sample in ``x_class`` is less than or equal to ``aff_thresh``.

**Parameters**:

* x_class (``npt.NDArray``): Array containing the class samples. Expected shape: (n_samples, n_features).
* vector_x (``npt.NDArray``): Array representing the detector. Expected shape: (n_features,).
* threshold (``float``): threshold.
* metric (``int``): Distance metric to be used. Available options: [0 (Euclidean), 1 (Manhattan), 2 (Minkowski)]
* p (``float``): Parameter for the Minkowski distance (used only if `metric` is "minkowski").

**returns**:

* int: Index of the predicted class. Returns -1 if it is non-self for all classes.

---
---
2 changes: 1 addition & 1 deletion docs/advanced-guides/Utils/Display.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def finish(self) -> None

End the table display, printing the bottom border and total time.

---
---
39 changes: 24 additions & 15 deletions docs/advanced-guides/Utils/Distance.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ def hamming(u: npt.NDArray, v: npt.NDArray) -> np.float64:
```

The function to calculate the normalized Hamming distance between two points.

$((x₁ ≠ x₂) + (y₁ ≠ y₂) + ... + (yn ≠ yn)) / n$

$$\frac{(x_1 \neq y_1) + (x_2 \neq y_2) + \cdots + (x_n \neq y_n)}{n}$$

**Parameters:**

* u (``npt.NDArray``): Coordinates of the first point.
* v (``npt.NDArray``): Coordinates of the second point.

**Returns:**

* Distance (``float``) between the two points.

---
Expand All @@ -36,15 +37,15 @@ def euclidean(u: npt.NDArray[np.float64], v: npt.NDArray[np.float64]) -> np.floa

Function to calculate the normalized Euclidean distance between two points.

$√( (x₁ - x₂)² + (y₁ - y₂)² + ... + (yn - yn)²)$


$$\sqrt{(X_{1} - X_{1})^2 + (Y_{2} - Y_{2})^2 + \cdots + (Y_{n} - Y_{n})^2}$$

**Parameters:**

* u (``npt.NDArray``): Coordinates of the first point.
* v (``npt.NDArray``): Coordinates of the second point.

**Returns:**

* Distance (``float``) between the two points.

---
Expand All @@ -56,15 +57,16 @@ def cityblock(u: npt.NDArray[np.float64], v: npt.NDArray[np.float64]) -> np.floa
```

Function to calculate the normalized Manhattan distance between two points.

$(|x₁ - x₂| + |y₁ - y₂| + ... + |yn - yn|) / n$

$$\frac{(|X_{1} - X_{1}| + |Y_{2} - Y_{2}| + \cdots + |Y_{n} - Y_{n}|)}{n}$$

**Parameters:**

* u (``npt.NDArray``): Coordinates of the first point.
* v (``npt.NDArray``): Coordinates of the second point.

**Returns:**

* Distance (``float``) between the two points.

---
Expand All @@ -76,19 +78,20 @@ def minkowski(u: npt.NDArray[np.float64], v: npt.NDArray[np.float64], p: float =
```

Function to calculate the normalized Minkowski distance between two points.

$(( |X₁ - Y₁|p + |X₂ - Y₂|p + ... + |Xn - Yn|p) ¹/ₚ) / n$

$$( |X_{1} - Y_{1}|^p + |X_{2} - Y_{2}|^p + \cdots + |X_{n} - Y_{n}|^p)^\frac{1}{p}$$

**Parameters:**

* u (``npt.NDArray``): Coordinates of the first point.
* v (``npt.NDArray``): Coordinates of the second point.
* p float: The p parameter defines the type of distance to be calculated:
- p = 1: **Manhattan** distance — sum of absolute differences.
- p = 2: **Euclidean** distance — sum of squared differences (square root).
- p > 2: **Minkowski** distance with an increasing penalty as p increases.
* p = 1: **Manhattan** distance — sum of absolute differences.
* p = 2: **Euclidean** distance — sum of squared differences (square root).
* p > 2: **Minkowski** distance with an increasing penalty as p increases.

**Returns:**

* Distance (``float``) between the two points.

---
Expand All @@ -107,12 +110,14 @@ def compute_metric_distance(
Function to calculate the distance between two points by the chosen ``metric``.

**Parameters:**

* u (``npt.NDArray``): Coordinates of the first point.
* v (``npt.NDArray``): Coordinates of the second point.
* metric (``int``): Distance metric to be used. Available options: [0 (Euclidean), 1 (Manhattan), 2 (Minkowski)]
* p (``float``): Parameter for the Minkowski distance (used only if `metric` is "minkowski").

**Returns:**

* Distance (``double``) between the two points with the selected metric.

---
Expand All @@ -130,14 +135,15 @@ def min_distance_to_class_vectors(

Calculates the minimum distance between an input vector and the vectors of a class.


**Parameters:**

* x_class (``npt.NDArray``): Array containing the class vectors to be compared with the input vector. Expected shape: (n_samples, n_features).
* vector_x (``npt.NDArray``): Vector to be compared with the class vectors. Expected shape: (n_features,).
* metric (``int``): Distance metric to be used. Available options: [0 (Euclidean), 1 (Manhattan), 2 (Minkowski)]
* p (``float``): Parameter for the Minkowski distance (used only if `metric` is "minkowski").

**Returns:**

* float: The minimum distance calculated between the input vector and the class vectors.
* Returns -1.0 if the input dimensions are incompatible.

Expand All @@ -148,16 +154,19 @@ Calculates the minimum distance between an input vector and the vectors of a cla
```python
def get_metric_code(metric: str) -> int:
```

Returns the numeric code associated with a distance metric.

**Parameters:**

* metric (str): Name of the metric. Can be "euclidean", "manhattan", "minkowski" or "hamming".

**Raises**
----------

* ``ValueError``: If the metric provided is not supported

**Returns:**

* ``int``: Numeric code corresponding to the metric.

---
---
5 changes: 4 additions & 1 deletion docs/advanced-guides/Utils/Metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ Function to calculate precision accuracy based on lists of true labels and
predicted labels.

**Parameters**:

* **_y_true_** (``Union[npt.NDArray, list]``): Ground truth (correct) labels.
Expected to be of the same length as `y_pred`.
* **_y_pred_** (``Union[npt.NDArray, list]``): Predicted labels. Expected to
be of the same length as `y_true`.

Returns:

* **_Accuracy_** (``float``): The ratio of correct predictions to the total
number of predictions.

**Raises**:

* `ValueError`: If `y_true` or `y_pred` are empty or if they do not have the same length.

---
---
2 changes: 2 additions & 0 deletions docs/advanced-guides/Utils/Multiclass.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ according to the output class, to loop through the sample array, only in positio
the output is the class being trained.

**Parameters**:

* ***classes*** (``list or npt.NDArray``): list with unique classes.
* ***y*** (npt.NDArray): Receives a ``y``[``N sample``] array with the output classes of the ``X`` sample array.

**returns**:

* dict: A dictionary with the list of array positions(``y``), with the classes as key.
13 changes: 8 additions & 5 deletions docs/advanced-guides/Utils/Sanitizers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def sanitize_choice(value: T, valid_choices: Iterable[T], default: T) -> T

The function ``sanitize_choice(...)``, returns the value if it is present in the set of valid choices; otherwise, returns the default value.


**Parameters:**

* ***value*** (``T``): The value to be checked.
* ***valid_choices*** (``Iterable[T]``): A collection of valid choices.
* ***default***: The default value to be returned if ``value`` is not in ``valid_choices``.


**Returns:**

* `T`: The original value if valid, or the default value if not.

---
Expand All @@ -35,12 +35,13 @@ def sanitize_param(value: T, default: T, condition: Callable[[T], bool]) -> T:
The function ``sanitize_param(...)``, returns the value if it satisfies the specified condition; otherwise, returns the default value.

**Parameters:**

* value (``T``): The value to be checked.
* default (``T``): The default value to be returned if the condition is not satisfied.
* condition (``Callable[[T], bool]``): A function that takes a value and returns a boolean, determining if the value is valid.


**Returns:**

* `T`: The original value if the condition is satisfied, or the default value if not.

---
Expand All @@ -54,9 +55,11 @@ def sanitize_seed(seed: Any) -> Optional[int]:
The function ``sanitize_param(...)``, returns the seed if it is a non-negative integer; otherwise, returns None.

**Parameters:**

* seed (``Any``): The seed value to be validated.

**Returns:**

* ``Optional[int]``: The original seed if it is a non-negative integer, or ``None`` if it is invalid.

---
Expand All @@ -73,10 +76,10 @@ def sanitize_bounds(
The function ``sanitize_bounds(...)``, validate and normalize feature bounds.

**Parameters:**

* ***bounds*** (``Any``): he input bounds, which must be either None or a dictionary with 'low' and 'high' keys.
* ***problem_size*** (``int``): The expected length for the normalized bounds lists, corresponding to the number of features in the problem.


**Returns:**
* `Dict[str, list]`: Dictionary ``{'low': [low_1, ..., low_N], 'high': [high_1, ..., high_N]}``.

* `Dict[str, list]`: Dictionary ``{'low': [low_1, ..., low_N], 'high': [high_1, ..., high_N]}``.
4 changes: 3 additions & 1 deletion docs/advanced-guides/Utils/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ This function analyzes the input vector and classifies its data as one of the su
* `vector` (`npt.NDArray`): An array containing the data to be classified.

**Returns**

* `FeatureType` (`Literal["binary-features", "continuous-features", "ranged-features"]`): The detected type of data in the vector.

**Raises**
* `UnsupportedDataTypeError`: Raised if the vector contains an unsupported data type.

* `UnsupportedDataTypeError`: Raised if the vector contains an unsupported data type.
Loading