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
11 changes: 9 additions & 2 deletions aisp/base/core/_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class BaseClassifier(ABC, Base):
This class defines the core interface for classification models. It enforces the
implementation of the ``fit`` and ``predict`` methods in all derived classes,
and provides a default implementation of ``score`` and utility functions.

Attributes
----------
classes : Optional[npt.NDArray]
Class labels identified during training.
_n_features : int
The number of features of the data.
"""

classes: Optional[npt.NDArray] = None
Expand Down Expand Up @@ -64,7 +71,7 @@ def predict(self, X: Union[npt.NDArray, list]) -> npt.NDArray:

Returns
-------
Predictions : Optional[npt.NDArray]
predictions : npt.NDArray
Predicted values for each input sample.
"""

Expand Down Expand Up @@ -113,7 +120,7 @@ def _slice_index_list_by_class(self, y: npt.NDArray) -> dict:

Returns
-------
dict: dict
indices_by_class : dict
A dictionary with the list of array positions(``y``), with the classes as key.
"""
return slice_index_list_by_class(self.classes, y)
24 changes: 23 additions & 1 deletion aisp/base/core/_clusterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Union
from typing import Optional, Union
from warnings import warn

import numpy.typing as npt

Expand All @@ -16,8 +17,29 @@ class BaseClusterer(ABC, Base):
This class defines the core interface for clustering models. It enforces
the implementation of the `fit` and `predict` methods in all derived classes,
and provides a default implementation for `fit_predict` and `get_params`.

Attributes
----------
labels : Optional[npt.NDArray]
Labels for the clusters generated during model fitting.
"""

labels: Optional[npt.NDArray] = None

@property
def classes(self) -> Optional[npt.NDArray]:
"""Deprecated alias kept for backward compatibility.

Use `labels` instead of `classes`.
"""
warn(
"The `classes` attribute is deprecated and will be removed in future "
"versions. Use labels instead.",
FutureWarning,
2
)
return self.labels

@abstractmethod
def fit(self, X: Union[npt.NDArray, list], verbose: bool = True) -> BaseClusterer:
"""
Expand Down
19 changes: 17 additions & 2 deletions aisp/base/core/_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class BaseOptimizer(ABC, Base):
This class defines the core interface for optimization strategies. It keeps track of cost
history, evaluated solutions, and the best solution found during the optimization process.
Subclasses must implement ``optimize`` and ``affinity_function``.

Attributes
----------
cost_history : List[float]
History of best costs found at each iteration.
solution_history : List
History of the best solution found at each iteration.
best_solution : Any
The best solution found.
best_cost : Optional[float]
Cost of the best solution found.
mode : {"min", "max"}, default="min"
Defines whether the algorithm minimizes or maximizes the cost function.
"""

def __init__(self) -> None:
Expand Down Expand Up @@ -57,6 +70,8 @@ def _record_best(self, cost: float, best_solution: Any) -> None:
----------
cost : float
Cost value to be added to the history.
best_solution : Any
The best solution associated with the given cost.
"""
self._solution_history.append(best_solution)
self._cost_history.append(cost)
Expand Down Expand Up @@ -128,9 +143,9 @@ def optimize(

Parameters
----------
max_iters : int
max_iters : int, default=50
Maximum number of iterations
n_iter_no_change: int, default=10
n_iter_no_change : int, default=10
the maximum number of iterations without updating the best
verbose : bool, default=True
Flag to enable or disable detailed output during optimization.
Expand Down
2 changes: 1 addition & 1 deletion aisp/base/immune/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def hyper_clonal_mutate(
----------
n : int
Number of clones to be generated from mutations of the original cell.
feature_type : Literal["binary-features", "continuous-features", "ranged-features"]
feature_type : { "binary-features", "continuous-features", "ranged-features" }
Specifies the type of feature_type to use based on the nature of the input features
bounds : npt.NDArray[np.float64], optional
Array (n_features, 2) with min and max per dimension.
Expand Down
Loading