artlib.common.BaseART
Base class for all ART objects.
Classes
Generic implementation of Adaptive Resonance Theory (ART) |
Module Contents
- class artlib.common.BaseART.BaseART(params: Dict)
Bases:
sklearn.base.BaseEstimator,sklearn.base.ClusterMixinGeneric implementation of Adaptive Resonance Theory (ART)
- data_format = 'default'
- params
- sample_counter_ = 0
- d_min_ = None
- d_max_ = None
- is_fitted_ = False
- labels_
- __getattr__(key)
- __setattr__(key, value)
- set_params(**params)
Set the parameters of this estimator.
Specific redefinition of sklearn.BaseEstimator.set_params for ART classes.
- set_data_bounds(lower_bounds: numpy.ndarray, upper_bounds: numpy.ndarray)
Manually set the data bounds for normalization.
- Parameters:
lower_bounds (np.ndarray) – The lower bounds for each column.
upper_bounds (np.ndarray) – The upper bounds for each column.
- find_data_bounds(*data_batches: list[numpy.ndarray]) Tuple[numpy.ndarray, numpy.ndarray]
Automatically find the data bounds for normalization from a list of data batches.
- prepare_data(X: numpy.ndarray) numpy.ndarray
Prepare data for clustering.
- Parameters:
X (np.ndarray) – The dataset.
- Returns:
Normalized data.
- Return type:
np.ndarray
- restore_data(X: numpy.ndarray) numpy.ndarray
Restore data to state prior to preparation.
- Parameters:
X (np.ndarray) – The dataset.
- Returns:
Restored data.
- Return type:
np.ndarray
- property n_clusters: int
Get the current number of clusters.
- Returns:
The number of clusters.
- Return type:
- static validate_params(params: Dict)
- Abstractmethod:
Validate clustering parameters.
- Parameters:
params (dict) – Dictionary containing parameters for the algorithm.
- check_dimensions(X: numpy.ndarray)
Check the data has the correct dimensions.
- Parameters:
X (np.ndarray) – The dataset.
- validate_data(X: numpy.ndarray)
Validates the data prior to clustering.
Parameters: - X: data set
- abstract category_choice(i: numpy.ndarray, w: numpy.ndarray, params: Dict) Tuple[float, Dict | None]
Get the activation of the cluster.
- abstract match_criterion(i: numpy.ndarray, w: numpy.ndarray, params: Dict, cache: Dict | None = None) Tuple[float, Dict | None]
Get the match criterion of the cluster.
- Parameters:
- Returns:
Cluster match criterion and cache used for later processing.
- Return type:
- match_criterion_bin(i: numpy.ndarray, w: numpy.ndarray, params: Dict, cache: Dict | None = None, op: Callable = operator.ge) Tuple[bool, Dict]
Get the binary match criterion of the cluster.
- Parameters:
- Returns:
Binary match criterion and cache used for later processing.
- Return type:
- abstract update(i: numpy.ndarray, w: numpy.ndarray, params: Dict, cache: Dict | None = None) numpy.ndarray
Get the updated cluster weight.
- abstract new_weight(i: numpy.ndarray, params: Dict) numpy.ndarray
Generate a new cluster weight.
- Parameters:
i (np.ndarray) – Data sample.
params (dict) – Dictionary containing parameters for the algorithm.
- Returns:
Updated cluster weight.
- Return type:
np.ndarray
- add_weight(new_w: numpy.ndarray)
Add a new cluster weight.
- Parameters:
new_w (np.ndarray) – New cluster weight to add.
- set_weight(idx: int, new_w: numpy.ndarray)
Set the value of a cluster weight.
- Parameters:
idx (int) – Index of cluster to update.
new_w (np.ndarray) – New cluster weight.
- _match_tracking(cache: List[Dict] | Dict, epsilon: float, params: List[Dict] | Dict, method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) bool
Perform match tracking using the specified method.
- Parameters:
- Returns:
Whether to continue searching for a match.
- Return type:
- static _match_tracking_operator(method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) Callable
- _set_params(new_params)
- _deep_copy_params() Dict
- step_fit(x: numpy.ndarray, match_reset_func: Callable | None = None, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0) int
Fit the model to a single sample.
- Parameters:
x (np.ndarray) – Data sample.
match_reset_func (callable, optional) – A callable that influences cluster creation.
match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+") – Method for resetting match criterion.
epsilon (float, default=0.0) – Epsilon value used for adjusting match criterion.
- Returns:
Cluster label of the input sample.
- Return type:
- step_pred(x) int
Predict the label for a single sample.
- Parameters:
x (np.ndarray) – Data sample.
- Returns:
Cluster label of the input sample.
- Return type:
- pre_step_fit(X: numpy.ndarray)
Undefined function called prior to each sample fit. Useful for cluster pruning.
- Parameters:
X (np.ndarray) – The dataset.
- post_step_fit(X: numpy.ndarray)
Undefined function called after each sample fit. Useful for cluster pruning.
- Parameters:
X (np.ndarray) – The dataset.
- post_fit(X: numpy.ndarray)
Undefined function called after fit. Useful for cluster pruning.
- Parameters:
X (np.ndarray) – The dataset.
- fit(X: numpy.ndarray, y: numpy.ndarray | None = None, match_reset_func: Callable | None = None, max_iter=1, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0, verbose: bool = False, leave_progress_bar: bool = True)
Fit the model to the data.
- Parameters:
X (np.ndarray) – The dataset.
y (np.ndarray, optional) – Not used. For compatibility.
match_reset_func (callable, optional) – A callable that influences cluster creation.
max_iter (int, default=1) – Number of iterations to fit the model on the same dataset.
match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+") – Method for resetting match criterion.
epsilon (float, default=0.0) – Epsilon value used for adjusting match criterion.
verbose (bool, default=False) – If True, displays progress of the fitting process.
leave_progress_bar (bool, default=True) – If True, leaves thge progress of the fitting process. Only used when verbose=True
- partial_fit(X: numpy.ndarray, match_reset_func: Callable | None = None, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0)
Iteratively fit the model to the data.
- Parameters:
X (np.ndarray) – The dataset.
match_reset_func (callable, optional) – A callable that influences cluster creation.
match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+") – Method for resetting match criterion.
epsilon (float, default=0.0) – Epsilon value used for adjusting match criterion.
- fit_gif(X: numpy.ndarray, y: numpy.ndarray | None = None, match_reset_func: Callable | None = None, max_iter=1, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0, verbose: bool = False, leave_progress_bar: bool = True, ax: matplotlib.axes.Axes | None = None, filename: str | None = None, colors: artlib.common.utils.IndexableOrKeyable | None = None, n_cluster_estimate: int = 20, fps: int = 5, final_hold_secs: float = 0.0, **kwargs)
Fit the model to the data and make a gif of the process.
- Parameters:
X (np.ndarray) – The dataset.
y (np.ndarray, optional) – Not used. For compatibility.
match_reset_func (callable, optional) – A callable that influences cluster creation.
max_iter (int, default=1) – Number of iterations to fit the model on the same dataset.
match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+") – Method for resetting match criterion.
epsilon (float, default=0.0) – Epsilon value used for adjusting match criterion.
verbose (bool, default=False) – If True, displays progress of the fitting process.
leave_progress_bar (bool, default=True) – If True, leaves thge progress of the fitting process. Only used when verbose=True
ax (matplotlib.axes.Axes, optional) – Figure axes.
colors (IndexableOrKeyable, optional) – Colors to use for each cluster.
n_cluster_estimate (int, default=20) – estimate of number of clusters. Used for coloring plot.
fps (int, default=5) – gif frames per second
final_hold_secs (float, default=0.0) – seconds to hold the final frame (n_final_frames=ceil(final_hold_secs * fps))
**kwargs (dict) – see :func: artlib.common.BaseART.visualize
- predict(X: numpy.ndarray, clip: bool = False) numpy.ndarray
Predict labels for the data.
- Parameters:
X (np.ndarray) – The dataset.
clip (bool) – clip the input values to be between the previously seen data limits
- Returns:
Labels for the data.
- Return type:
np.ndarray
- abstract plot_cluster_bounds(ax: matplotlib.axes.Axes, colors: artlib.common.utils.IndexableOrKeyable, linewidth: int = 1)
Undefined function for visualizing the bounds of each cluster.
- Parameters:
ax (matplotlib.axes.Axes) – Figure axes.
colors (IndexableOrKeyable) – Colors to use for each cluster.
linewidth (int, default=1) – Width of boundary line.
- abstract get_cluster_centers() List[numpy.ndarray]
Undefined function for getting centers of each cluster. Used for regression.
- Returns:
Cluster centroids.
- Return type:
list of np.ndarray