artlib.elementary.FuzzyART

Fuzzy ART [8].

Classes

FuzzyART

Fuzzy ART for Clustering.

Functions

get_bounding_box(→ tuple[list[int], list[int]])

Extract the bounding boxes from a FuzzyART weight.

_category_choice_numba(→ float)

Compute the category choice (activation) using Numba optimization.

_match_criterion_numba(→ float)

Compute the match criterion using Numba optimization.

_update_numba(→ numpy.ndarray)

Compute the updated cluster weight using Numba optimization.

Module Contents

artlib.elementary.FuzzyART.get_bounding_box(w: numpy.ndarray, n: int | None = None) tuple[list[int], list[int]]

Extract the bounding boxes from a FuzzyART weight.

Parameters:
  • w (np.ndarray) – A fuzzy ART weight.

  • n (int, optional) – Dimensions of the bounding box.

Returns:

A tuple containing the reference point and lengths of each edge.

Return type:

tuple

artlib.elementary.FuzzyART._category_choice_numba(i: numpy.ndarray, w: numpy.ndarray, alpha: float) float

Compute the category choice (activation) using Numba optimization.

Parameters:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • alpha (float) – Choice parameter for the algorithm.

Returns:

Computed cluster activation value.

Return type:

float

artlib.elementary.FuzzyART._match_criterion_numba(i: numpy.ndarray, w: numpy.ndarray, dim_original: float) float

Compute the match criterion using Numba optimization.

Parameters:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • dim_original (float) – Original number of features before complement coding.

Returns:

Computed match criterion.

Return type:

float

artlib.elementary.FuzzyART._update_numba(i: numpy.ndarray, w: numpy.ndarray, b: float | None) numpy.ndarray

Compute the updated cluster weight using Numba optimization.

Parameters:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • b (float, optional) – Learning rate parameter (beta). If None, only the fuzzy AND operation is applied.

Returns:

Updated cluster weight.

Return type:

np.ndarray

class artlib.elementary.FuzzyART.FuzzyART(rho: float, alpha: float, beta: float)

Bases: artlib.common.BaseART.BaseART

Fuzzy ART for Clustering.

This module implements Fuzzy ART as first published in: [8].

Fuzzy ART is a hyper-box based clustering method that is exceptionally fast and explainable.

prepare_data(X: numpy.ndarray) numpy.ndarray

Prepare data for clustering.

Parameters:

X (np.ndarray) – Dataset.

Returns:

Normalized and complement coded data.

Return type:

np.ndarray

restore_data(X: numpy.ndarray) numpy.ndarray

Restore data to its state prior to preparation.

Parameters:

X (np.ndarray) – Dataset.

Returns:

Restored data.

Return type:

np.ndarray

static validate_params(params: dict)

Validate clustering parameters.

Parameters:

params (dict) – Dictionary containing parameters for the algorithm.

check_dimensions(X: numpy.ndarray)

Check that the data has the correct dimensions.

Parameters:

X (np.ndarray) – Dataset.

validate_data(X: numpy.ndarray)

Validate the data prior to clustering.

Parameters:

X (np.ndarray) – Dataset.

category_choice(i: numpy.ndarray, w: numpy.ndarray, params: dict) tuple[float, dict | None]

Get the activation of the cluster.

Parameters:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • params (dict) – Dictionary containing parameters for the algorithm.

Returns:

  • float – Cluster activation.

  • dict, optional – Cache used for later processing.

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:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • params (dict) – Dictionary containing parameters for the algorithm.

  • cache (dict, optional) – Cache containing values from previous calculations.

Returns:

  • float – Cluster match criterion.

  • dict – Cache used for later processing.

update(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: dict | None = None) numpy.ndarray

Get the updated cluster weight.

Parameters:
  • i (np.ndarray) – Data sample.

  • w (np.ndarray) – Cluster weight or information.

  • params (dict) – Dictionary containing parameters for the algorithm.

  • cache (dict, optional) – Cache containing values from previous calculations.

Returns:

Updated cluster weight.

Return type:

np.ndarray

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:

New cluster weight.

Return type:

np.ndarray

get_bounding_boxes(n: int | None = None) List[tuple[list[int], list[int]]]

Get the bounding boxes for each cluster.

Parameters:

n (int, optional) – Dimensions of the bounding box.

Returns:

List of bounding boxes.

Return type:

list

get_cluster_centers() List[numpy.ndarray]

Get the centers of each cluster, used for regression.

Returns:

Cluster centroids.

Return type:

list of np.ndarray

shrink_clusters(shrink_ratio: float = 0.1)

Shrink the clusters by adjusting the bounding box.

Parameters:

shrink_ratio (float, optional) – The ratio by which to shrink the clusters, by default 0.1.

Returns:

Self after shrinking the clusters.

Return type:

FuzzyART

plot_cluster_bounds(ax: matplotlib.axes.Axes, colors: Iterable, linewidth: int = 1)

Visualize the bounds of each cluster.

Parameters:
  • ax (matplotlib.axes.Axes) – Figure axes.

  • colors (IndexableOrKeyable) – Colors to use for each cluster.

  • linewidth (int, optional) – Width of boundary line, by default 1.