artlib.common.BaseART ===================== .. py:module:: artlib.common.BaseART .. autoapi-nested-parse:: Base class for all ART objects. Classes ------- .. autoapisummary:: artlib.common.BaseART.BaseART Module Contents --------------- .. py:class:: BaseART(params: Dict) Bases: :py:obj:`sklearn.base.BaseEstimator`, :py:obj:`sklearn.base.ClusterMixin` Generic implementation of Adaptive Resonance Theory (ART) .. py:attribute:: data_format :value: 'default' .. py:attribute:: params .. py:attribute:: sample_counter_ :value: 0 .. py:attribute:: weight_sample_counter_ :type: List[int] :value: [] .. py:attribute:: d_min_ :value: None .. py:attribute:: d_max_ :value: None .. py:attribute:: is_fitted_ :value: False .. py:attribute:: labels_ .. py:method:: __getattr__(key) .. py:method:: __setattr__(key, value) .. py:method:: get_params(deep: bool = True) -> Dict :param deep: If True, will return the parameters for this class and contained subobjects that are estimators. :type deep: bool, default=True :returns: Parameter names mapped to their values. :rtype: dict .. py:method:: set_params(**params) Set the parameters of this estimator. Specific redefinition of `sklearn.BaseEstimator.set_params` for ART classes. :param \*\*params: Estimator parameters. :type \*\*params: dict :returns: **self** -- Estimator instance. :rtype: object .. py:method:: set_data_bounds(lower_bounds: numpy.ndarray, upper_bounds: numpy.ndarray) Manually set the data bounds for normalization. :param lower_bounds: The lower bounds for each column. :type lower_bounds: np.ndarray :param upper_bounds: The upper bounds for each column. :type upper_bounds: np.ndarray .. py:method:: find_data_bounds(*data_batches: list[numpy.ndarray]) -> Tuple[numpy.ndarray, numpy.ndarray] Automatically find the data bounds for normalization from a list of data batches. :param \*data_batches: Batches of data to be presented to the model :type \*data_batches: list[np.ndarray] :returns: Lower and upper bounds for data. :rtype: tuple[np.ndarray, np.ndarray] .. py:method:: prepare_data(X: numpy.ndarray) -> numpy.ndarray Prepare data for clustering. :param X: The dataset. :type X: np.ndarray :returns: Normalized data. :rtype: np.ndarray .. py:method:: restore_data(X: numpy.ndarray) -> numpy.ndarray Restore data to state prior to preparation. :param X: The dataset. :type X: np.ndarray :returns: Restored data. :rtype: np.ndarray .. py:property:: n_clusters :type: int Get the current number of clusters. :returns: The number of clusters. :rtype: int .. py:method:: validate_params(params: Dict) :staticmethod: :abstractmethod: Validate clustering parameters. :param params: Dictionary containing parameters for the algorithm. :type params: dict .. py:method:: check_dimensions(X: numpy.ndarray) Check the data has the correct dimensions. :param X: The dataset. :type X: np.ndarray .. py:method:: validate_data(X: numpy.ndarray) Validates the data prior to clustering. Parameters: - X: data set .. py:method:: category_choice(i: numpy.ndarray, w: numpy.ndarray, params: Dict) -> Tuple[float, Optional[Dict]] :abstractmethod: 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: Cluster activation and cache used for later processing. :rtype: tuple .. py:method:: match_criterion(i: numpy.ndarray, w: numpy.ndarray, params: Dict, cache: Optional[Dict] = None) -> Tuple[float, Optional[Dict]] :abstractmethod: 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: Cluster match criterion and cache used for later processing. :rtype: tuple .. 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: Dictionary containing parameters for the algorithm. :type params: dict :param cache: Cache containing values from previous calculations. :type cache: dict, optional :returns: Binary match criterion and cache used for later processing. :rtype: tuple .. py:method:: update(i: numpy.ndarray, w: numpy.ndarray, params: Dict, cache: Optional[Dict] = None) -> numpy.ndarray :abstractmethod: 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 :abstractmethod: 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: Updated 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:: set_weight(idx: int, new_w: numpy.ndarray) Set the value of a cluster weight. :param idx: Index of cluster to update. :type idx: int :param new_w: New cluster weight. :type new_w: 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 Perform match tracking using the specified method. :param cache: Cached match criterion value. :type cache: dict :param epsilon: Small adjustment factor for match tracking. :type epsilon: float :param params: Parameters :type params: dict :param method: Match tracking method to apply. :type method: Literal["MT+", "MT-", "MT0", "MT1", "MT~"] :returns: Whether to continue searching for a match. :rtype: bool .. py:method:: _match_tracking_operator(method: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~']) -> Callable :staticmethod: .. py:method:: _set_params(new_params) .. py:method:: _deep_copy_params() -> 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: A callable that influences cluster creation. :type match_reset_func: callable, optional :param match_tracking: Method for resetting match criterion. :type match_tracking: {"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+" :param epsilon: Epsilon value used for adjusting match criterion. :type epsilon: float, default=0.0 :returns: Cluster label of the input sample. :rtype: int .. py:method:: step_pred(x) -> int Predict the label for a single sample. :param x: Data sample. :type x: np.ndarray :returns: Cluster label of the input sample. :rtype: int .. py:method:: pre_step_fit(X: numpy.ndarray) Undefined function called prior to each sample fit. Useful for cluster pruning. :param X: The dataset. :type X: np.ndarray .. py:method:: post_step_fit(X: numpy.ndarray) Undefined function called after each sample fit. Useful for cluster pruning. :param X: The dataset. :type X: np.ndarray .. py:method:: post_fit(X: numpy.ndarray) Undefined function called after fit. Useful for cluster pruning. :param X: The dataset. :type X: np.ndarray .. py:method:: fit(X: numpy.ndarray, y: Optional[numpy.ndarray] = None, match_reset_func: Optional[Callable] = None, max_iter=1, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0, verbose: bool = False, leave_progress_bar: bool = True) Fit the model to the data. :param X: The dataset. :type X: np.ndarray :param y: Not used. For compatibility. :type y: np.ndarray, optional :param match_reset_func: A callable that influences cluster creation. :type match_reset_func: callable, optional :param max_iter: Number of iterations to fit the model on the same dataset. :type max_iter: int, default=1 :param match_tracking: Method for resetting match criterion. :type match_tracking: {"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+" :param epsilon: Epsilon value used for adjusting match criterion. :type epsilon: float, default=0.0 :param verbose: If True, displays progress of the fitting process. :type verbose: bool, default=False :param leave_progress_bar: If True, leaves thge progress of the fitting process. Only used when verbose=True :type leave_progress_bar: bool, default=True .. py:method:: partial_fit(X: numpy.ndarray, match_reset_func: Optional[Callable] = None, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0) Iteratively fit the model to the data. :param X: The dataset. :type X: np.ndarray :param match_reset_func: A callable that influences cluster creation. :type match_reset_func: callable, optional :param match_tracking: Method for resetting match criterion. :type match_tracking: {"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+" :param epsilon: Epsilon value used for adjusting match criterion. :type epsilon: float, default=0.0 .. py:method:: fit_gif(X: numpy.ndarray, y: Optional[numpy.ndarray] = None, match_reset_func: Optional[Callable] = None, max_iter=1, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+', epsilon: float = 0.0, verbose: bool = False, leave_progress_bar: bool = True, ax: Optional[matplotlib.axes.Axes] = None, filename: Optional[str] = None, colors: Optional[artlib.common.utils.IndexableOrKeyable] = None, n_cluster_estimate: int = 20, fps: int = 5, final_hold_secs: float = 0.0, **kwargs) Fit the model to the data and make a gif of the process. :param X: The dataset. :type X: np.ndarray :param y: Not used. For compatibility. :type y: np.ndarray, optional :param match_reset_func: A callable that influences cluster creation. :type match_reset_func: callable, optional :param max_iter: Number of iterations to fit the model on the same dataset. :type max_iter: int, default=1 :param match_tracking: Method for resetting match criterion. :type match_tracking: {"MT+", "MT-", "MT0", "MT1", "MT~"}, default="MT+" :param epsilon: Epsilon value used for adjusting match criterion. :type epsilon: float, default=0.0 :param verbose: If True, displays progress of the fitting process. :type verbose: bool, default=False :param leave_progress_bar: If True, leaves thge progress of the fitting process. Only used when verbose=True :type leave_progress_bar: bool, default=True :param ax: Figure axes. :type ax: matplotlib.axes.Axes, optional :param colors: Colors to use for each cluster. :type colors: IndexableOrKeyable, optional :param n_cluster_estimate: estimate of number of clusters. Used for coloring plot. :type n_cluster_estimate: int, default=20 :param fps: gif frames per second :type fps: int, default=5 :param final_hold_secs: seconds to hold the final frame (n_final_frames=ceil(final_hold_secs * fps)) :type final_hold_secs: float, default=0.0 :param \*\*kwargs: see :func: `artlib.common.BaseART.visualize` :type \*\*kwargs: dict .. py:method:: predict(X: numpy.ndarray, clip: bool = False) -> numpy.ndarray Predict labels for the data. :param X: The dataset. :type X: np.ndarray :param clip: clip the input values to be between the previously seen data limits :type clip: bool :returns: Labels for the data. :rtype: np.ndarray .. py:method:: shrink_clusters(shrink_ratio: float = 0.1) Shrink the clusters by a specified ratio. :param shrink_ratio: The ratio by which to shrink the clusters. Must be between 0 and 1. Default is 0.1. :type shrink_ratio: float, optional :returns: **self** -- Returns the instance with shrunken clusters. :rtype: object .. py:method:: plot_cluster_bounds(ax: matplotlib.axes.Axes, colors: artlib.common.utils.IndexableOrKeyable, linewidth: int = 1) :abstractmethod: Undefined function for visualizing 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. :type linewidth: int, default=1 .. py:method:: get_cluster_centers() -> List[numpy.ndarray] :abstractmethod: Undefined function for getting centers of each cluster. Used for regression. :returns: Cluster centroids. :rtype: list of np.ndarray .. py:method:: visualize(X: numpy.ndarray, y: numpy.ndarray, ax: Optional[matplotlib.axes.Axes] = None, marker_size: int = 10, linewidth: int = 1, colors: Optional[artlib.common.utils.IndexableOrKeyable] = None) Visualize the clustering of the data. :param X: The dataset. :type X: np.ndarray :param y: Sample labels. :type y: np.ndarray :param ax: Figure axes. :type ax: matplotlib.axes.Axes, optional :param marker_size: Size used for data points. :type marker_size: int, default=10 :param linewidth: Width of boundary line. :type linewidth: int, default=1 :param colors: Colors to use for each cluster. :type colors: IndexableOrKeyable, optional