artlib.topological.TopoART ========================== .. py:module:: artlib.topological.TopoART .. autoapi-nested-parse:: Topo ART :cite:`tscherepanow2010topoart`. Classes ------- .. autoapisummary:: artlib.topological.TopoART.TopoART Module Contents --------------- .. py:class:: TopoART(base_module: artlib.common.BaseART.BaseART, beta_lower: float, tau: int, phi: int) Bases: :py:obj:`artlib.common.BaseART.BaseART` Topo ART for Topological Clustering. This module implements Topo ART as first published in: :cite:`tscherepanow2010topoart`. .. # Tscherepanow, M. (2010). .. # TopoART: A Topology Learning Hierarchical ART Network. .. # In K. Diamantaras, W. Duch, & L. S. Iliadis (Eds.), .. # Artificial Neural Networks – ICANN 2010 (pp. 157–167). .. # Berlin, Heidelberg: Springer Berlin Heidelberg. .. # doi:10.1007/978-3-642-15825-4_21. Topo ART clusters accepts an instantiated :class:`~artlib.common.BaseART.BaseART` module and generates a topological clustering by recording the first and second resonant cluster relationships in an adjacency matrix. Further, it updates the second resonant cluster with a lower learning rate than the first, providing for a distributed learning model. .. py:attribute:: base_module .. py:attribute:: adjacency .. py:attribute:: _permanent_mask .. py:method:: validate_params(params: dict) :staticmethod: Validate clustering parameters. :param params: A dictionary containing parameters for the algorithm. :type params: dict :raises AssertionError: If the required parameters are not provided or are invalid. .. py:property:: W :type: List[numpy.ndarray] Get the weight matrix of the base module. :returns: The weight matrix of the base ART module. :rtype: list[np.ndarray] .. py:method:: validate_data(X: numpy.ndarray) Validate the data prior to clustering. :param X: The input dataset. :type X: np.ndarray .. py:method:: prepare_data(X: numpy.ndarray) -> numpy.ndarray Prepare data for clustering. :param X: The input dataset. :type X: np.ndarray :returns: Prepared (normalized) data. :rtype: np.ndarray .. py:method:: restore_data(X: numpy.ndarray) -> numpy.ndarray Restore data to the state prior to preparation. :param X: The input dataset. :type X: np.ndarray :returns: Restored data. :rtype: 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: Parameters for the algorithm. :type params: dict :returns: Cluster activation and cache used for later processing. :rtype: tuple[float, Optional[dict]] .. 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: Parameters for the algorithm. :type params: dict :param cache: Values cached from previous calculations. :type cache: dict, optional :returns: Cluster match criterion and cache used for later processing. :rtype: tuple[float, dict] .. py:method:: match_criterion_bin(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: Optional[dict] = None, op: Callable = operator.ge) -> tuple[bool, dict] Get the binary 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: Parameters for the algorithm. :type params: dict :param cache: Values cached from previous calculations. :type cache: dict, optional :param op: Comparison operator to use for the binary match criterion. :type op: Callable, default=operator.ge :returns: Binary match criterion and cache used for later processing. :rtype: tuple[bool, dict] .. py:method:: update(i: numpy.ndarray, w: numpy.ndarray, params: dict, cache: Optional[dict] = None) -> numpy.ndarray Update the cluster weight. :param i: Data sample. :type i: np.ndarray :param w: Cluster weight or information. :type w: np.ndarray :param params: Parameters for the algorithm. :type params: dict :param cache: Values cached 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: Parameters for the algorithm. :type params: dict :returns: Newly generated cluster weight. :rtype: np.ndarray .. py:method:: add_weight(new_w: numpy.ndarray) Add a new cluster weight. :param new_w: New cluster weight to add. :type new_w: np.ndarray .. py:method:: prune(X: numpy.ndarray) Prune clusters based on the number of associated samples. :param X: The input dataset. :type X: np.ndarray .. py:method:: post_step_fit(X: numpy.ndarray) Perform post-fit operations, such as cluster pruning, after fitting each sample. :param X: The input dataset. :type X: np.ndarray .. py:method:: _match_tracking(cache: Union[List[Dict], Dict], epsilon: float, params: Union[List[Dict], Dict], method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) -> bool Adjust the vigilance parameter based on match tracking methods. :param cache: Cached values from previous calculations. :type cache: dict :param epsilon: Adjustment factor for the vigilance parameter. :type epsilon: float :param params: Parameters for the algorithm. :type params: dict :param method: Method to use for match tracking. :type method: Literal["MT+", "MT-", "MT0", "MT1", "MT~"] :returns: True if the match tracking continues, False otherwise. :rtype: bool .. py:method:: _set_params(new_params) Set new parameters for the base module. :param new_params: New parameters to set. :type new_params: dict .. py:method:: _deep_copy_params() -> dict Create a deep copy of the parameters. :returns: Deep copy of the parameters. :rtype: dict .. py:method:: step_fit(x: numpy.ndarray, match_reset_func: Optional[Callable] = None, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0) -> int Fit the model to a single sample. :param x: Data sample. :type x: np.ndarray :param match_reset_func: Function to reset the match based on custom criteria. :type match_reset_func: Callable, optional :param match_tracking: Method to reset the match. :type match_tracking: Literal["MT+", "MT-", "MT0", "MT1", "MT~"], default="MT+" :param epsilon: Adjustment factor for vigilance. :type epsilon: float, default=0.0 :returns: Cluster label of the input sample. :rtype: int .. py:method:: get_cluster_centers() -> List[numpy.ndarray] Get the centers of each cluster. :returns: Cluster centroids. :rtype: List[np.ndarray] .. py:method:: plot_cluster_bounds(ax: matplotlib.axes.Axes, colors: artlib.common.utils.IndexableOrKeyable, linewidth: int = 1) Visualize the boundaries of each cluster. :param ax: Figure axes. :type ax: Axes :param colors: Colors to use for each cluster. :type colors: IndexableOrKeyable :param linewidth: Width of boundary lines. :type linewidth: int, default=1