artlib.elementary.FuzzyART ========================== .. py:module:: artlib.elementary.FuzzyART .. autoapi-nested-parse:: Fuzzy ART :cite:`carpenter1991fuzzy`. Classes ------- .. autoapisummary:: artlib.elementary.FuzzyART.FuzzyART Functions --------- .. autoapisummary:: artlib.elementary.FuzzyART.get_bounding_box artlib.elementary.FuzzyART._category_choice_numba artlib.elementary.FuzzyART._match_criterion_numba artlib.elementary.FuzzyART._update_numba Module Contents --------------- .. py:function:: get_bounding_box(w: numpy.ndarray, n: Optional[int] = None) -> tuple[list[int], list[int]] Extract the bounding boxes from a FuzzyART weight. :param w: A fuzzy ART weight. :type w: np.ndarray :param n: Dimensions of the bounding box. :type n: int, optional :returns: A tuple containing the reference point and lengths of each edge. :rtype: tuple .. py:function:: _category_choice_numba(i: numpy.ndarray, w: numpy.ndarray, alpha: float) -> float Compute the category choice (activation) using Numba optimization. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param alpha: Choice parameter for the algorithm. :type alpha: float :returns: Computed cluster activation value. :rtype: float .. py:function:: _match_criterion_numba(i: numpy.ndarray, w: numpy.ndarray, dim_original: float) -> float Compute the match criterion using Numba optimization. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param dim_original: Original number of features before complement coding. :type dim_original: float :returns: Computed match criterion. :rtype: float .. py:function:: _update_numba(i: numpy.ndarray, w: numpy.ndarray, b: Optional[float]) -> numpy.ndarray Compute the updated cluster weight using Numba optimization. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param b: Learning rate parameter (beta). If None, only the fuzzy AND operation is applied. :type b: float, optional :returns: Updated cluster weight. :rtype: np.ndarray .. py:class:: FuzzyART(rho: float, alpha: float, beta: float) Bases: :py:obj:`artlib.common.BaseART.BaseART` Fuzzy ART for Clustering. This module implements Fuzzy ART as first published in: :cite:`carpenter1991fuzzy`. .. # Carpenter, G. A., Grossberg, S., & Rosen, D. B. (1991c). .. # Fuzzy ART: Fast stable learning and categorization of analog patterns by an .. # adaptive resonance system. .. # Neural Networks, 4, 759 – 771. doi:10.1016/0893-6080(91)90056-B. Fuzzy ART is a hyper-box based clustering method that is exceptionally fast and explainable. .. py:method:: prepare_data(X: numpy.ndarray) -> numpy.ndarray Prepare data for clustering. :param X: Dataset. :type X: np.ndarray :returns: Normalized and complement coded data. :rtype: np.ndarray .. py:method:: restore_data(X: numpy.ndarray) -> numpy.ndarray Restore data to its state prior to preparation. :param X: Dataset. :type X: np.ndarray :returns: Restored data. :rtype: np.ndarray .. py:method:: validate_params(params: dict) :staticmethod: Validate clustering parameters. :param params: Dictionary containing parameters for the algorithm. :type params: dict .. py:method:: check_dimensions(X: numpy.ndarray) Check that the data has the correct dimensions. :param X: Dataset. :type X: np.ndarray .. py:method:: validate_data(X: numpy.ndarray) Validate the data prior to clustering. :param X: Dataset. :type X: np.ndarray .. py:method:: category_choice(i: numpy.ndarray, w: numpy.ndarray, params: dict) -> tuple[float, Optional[dict]] Get the activation of the cluster. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param params: Dictionary containing parameters for the algorithm. :type params: dict :returns: * *float* -- Cluster activation. * *dict, optional* -- Cache used for later processing. .. py:method:: match_criterion(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: Optional[dict] = None) -> Tuple[float, Optional[Dict]] Get the match criterion of the cluster. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param params: Dictionary containing parameters for the algorithm. :type params: dict :param cache: Cache containing values from previous calculations. :type cache: dict, optional :returns: * *float* -- Cluster match criterion. * *dict* -- Cache used for later processing. .. py:method:: update(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: Optional[dict] = None) -> numpy.ndarray Get the updated cluster weight. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param params: Dictionary containing parameters for the algorithm. :type params: dict :param cache: Cache containing values from previous calculations. :type cache: dict, optional :returns: Updated cluster weight. :rtype: np.ndarray .. py:method:: new_weight(i: numpy.ndarray, params: dict) -> numpy.ndarray Generate a new cluster weight. :param i: Data sample. :type i: np.ndarray :param params: Dictionary containing parameters for the algorithm. :type params: dict :returns: New cluster weight. :rtype: np.ndarray .. py:method:: get_bounding_boxes(n: Optional[int] = None) -> List[tuple[list[int], list[int]]] Get the bounding boxes for each cluster. :param n: Dimensions of the bounding box. :type n: int, optional :returns: List of bounding boxes. :rtype: list .. py:method:: get_cluster_centers() -> List[numpy.ndarray] Get the centers of each cluster, used for regression. :returns: Cluster centroids. :rtype: list of np.ndarray .. py:method:: shrink_clusters(shrink_ratio: float = 0.1) Shrink the clusters by adjusting the bounding box. :param shrink_ratio: The ratio by which to shrink the clusters, by default 0.1. :type shrink_ratio: float, optional :returns: Self after shrinking the clusters. :rtype: FuzzyART .. py:method:: plot_cluster_bounds(ax: matplotlib.axes.Axes, colors: Iterable, linewidth: int = 1) Visualize the bounds of each cluster. :param ax: Figure axes. :type ax: matplotlib.axes.Axes :param colors: Colors to use for each cluster. :type colors: IndexableOrKeyable :param linewidth: Width of boundary line, by default 1. :type linewidth: int, optional