artlib.elementary.BinaryFuzzyART

Fuzzy ART [8].

Classes

BinaryFuzzyART

Fuzzy ART optimized for binary input data.

Functions

_and_popcount(i, w)

_category_choice_binary(→ Tuple[int, bool])

Optimized category choice for binary data using count_nonzero.

Module Contents

artlib.elementary.BinaryFuzzyART._and_popcount(i, w)
artlib.elementary.BinaryFuzzyART._category_choice_binary(i: numpy.ndarray, w: numpy.ndarray, pre_MT: bool, rho_int: int) Tuple[int, bool]

Optimized category choice for binary data using count_nonzero.

class artlib.elementary.BinaryFuzzyART.BinaryFuzzyART(rho: float)

Bases: artlib.elementary.FuzzyART.FuzzyART

Fuzzy ART optimized for binary input data.

w_count_cache: List[int] = []
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.

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[int, dict | None]

Get the activation of the cluster using optimized binary operations.

match_criterion(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: dict | None = None) Tuple[float, Dict | None]

Get the match criterion using optimized binary operations.

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:
  • 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:

Binary match criterion and cache used for later processing.

Return type:

tuple

set_weight(idx: int, new_w: numpy.ndarray, cache: dict | None = None)

Set the value of a cluster weight.

Parameters:
  • idx (int) – Index of cluster to update.

  • new_w (np.ndarray) – New cluster weight.

  • cache (Optional[dict]) – cache of values created during training step

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

Get the updated cluster weight using optimized binary operations.

add_weight(new_w: numpy.ndarray)

Add a new cluster weight.

Parameters:

new_w (np.ndarray) – New cluster weight to add.

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:

int

_match_tracking_integer(cache: List[Dict] | Dict, epsilon: int, params: List[Dict] | Dict, method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) bool

Perform match tracking using the specified method.

Parameters:
  • cache (dict) – Cached match criterion value.

  • epsilon (float) – Small adjustment factor for match tracking.

  • params (dict) – Parameters

  • method (Literal["MT+", "MT-", "MT0", "MT1", "MT~"]) – Match tracking method to apply.

Returns:

Whether to continue searching for a match.

Return type:

bool

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. Rounded up to nearest int

Returns:

Cluster label of the input sample.

Return type:

int