artlib.cvi.CVIART

CVIART.

Classes

CVIART

CVI Art Classification.

Module Contents

class artlib.cvi.CVIART.CVIART(base_module: artlib.common.BaseART.BaseART, validity: int)

Bases: artlib.common.BaseART.BaseART

CVI Art Classification.

Expanded version of Art that uses Cluster Validity Indicies to help with cluster selection. PBM is not implemented, can be seen here. git.mst.edu/acil-group/CVI-Fuzzy-ART/-/blob/master/PBM_index.m?ref_type=heads

Note, the default step_fit function in base ART evaluates the matching function even if the other criteria has failed. This means it could run slower then it would otherwise.

CALINSKIHARABASZ = 1
DAVIESBOULDIN = 2
SILHOUETTE = 3
base_module
validate_params(params: dict)

Validate clustering parameters.

Parameters:

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

prepare_data(X: numpy.ndarray) numpy.ndarray

Prepare data for clustering.

Parameters:

X (np.ndarray) – Dataset to be normalized.

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) – Dataset to be restored.

Returns:

Restored data.

Return type:

np.ndarray

property W: List

Get the base module weights.

Returns:

base module weights

Return type:

list of np.ndarray

property labels_: numpy.ndarray

Get the base module labels.

Returns:

base module labels

Return type:

np.ndarray

CVI_match(x, w, c_, params, extra, cache)

Evaluate the cluster validity index (CVI) for a match.

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

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

  • c (int) – Cluster index.

  • params (dict) – Parameters for the algorithm.

  • extra (dict) – Extra information including index and validity type.

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

Returns:

True if the new validity score improves the clustering, False otherwise.

Return type:

bool

_match_tracking(cache: dict, epsilon: float, params: dict, method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) bool

Adjust the vigilance parameter (rho) based on the match tracking method.

Parameters:
  • cache (dict) – Cache containing match criterion.

  • epsilon (float) – Epsilon value for adjusting the vigilance parameter.

  • params (dict) – Parameters for the algorithm.

  • method ({"MT+", "MT-", "MT0", "MT1", "MT~"}) – Method for resetting match criterion.

Returns:

True if further matching is required, False otherwise.

Return type:

bool

_set_params(new_params)
_deep_copy_params() dict
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)

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 accepting the data sample, a cluster weight, the params dict, and the cache dict. Returns True if the cluster is valid for the sample, False otherwise.

  • max_iter (int, optional) – Number of iterations to fit the model on the same dataset, by default 1.

  • match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, optional) – Method for resetting match criterion.

  • epsilon (float, optional) – Epsilon value used for adjusting match criterion, by default 0.0.

pre_step_fit(X: numpy.ndarray)

Preprocessing step before fitting each sample.

Parameters:

X (np.ndarray) – The dataset.

post_step_fit(X: numpy.ndarray)

Postprocessing step after fitting each sample.

Parameters:

X (np.ndarray) – The dataset.

abstract 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 accepting the data sample, a cluster weight, the params dict, and the cache dict. Returns True if the cluster is valid for the sample, False otherwise.

  • match_tracking ({"MT+", "MT-", "MT0", "MT1", "MT~"}, optional) – Method for resetting match criterion.

  • epsilon (float, optional) – Epsilon value used for adjusting match criterion, by default 0.0.

Returns:

Cluster label of the input sample.

Return type:

int

step_pred(x: numpy.ndarray) int

Predict the label for a single sample.

Parameters:

x (np.ndarray) – Data sample.

Returns:

Cluster label of the input sample.

Return type:

int

get_cluster_centers() List[numpy.ndarray]

Get the centers of the clusters.

Returns:

Cluster centroids.

Return type:

list of np.ndarray

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

Plot the boundaries 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.