### ROCK Algorithm Initialization and Processing Example Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dec/rock_8py_source.html Demonstrates how to initialize and run the ROCK clustering algorithm on a sample dataset. It includes reading data, creating the ROCK instance, processing the data, and visualizing the results. Ensure pyclustering is installed and sample data is accessible. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.rock import rock from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample # Read sample for clustering from file. sample = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA) # Create instance of ROCK algorithm for cluster analysis. Seven clusters should be allocated. rock_instance = rock(sample, 1.0, 7) # Run cluster analysis. rock_instance.process() # Obtain results of clustering. clusters = rock_instance.get_clusters() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### K-Medians Constructor and Usage Example Source: https://pyclustering.github.io/docs/0.10.1/html/df/d68/classpyclustering_1_1cluster_1_1kmedians_1_1kmedians.html Demonstrates how to initialize and use the K-Medians algorithm. It requires data points, initial medians, and optionally a tolerance. The example also shows how to visualize the clustering results. ```python from pyclustering.cluster.kmedians import kmedians from pyclustering.cluster import cluster_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import FCPS_SAMPLES data = read_sample(FCPS_SAMPLES.TWO_GAUSSIANS) initial_medians = [data[0], data[100]] kmedians_instance = kmedians(data, initial_medians) kmedians_instance.process() clusters = kmedians_instance.get_clusters() medians = kmedians_instance.get_medians() visualizer = cluster_visualizer() visualizer.append_clusters(clusters, data) visualizer.show() ``` -------------------------------- ### SOM-SC Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/dc/dc3/somsc_8py_source.html Demonstrates how to load data, initialize and process the SOM-SC algorithm, and visualize the clustering results. Ensure pyclustering is installed and sample data is accessible. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.somsc import somsc from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample # Load list of points for cluster analysis sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) # Create instance of SOM-SC algorithm to allocated two clusters somsc_instance = somsc(sample, 2) # Run cluster analysis and obtain results somsc_instance.process() clusters = somsc_instance.get_clusters() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### Perform Cluster Analysis with BIRCH Source: https://pyclustering.github.io/docs/0.10.1/html/index.html This example demonstrates how to load sample data, perform cluster analysis using the BIRCH algorithm to allocate three clusters, and retrieve the allocated clusters. Ensure pyclustering is installed. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.birch import birch from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample # Load data for cluster analysis - 'Lsun' sample. sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN) # Create BIRCH algorithm to allocate three clusters. birch_instance = birch(sample, 3) # Run cluster analysis. birch_instance.process() # Get allocated clusters. clusters = birch_instance.get_clusters() ``` -------------------------------- ### SOM Example Usage Source: https://pyclustering.github.io/docs/0.10.1/html/d7/d7b/classpyclustering_1_1nnet_1_1som_1_1som.html Example demonstrating the import of necessary modules and the definition of sample data for use with the SOM. ```python import random from pyclustering.utils import read_sample from pyclustering.nnet.som import som, type_conn, type_init, som_parameters from pyclustering.samples.definitions import FCPS_SAMPLES ``` -------------------------------- ### G-Means Clustering with Default Settings Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dd0/gmeans_8py_source.html This example demonstrates the basic usage of the G-Means algorithm, starting with a single cluster and processing a sample dataset. It shows how to retrieve clusters, centers, and the total Weighted Cluster Error (WCE), and visualizes the results. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.gmeans import gmeans from pyclustering.utils import read_sample from pyclustering.samples.definitions import FCPS_SAMPLES # Read sample 'Lsun' from file. sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN) # Create instance of G-Means algorithm. By default the algorithm starts search from a single cluster. gmeans_instance = gmeans(sample).process() # Extract clustering results: clusters and their centers clusters = gmeans_instance.get_clusters() centers = gmeans_instance.get_centers() # Print total sum of metric errors print("Total WCE:", gmeans_instance.get_total_wce()) # Visualize clustering results visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### X-Means Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/d5/dc4/xmeans_8py_source.html Demonstrates how to perform X-Means clustering on a sample dataset. It includes reading data, initializing centers, processing, extracting results, and visualizing the clusters. The algorithm starts with a specified number of initial centers and has a maximum cluster limit. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.xmeans import xmeans from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES # Read sample 'simple3' from file. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Prepare initial centers - amount of initial centers defines amount of clusters from which X-Means will # start analysis. amount_initial_centers = 2 initial_centers = kmeans_plusplus_initializer(sample, amount_initial_centers).initialize() # Create instance of X-Means algorithm. The algorithm will start analysis from 2 clusters, the maximum # number of clusters that can be allocated is 20. xmeans_instance = xmeans(sample, initial_centers, 20) xmeans_instance.process() # Extract clustering results: clusters and their centers clusters = xmeans_instance.get_clusters() centers = xmeans_instance.get_centers() # Print total sum of metric errors print("Total WCE:", xmeans_instance.get_total_wce()) # Visualize clustering results visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.append_cluster(centers, None, marker='*', markersize=10) visualizer.show() ``` -------------------------------- ### Get Start and Stop Iterations for Sync Network Source: https://pyclustering.github.io/docs/0.10.1/html/d6/da0/nnet_2sync_8py_source.html Prepares start and stop iteration values for calculations within the Sync network. If start or stop iterations are not provided, default values are used based on the length of the sync output. ```python @staticmethod def __get_start_stop_iterations(sync_output_dynamic, start_iteration, stop_iteration): if start_iteration is None: start_iteration = 0 if stop_iteration is None: stop_iteration = len(sync_output_dynamic) return start_iteration, stop_iteration ``` -------------------------------- ### PCNN Simulation Example Source: https://pyclustering.github.io/docs/0.10.1/html/d0/da2/classpyclustering_1_1nnet_1_1pcnn_1_1pcnn__network.html Example demonstrating how to perform a PCNN simulation using the pcnn_network and pcnn_visualizer classes. ```python from pyclustering.nnet.pcnn import pcnn_network, pcnn_visualizer ``` -------------------------------- ### Silhouette K-Search Example - Python Source: https://pyclustering.github.io/docs/0.10.1/html/d4/db5/silhouette_8py_source.html Example demonstrating the use of silhouette_ksearch with K-Means on the 'Hepta' sample dataset. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.cluster.kmeans import kmeans from pyclustering.cluster.silhouette import silhouette_ksearch_type, silhouette_ksearch from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample sample = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA) ``` -------------------------------- ### KD-Tree Nearest Neighbor Search Example Source: https://pyclustering.github.io/docs/0.10.1/html/d4/d60/kdtree_8py_source.html Demonstrates how to create a KD-tree from sample data and perform nearest neighbor searches using specified distances. This example utilizes a balanced KD-tree constructed from a dataset. ```python from pyclustering.samples.definitions import SIMPLE_SAMPLES; from pyclustering.container.kdtree import kdtree; from pyclustering.utils import read_sample; sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3); tree_instance = kdtree(sample); search_distance = 0.3; near_node = tree_instance.find_nearest_dist_node([1.12, 4.31], search_distance); near_nodes = tree_instance.find_nearest_dist_nodes([1.12, 4.31], search_distance); print("Nearest nodes:", near_nodes); ``` -------------------------------- ### Multidimensional Cluster Visualizer Example Source: https://pyclustering.github.io/docs/0.10.1/html/d0/d94/cluster_2____init_____8py_source.html Demonstrates how to visualize clustering results for multi-dimensional data using the `cluster_visualizer_multidim` class. This example loads a 4D sample, performs X-Means clustering, and then visualizes the results. ```python from pyclustering.utils import read_sample from pyclustering.samples.definitions import FAMOUS_SAMPLES from pyclustering.cluster import cluster_visualizer_multidim # load 4D data sample 'Iris' sample_4d = read_sample(FAMOUS_SAMPLES.SAMPLE_IRIS) # initialize 3 initial centers using K-Means++ algorithm centers = kmeans_plusplus_initializer(sample_4d, 3).initialize() # performs cluster analysis using X-Means xmeans_instance = xmeans(sample_4d, centers) xmeans_instance.process() clusters = xmeans_instance.get_clusters() # visualize obtained clusters in multi-dimensional space visualizer = cluster_visualizer_multidim() visualizer.append_clusters(clusters, sample_4d) visualizer.show(max_row_size=3) ``` -------------------------------- ### Full K-Means++ Initialization and Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/dc/d30/center__initializer_8py_source.html Demonstrates the complete workflow of using K-Means++ for initial center preparation, followed by K-Means clustering and visualization. Ensure necessary imports are present. ```python from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.cluster.kmeans import kmeans from pyclustering.cluster import cluster_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES # Read data 'SampleSimple3' from Simple Sample collection. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Calculate initial centers using K-Means++ method. centers = kmeans_plusplus_initializer(sample, 4, kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize() # Display initial centers. visualizer = cluster_visualizer() visualizer.append_cluster(sample) visualizer.append_cluster(centers, marker='*', markersize=10) visualizer.show() # Perform cluster analysis using K-Means algorithm with initial centers. kmeans_instance = kmeans(sample, centers) # Run clustering process and obtain result. kmeans_instance.process() clusters = kmeans_instance.get_clusters() ``` -------------------------------- ### Get BSAS Cluster Encoding Source: https://pyclustering.github.io/docs/0.10.1/html/db/d8b/classpyclustering_1_1cluster_1_1bsas_1_1bsas.html Returns the type of encoding used for the clustering results. This indicates how the clusters are represented, for example, by representatives or by assigning each point to a cluster. ```python get_cluster_encoding() ``` -------------------------------- ### K-Medians Algorithm Example Source: https://pyclustering.github.io/docs/0.10.1/html/d8/d36/kmedians_8py_source.html Demonstrates how to load data, initialize and process the K-Medians algorithm, and visualize the results. Requires sample data and initial median points. ```python from pyclustering.cluster.kmedians import kmedians from pyclustering.cluster import cluster_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import FCPS_SAMPLES # Load list of points for cluster analysis. sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) # Create instance of K-Medians algorithm. initial_medians = [[0.0, 0.1], [2.5, 0.7]] kmedians_instance = kmedians(sample, initial_medians) # Run cluster analysis and obtain results. kmedians_instance.process() clusters = kmedians_instance.get_clusters() medians = kmedians_instance.get_medians() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.append_cluster(initial_medians, marker='*', markersize=10) visualizer.append_cluster(medians, marker='*', markersize=10) visualizer.show() ``` -------------------------------- ### SOM Initialization and Training Example Source: https://pyclustering.github.io/docs/0.10.1/html/d1/db0/som_8py_source.html Demonstrates how to initialize, train, and simulate a SOM network. It includes reading sample data, configuring SOM parameters, training the network, and simulating with modified data points. Visualization methods are also shown. ```python import random from pyclustering.utils import read_sample from pyclustering.nnet.som import som, type_conn, type_init, som_parameters from pyclustering.samples.definitions import FCPS_SAMPLES # read sample 'Lsun' from file sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN) # create SOM parameters parameters = som_parameters() # create self-organized feature map with size 7x7 rows = 10 # five rows cols = 10 # five columns structure = type_conn.grid_four; # each neuron has max. four neighbors. network = som(rows, cols, structure, parameters) # train network on 'Lsun' sample during 100 epouchs. network.train(sample, 100) # simulate trained network using randomly modified point from input dataset. index_point = random.randint(0, len(sample) - 1) point = sample[index_point] # obtain randomly point from data point[0] += random.random() * 0.2 # change randomly X-coordinate point[1] += random.random() * 0.2 # change randomly Y-coordinate index_winner = network.simulate(point) # check what are objects from input data are much close to randomly modified. index_similar_objects = network.capture_objects[index_winner] # neuron contains information of encoded objects print("Point '%s' is similar to objects with indexes '%s'." % (str(point), str(index_similar_objects))) print("Coordinates of similar objects:") for index in index_similar_objects: print("\tPoint:", sample[index]) # result visualization: # show distance matrix (U-matrix). network.show_distance_matrix() # show density matrix (P-matrix). network.show_density_matrix() # show winner matrix. network.show_winner_matrix() # show self-organized map. network.show_network() ``` -------------------------------- ### K-Medians Algorithm Initialization and Processing Source: https://pyclustering.github.io/docs/0.10.1/html/df/d68/classpyclustering_1_1cluster_1_1kmedians_1_1kmedians.html Demonstrates how to initialize and run the K-Medians algorithm with sample data. It includes loading data, setting initial medians, processing the data to obtain clusters and medians, and visualizing the results. ```python from pyclustering.cluster.kmedians import kmedians from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample from pyclustering.cluster_visualizer import cluster_visualizer # Load list of points for cluster analysis. sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) # Create instance of K-Medians algorithm. initial_medians = [[0.0, 0.1], [2.5, 0.7]] kmedians_instance = kmedians(sample, initial_medians) # Run cluster analysis and obtain results. kmedians_instance.process() clusters = kmedians_instance.get_clusters() medians = kmedians_instance.get_medians() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.append_cluster(initial_medians, marker='*', markersize=10) visualizer.append_cluster(medians, marker='*', markersize=10) visualizer.show() ``` -------------------------------- ### SyncNet Example Usage Source: https://pyclustering.github.io/docs/0.10.1/html/d4/d98/classpyclustering_1_1cluster_1_1syncnet_1_1syncnet.html Demonstrates the basic usage of the SyncNet clustering algorithm, including importing necessary modules, reading sample data, and initializing the visualizer. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.syncnet import syncnet, solve_type from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample ``` -------------------------------- ### Initialize and Process ROCK Algorithm Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dde/classpyclustering_1_1cluster_1_1rock_1_1rock.html Demonstrates how to initialize the ROCK algorithm with sample data and parameters, process the data to find clusters, and retrieve the results. Ensure sample data is loaded and visualization tools are available if needed. ```python sample = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA) rock_instance = rock(sample, 1.0, 7) rock_instance.process() clusters = rock_instance.get_clusters() visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### SOM Get State Source: https://pyclustering.github.io/docs/0.10.1/html/d7/d7b/classpyclustering_1_1nnet_1_1som_1_1som.html Internal method to get the state of the SOM. ```python __getstate__() ``` -------------------------------- ### Initialize and Process SYNC-SOM Source: https://pyclustering.github.io/docs/0.10.1/html/d8/d46/classpyclustering_1_1cluster_1_1syncsom_1_1syncsom.html Demonstrates reading sample data, initializing the SYNC-SOM network, processing the data to perform clustering, and retrieving the resulting clusters. ```python from pyclustering.cluster.syncsom import syncsom from pyclustering.utils import read_sample # read sample for clustering sample = read_sample(file); # create oscillatory network for cluster analysis where the first layer has # size 10x10 and connectivity radius for objects 1.0. network = syncsom(sample, 10, 10, 1.0); # simulate network (perform cluster analysis) and collect output dynamic (dyn_time, dyn_phase) = network.process(True, 0.998); # obtain encoded clusters encoded_clusters = network.get_som_clusters(); # obtain real clusters clusters = network.get_clusters(); # show the first layer of the network network.show_som_layer(); # show the second layer of the network network.show_sync_layer(); ``` -------------------------------- ### Install PyClustering using pip Source: https://pyclustering.github.io Use this command to install the pyclustering library via pip. ```bash $ pip3 install pyclustering ``` -------------------------------- ### Prepare initial centers for K-Means algorithm using K-Means++ Source: https://pyclustering.github.io/docs/0.10.1/html/db/de0/classpyclustering_1_1cluster_1_1center__initializer_1_1kmeans__plusplus__initializer.html This example demonstrates the complete process of preparing initial centers for the K-Means algorithm using the K-Means++ method. It involves reading sample data, initializing the K-Means++ initializer, calculating the initial centers, and then performing K-Means clustering. Finally, it visualizes the results. ```python from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.cluster.kmeans import kmeans from pyclustering.cluster import cluster_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES sample = read_sample(SIMPLE_SAMPLES.TWO_GAUSSIANS) amount_centers = 4 amount_candidates = 3 initializer = kmeans_plusplus_initializer(sample, amount_centers, amount_candidates) initial_centers = initializer.initialize() kmeans_instance = kmeans(sample, initial_centers) kmeans_instance.process() clusters = kmeans_instance.get_clusters() vis = cluster_visualizer() vis.append_clusters(clusters, sample) vis.show() ``` -------------------------------- ### K-Medians Algorithm Initialization and Processing Source: https://pyclustering.github.io/docs/0.10.1/html/df/d68/classpyclustering_1_1cluster_1_1kmedians_1_1kmedians.html Demonstrates how to initialize and run the K-Medians algorithm with sample data and initial centers. The process method performs the clustering, and results can be retrieved using get methods. ```python from pyclustering.cluster.kmedians import kmedians from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample # Load list of points for cluster analysis. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Initial centers for sample 'Simple3'. initial_medians = [[0.2, 0.1], [4.0, 1.0], [2.0, 2.0], [2.3, 3.9]] # Create instance of K-Medians algorithm with prepared centers. kmedians_instance = kmedians(sample, initial_medians) # Run cluster analysis. kmedians_instance.process() # Calculate the closest cluster to following two points. points = [[0.25, 0.2], [2.5, 4.0]] closest_clusters = kmedians_instance.predict(points) print(closest_clusters) ``` -------------------------------- ### Install pyclustering after Makefile build Source: https://pyclustering.github.io/docs/0.10.1/html/index.html Navigate back to the pyclustering root folder and install the library after building it with the Makefile. ```bash cd ../ python3 setup.py install ``` -------------------------------- ### Balanced KD-Tree Initialization and Visualization Source: https://pyclustering.github.io/docs/0.10.1/html/d4/d60/kdtree_8py_source.html Demonstrates how to create a balanced KD-tree from a sample dataset and visualize it. Requires importing necessary modules from pyclustering. ```python from pyclustering.container.kdtree import kdtree_balanced, kdtree_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import FCPS_SAMPLES sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN) tree_instance = kdtree_balanced(sample) kdtree_visualizer(tree_instance).visualize() ``` -------------------------------- ### Initialize and Simulate fsync Network Source: https://pyclustering.github.io/docs/0.10.1/html/dc/d73/classpyclustering_1_1nnet_1_1fsync_1_1fsync__network.html Prepare parameters, create an fsync_network, and simulate its dynamics. Set 'collect_dynamic' to True to obtain the entire output dynamic. ```python amount_oscillators = 3 frequency = 1.0 radiuses = [1.0, 2.0, 3.0] coupling_strength = 1.0 oscillatory_network = fsync_network(amount_oscillators, frequency, radiuses, coupling_strength) output_dynamic = oscillatory_network.simulate(200, 10, True) ``` -------------------------------- ### DBSCAN Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/index.html An example of cluster analysis using the DBSCAN algorithm for FCPS samples and visualization of results. ```python # DBSCAN clustering example (no code provided in source) ``` -------------------------------- ### G-Means Output Example Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dd0/gmeans_8py_source.html Example output showing the cluster labels assigned to data points after G-Means processing. ```text [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] ``` -------------------------------- ### X-Means Algorithm Initialization and Processing Source: https://pyclustering.github.io/docs/0.10.1/html/dd/db4/classpyclustering_1_1cluster_1_1xmeans_1_1xmeans.html Demonstrates how to initialize and run the X-Means algorithm with sample data and predefined centers. It also shows how to predict the closest cluster for new points. ```python from pyclustering.cluster.xmeans import xmeans from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample # Load list of points for cluster analysis. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Initial centers for sample 'Simple3'. initial_centers = [[0.2, 0.1], [4.0, 1.0], [2.0, 2.0], [2.3, 3.9]] # Create instance of X-Means algorithm with prepared centers. xmeans_instance = xmeans(sample, initial_centers) # Run cluster analysis. xmeans_instance.process() # Calculate the closest cluster to following two points. points = [[0.25, 0.2], [2.5, 4.0]] closest_clusters = xmeans_instance.predict(points) print(closest_clusters) ``` -------------------------------- ### ROCK Clustering Algorithm Example Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dde/classpyclustering_1_1cluster_1_1rock_1_1rock.html Demonstrates how to use the ROCK clustering algorithm. Imports necessary modules and defines sample data for clustering. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.rock import rock from pyclustering.samples.definitions import FCPS_SAMPLES from pyclustering.utils import read_sample ``` -------------------------------- ### Class Members starting with 'x' Source: https://pyclustering.github.io/docs/0.10.1/html/functions_x.html This section details the class members that start with the letter 'x' in the pyclustering library. ```APIDOC ## Class Members - x ### Description This section lists class members starting with 'x'. ### Members * **x_labels** : `pyclustering.nnet.dynamic_visualizer.canvas_descr` * **x_lim** : `pyclustering.nnet.dynamic_visualizer.canvas_descr` * **x_title** : `pyclustering.nnet.dynamic_visualizer.canvas_descr` ``` -------------------------------- ### Initialize and Process Genetic Algorithm Clustering Source: https://pyclustering.github.io/docs/0.10.1/html/d5/d4d/classpyclustering_1_1cluster_1_1ga_1_1genetic__algorithm.html Demonstrates how to initialize and run the genetic algorithm for clustering. Ensure necessary imports are present. ```python from pyclustering.cluster.ga import genetic_algorithm, ga_observer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES ``` -------------------------------- ### FCM Image Segmentation Example Source: https://pyclustering.github.io/docs/0.10.1/html/df/dfc/fcm_8py_source.html Performs image segmentation using the Fuzzy C-Means algorithm. This example loads an image, applies FCM for segmentation, and visualizes the results. ```python from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.cluster.fcm import fcm from pyclustering.utils import read_image, draw_image_mask_segments # load list of points for cluster analysis data = read_image("stpetersburg_admiral.jpg") # initialize initial_centers = kmeans_plusplus_initializer(data, 3, kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize() # create instance of Fuzzy C-Means algorithm fcm_instance = fcm(data, initial_centers) # run cluster analysis and obtain results fcm_instance.process() clusters = fcm_instance.get_clusters() # visualize segmentation results draw_image_mask_segments("stpetersburg_admiral.jpg", clusters) ``` -------------------------------- ### Initialize and Use Cluster Visualizer Source: https://pyclustering.github.io/docs/0.10.1/html/d0/d94/cluster_2____init_____8py_source.html This example demonstrates how to initialize a cluster visualizer, load 2D and 3D data samples, process them using DBSCAN, and then append and display the resulting clusters on separate canvases. It shows setting up the visualizer with a specific number of canvases and row size, and then displaying the results. ```python # load 2D data sample sample_2d = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1); # load 3D data sample sample_3d = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA); # extract clusters from the first sample using DBSCAN algorithm dbscan_instance = dbscan(sample_2d, 0.4, 2, False); dbscan_instance.process(); clusters_sample_2d = dbscan_instance.get_clusters(); # extract clusters from the second sample using DBSCAN algorithm dbscan_instance = dbscan(sample_3d, 1, 3, True); dbscan_instance.process(); clusters_sample_3d = dbscan_instance.get_clusters(); # create plot with two canvases where each row contains 2 canvases. size = 2; row_size = 2; visualizer = cluster_visualizer(size, row_size); # place clustering result of sample_2d to the first canvas visualizer.append_clusters(clusters_sample_2d, sample_2d, 0, markersize = 5); # place clustering result of sample_3d to the second canvas visualizer.append_clusters(clusters_sample_3d, sample_3d, 1, markersize = 30); # show plot visualizer.show(); ``` -------------------------------- ### CNN Network Example Source: https://pyclustering.github.io/docs/0.10.1/html/d2/da2/cnn_8py_source.html Example demonstrating the creation, simulation, and visualization of a Chaotic Neural Network (CNN). Loads sample data, simulates network activity, and visualizes the results. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample from pyclustering.nnet.cnn import cnn_network, cnn_visualizer # Load stimulus from file. stimulus = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Create chaotic neural network, amount of neurons should be equal to amount of stimulus. network_instance = cnn_network(len(stimulus)) # Perform simulation during 100 steps. steps = 100 output_dynamic = network_instance.simulate(steps, stimulus) # Display output dynamic of the network. cnn_visualizer.show_output_dynamic(output_dynamic) # Display dynamic matrix and observation matrix to show clustering phenomenon. cnn_visualizer.show_dynamic_matrix(output_dynamic) cnn_visualizer.show_observation_matrix(output_dynamic) # Visualize clustering results. clusters = output_dynamic.allocate_sync_ensembles(10) visualizer = cluster_visualizer() visualizer.append_clusters(clusters, stimulus) visualizer.show() ``` -------------------------------- ### Initialize and Process Genetic Algorithm Source: https://pyclustering.github.io/docs/0.10.1/html/d5/d4d/classpyclustering_1_1cluster_1_1ga_1_1genetic__algorithm.html Demonstrates how to initialize and run the genetic algorithm for clustering. Ensure necessary data and parameters are provided. ```python from pyclustering.cluster.ga import genetic_algorithm, ga_observer from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample # Read input data for clustering sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE4) # Create instance of observer that will collect all information: observer_instance = ga_observer(True, True, True) # Create genetic algorithm for clustering ga_instance = genetic_algorithm(data=sample, count_clusters=4, chromosome_count=100, population_count=200, count_mutation_gens=1) # Start processing ga_instance.process() # Obtain results clusters = ga_instance.get_clusters() # Print cluster to console print("Amount of clusters: '%d'. Clusters: '%s'" % (len(clusters), clusters)) ``` -------------------------------- ### KDTreeVisualizer.__init__ Source: https://pyclustering.github.io/docs/0.10.1/html/d4/d60/kdtree_8py_source.html Initializes the KD-tree visualizer. ```APIDOC ## KDTreeVisualizer.__init__ ### Description Initializes the KD-tree visualizer. ### Method Signature `def __init__(self, kdtree_instance)` ### Parameters - **kdtree_instance**: An instance of the KD-tree to visualize. ``` -------------------------------- ### K-Medoids Algorithm Initialization and Processing Source: https://pyclustering.github.io/docs/0.10.1/html/d0/dd3/classpyclustering_1_1cluster_1_1kmedoids_1_1kmedoids.html Demonstrates how to initialize the K-Medoids algorithm with sample data and initial medoids, then process the data to perform clustering. The closest clusters for new points can be predicted after processing. ```python from pyclustering.cluster.kmedoids import kmedoids from pyclustering.samples.definitions import SIMPLE_SAMPLES from pyclustering.utils import read_sample sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) initial_medoids = [4, 12, 25, 37] kmedoids_instance = kmedoids(sample, initial_medoids) kmedoids_instance.process() points = [[0.35, 0.5], [2.5, 2.0]] closest_clusters = kmedoids_instance.predict(points) print(closest_clusters) ``` -------------------------------- ### Syncsegm Image Segmentation Example Source: https://pyclustering.github.io/docs/0.10.1/html/db/d89/syncsegm_8py_source.html Example of using the syncsegm class to segment an image for colors and objects, while ignoring noise. It demonstrates creating the algorithm instance, processing an image, and obtaining segmentation results for both colors and objects. ```python # create oscillatory for image segmentaion - extract colors (radius 128) and objects (radius 4), # and ignore noise (segments with size that is less than 10 pixels) algorithm = syncsegm(128, 4, 10); # extract segments (colors and objects) analyzer = algorithm(path_to_file); # obtain segmentation results (only colors - from the first layer) color_segments = analyzer.allocate_colors(0.01, 10); draw_image_mask_segments(path_to_file, color_segments); # obtain segmentation results (objects - from the second layer) object_segments = analyzer.allocate_objects(0.01, 10); draw_image_mask_segments(path_to_file, object_segments); ``` -------------------------------- ### Get Centers Source: https://pyclustering.github.io/docs/0.10.1/html/dd/db4/classpyclustering_1_1cluster_1_1xmeans_1_1xmeans.html Returns the centers of the allocated clusters. ```APIDOC ## get_centers ### Description Returns list of centers for allocated clusters. ### Method `get_centers()` ``` -------------------------------- ### EMA Initialization Example Source: https://pyclustering.github.io/docs/0.10.1/html/d6/deb/ema_8py_source.html Demonstrates how to initialize the Expectation-Maximization algorithm's parameters (means and covariances) using the K-Means strategy. This requires sample data and the desired number of clusters. ```python from pyclustering.utils import read_sample from pyclustering.samples.definitions import FAMOUS_SAMPLES from pyclustering.cluster.ema import ema_initializer sample = read_sample(FAMOUS_SAMPLES.SAMPLE_OLD_FAITHFUL) amount_clusters = 2 initial_means, initial_covariance = ema_initializer(sample, amount_clusters).initialize() print(initial_means) print(initial_covariance) ``` -------------------------------- ### TTSAS Get Representatives Source: https://pyclustering.github.io/docs/0.10.1/html/df/db9/classpyclustering_1_1cluster_1_1ttsas_1_1ttsas.html Retrieves the representatives of the allocated clusters. ```APIDOC ## get_representatives ### Description Returns list of representatives of allocated clusters. ### Method get_representatives ### Parameters None ### Returns List of cluster representatives. ``` -------------------------------- ### kdtree_visualizer.__init__ Source: https://pyclustering.github.io/docs/0.10.1/html/d1/d0f/classpyclustering_1_1container_1_1kdtree_1_1kdtree__visualizer-members.html Initializes the kdtree_visualizer with a given kdtree instance. ```APIDOC ## __init__(self, kdtree_instance) ### Description Initializes the kdtree_visualizer with a given kdtree instance. ### Parameters * **kdtree_instance** (pyclustering.container.kdtree.kdtree) - The kdtree instance to visualize. ``` -------------------------------- ### K-Medoids (PAM) Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/d1/d6b/kmedoids_8py_source.html Demonstrates how to use the K-Medoids algorithm to cluster data. It includes loading sample data, initializing medoids using K-Means++, processing the data, and visualizing the results. Use this for general-purpose clustering when medoids are preferred over centroids. ```python from pyclustering.cluster.kmedoids import kmedoids from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.cluster import cluster_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import FCPS_SAMPLES # Load list of points for cluster analysis. sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) # Initialize initial medoids using K-Means++ algorithm initial_medoids = kmeans_plusplus_initializer(sample, 2).initialize(return_index=True) # Create instance of K-Medoids (PAM) algorithm. kmedoids_instance = kmedoids(sample, initial_medoids) # Run cluster analysis and obtain results. kmedoids_instance.process() clusters = kmedoids_instance.get_clusters() medoids = kmedoids_instance.get_medoids() # Print allocated clusters. print("Clusters:", clusters) # Display clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.append_cluster(initial_medoids, sample, markersize=12, marker='*', color='gray') visualizer.append_cluster(medoids, sample, markersize=14, marker='*', color='black') visualizer.show() ``` -------------------------------- ### kdtree_balanced Get Root Source: https://pyclustering.github.io/docs/0.10.1/html/db/d87/classpyclustering_1_1container_1_1kdtree_1_1kdtree__balanced.html Retrieves the root node of the KD-tree. ```APIDOC ## get_root (self) ### Description Returns root of the tree. ### Returns (Node) The root node of the KD-tree. ``` -------------------------------- ### Initialize K-Means++ Centers Source: https://pyclustering.github.io/docs/0.10.1/html/db/de0/classpyclustering_1_1cluster_1_1center__initializer_1_1kmeans__plusplus__initializer.html Demonstrates how to read sample data, initialize cluster centers using K-Means++ with the farthest candidate selection, and visualize the results. This is useful for setting up initial conditions for K-Means clustering. ```python from pyclustering.cluster import kmeans_plusplus_initializer from pyclustering.cluster import kmeans from pyclustering.utils import read_sample from pyclustering.utils.metric import type_metric, distance_metric from pyclustering.visualizer import cluster_visualizer # Read data 'SampleSimple3' from Simple Sample collection. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Calculate initial centers using K-Means++ method. centers = kmeans_plusplus_initializer(sample, 4, kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize() # Display initial centers. visualizer = cluster_visualizer() visualizer.append_cluster(sample) visualizer.append_cluster(centers, marker='*', markersize=10) visualizer.show() # Perform cluster analysis using K-Means algorithm with initial centers. kmeans_instance = kmeans(sample, centers) # Run clustering process and obtain result. kmeans_instance.process() clusters = kmeans_instance.get_clusters() ``` -------------------------------- ### KDTree Get Root Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dc8/classpyclustering_1_1container_1_1kdtree_1_1kdtree.html Retrieves the root node of the KDTree. ```APIDOC ## KDTree Get Root ### Description Returns the root of the tree. ### Signature `get_root(self)` ### Returns - `node`: The root node of the KDTree. ``` -------------------------------- ### X-Means Algorithm Example Source: https://pyclustering.github.io/docs/0.10.1/html/dd/db4/classpyclustering_1_1cluster_1_1xmeans_1_1xmeans.html Demonstrates how to perform cluster analysis using the X-Means algorithm. It involves reading sample data, initializing centers using K-Means++, running the X-Means algorithm, and visualizing the results. ```python from pyclustering.cluster import cluster_visualizer from pyclustering.cluster.xmeans import xmeans from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES # Read data # sample = read_sample("path/to/your/sample.txt") sample = read_sample(SIMPLE_SAMPLES.LAClustering) # Initialize data for X-Means algorithm initial_centers = kmeans_plusplus_initializer(sample, 2).initialize() # Create instance of X-Means algorithm xmeans_instance = xmeans(sample, initial_centers) # Run algorithm xmeans_instance.process() # Get clusters and centers clusters = xmeans_instance.get_clusters() centers = xmeans_instance.get_centers() # Visualize clusters visualizer = cluster_visualizer(2, 1) visualizer.append_clusters(clusters, sample) visualizer.append_centers(centers, data_type='points') visualizer.show() ``` -------------------------------- ### Get CF Cluster Source: https://pyclustering.github.io/docs/0.10.1/html/d6/d00/classpyclustering_1_1cluster_1_1birch_1_1birch.html Retrieves clusters represented by CF-entries. ```APIDOC ## get_cf_cluster ### Description Returns list of allocated CF-entry clusters where each cluster is represented by indexes (each index corresponds to CF-entry). ### Method get_cf_cluster ### Response #### Success Response - **cf_clusters** (list): A list of lists, where each inner list contains indices of CF-entries belonging to a cluster. ``` -------------------------------- ### Initialize and Run SyncNet Clustering Source: https://pyclustering.github.io/docs/0.10.1/html/d4/d98/classpyclustering_1_1cluster_1_1syncnet_1_1syncnet.html Demonstrates the basic workflow of using SyncNet for clustering. It involves reading sample data, initializing the network, processing the data to obtain clusters, and visualizing the results. ```python from pyclustering.cluster.syncnet import syncnet from pyclustering.utils import read_sample from pyclustering.cluster_visualizer import cluster_visualizer from pyclustering.core.geometry import solve_type # Read sample for clustering from some file. sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) # Create oscillatory network with connectivity radius 1.0. network = syncnet(sample, 1.0) # Run cluster analysis and collect output dynamic of the oscillatory network. # Network simulation is performed by Runge Kutta 4. analyser = network.process(0.998, solve_type.RK4) # Show oscillatory network. network.show_network() # Obtain clustering results. clusters = analyser.allocate_clusters() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### Get Clusters Source: https://pyclustering.github.io/docs/0.10.1/html/d6/d00/classpyclustering_1_1cluster_1_1birch_1_1birch.html Retrieves the allocated clusters from the BIRCH algorithm. ```APIDOC ## get_clusters ### Description Returns list of allocated clusters, each cluster is represented by a list of indexes where each index corresponds to a point in an input dataset. ### Method get_clusters ### Response #### Success Response - **clusters** (list): A list of lists, where each inner list contains indices of data points belonging to a cluster. ``` -------------------------------- ### Initialize and Simulate HysteresisGColor Network Source: https://pyclustering.github.io/docs/0.10.1/html/df/df9/classpyclustering_1_1gcolor_1_1hysteresis_1_1hysteresisgcolor.html Loads a graph, creates a hysteresisgcolor network, simulates its behavior, and visualizes the dynamic output. Ensure 'filename', 'alpha', and 'eps' are defined before use. ```python from pyclustering.nnet.hysteresis import hysteresis_visualizer; from pyclustering.gcolor.hysteresis import hysteresisgcolor; from pyclustering.utils.graph import read_graph, draw_graph; # load graph from a file graph = read_graph(filename); # create oscillatory network for solving graph coloring problem network = hysteresisgcolor(graph.data, alpha, eps); # perform simulation of the network output_dynamic = network.simulate(2000, 20); # show dynamic of the network hysteresis_visualizer.show_output_dynamic(output_dynamic); # obtain results of graph coloring and display results coloring_map = hysteresis_visualizer.allocate_map_coloring(); draw_graph(graph, coloring_map); ``` -------------------------------- ### Get Neighbors Source: https://pyclustering.github.io/docs/0.10.1/html/d3/df7/dsatur_8py_source.html Returns the indices of the neighbors for a given node. ```APIDOC ## `__get_neighbors` ### Description Returns indexes of neighbors of the specified node. ### Method `__get_neighbors(self, node_index)` ### Parameters * **node_index** (int) - The index of the node for which to find neighbors. ``` -------------------------------- ### Get Diameter Source: https://pyclustering.github.io/docs/0.10.1/html/d0/d77/classpyclustering_1_1container_1_1cftree_1_1cfentry.html Calculates the diameter of the cluster represented by the CF-entry. ```APIDOC ## get_diameter (self) ### Description Calculates diameter of cluster that is represented by the entry. ### Returns - (float): The diameter of the cluster. ``` -------------------------------- ### Get Radius Source: https://pyclustering.github.io/docs/0.10.1/html/d0/d77/classpyclustering_1_1container_1_1cftree_1_1cfentry.html Calculates the radius of the cluster represented by the CF-entry. ```APIDOC ## get_radius (self) ### Description Calculates radius of cluster that is represented by the entry. ### Returns - (float): The radius of the cluster. ``` -------------------------------- ### Initialize Hysteresis Analyser Source: https://pyclustering.github.io/docs/0.10.1/html/df/dbd/gcolor_2hysteresis_8py_source.html Constructor for the analyser. Requires output amplitudes and simulation time from a hysteresis network. ```python def __init__(self, amplitudes, time): super().__init__(amplitudes, time) ``` -------------------------------- ### Get Centroid Source: https://pyclustering.github.io/docs/0.10.1/html/d0/d77/classpyclustering_1_1container_1_1cftree_1_1cfentry.html Calculates the centroid of the cluster represented by the CF-entry. ```APIDOC ## get_centroid (self) ### Description Calculates centroid of cluster that is represented by the entry. ### Returns - (list or numpy.ndarray): The centroid of the cluster. ``` -------------------------------- ### Get Membership Source: https://pyclustering.github.io/docs/0.10.1/html/df/dfc/fcm_8py_source.html Retrieves the cluster membership probabilities for each data point. ```APIDOC ## Get Membership ### Description Returns the membership values (probabilities) of each data point belonging to each cluster. ### Method Signature `get_membership(self)` ### Returns - **list of lists**: A 2D list where `membership[i][j]` is the probability of the i-th data point belonging to the j-th cluster. ``` -------------------------------- ### Genetic Algorithm Clustering Example Source: https://pyclustering.github.io/docs/0.10.1/html/d2/d77/ga_8py_source.html Demonstrates how to use the genetic_algorithm class for clustering. Includes reading sample data, creating an observer, initializing and processing the algorithm, and retrieving/printing the results. ```python from pyclustering.cluster.ga import genetic_algorithm, ga_observer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES # Read input data for clustering sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE4) # Create instance of observer that will collect all information: observer_instance = ga_observer(True, True, True) # Create genetic algorithm for clustering ga_instance = genetic_algorithm(data=sample, count_clusters=4, chromosome_count=100, population_count=200, count_mutation_gens=1) # Start processing ga_instance.process() # Obtain results clusters = ga_instance.get_clusters() # Print cluster to console print("Amount of clusters: '%d'. Clusters: '%s'" % (len(clusters), clusters)) ``` -------------------------------- ### Get Children Source: https://pyclustering.github.io/docs/0.10.1/html/dd/d06/classpyclustering_1_1container_1_1kdtree_1_1node.html Retrieves the non-None children of the current KD-Tree node. ```APIDOC ## get_children(self) ### Description Returns a list of the node's children that are not `None`. ### Returns * (list) A list of not `None` children of the node. Returns `None` if the node has no children. ``` -------------------------------- ### Get Cluster Centers Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dd0/gmeans_8py_source.html Returns a list of the centers for each allocated cluster. ```python def get_centers(self): """!@brief Returns list of centers of allocated clusters. @return (array_like) Allocated centers. @see process() @see get_clusters() """ return self.__centers ``` -------------------------------- ### KD-Tree Initialization and Nearest Neighbor Search Source: https://pyclustering.github.io/docs/0.10.1/html/d8/dc8/classpyclustering_1_1container_1_1kdtree_1_1kdtree.html Demonstrates initializing a KD-Tree with sample data and performing nearest neighbor searches using distance and radius criteria. Ensure pyclustering is installed and sample data is accessible. ```python from pyclustering.samples.definitions import SIMPLE_SAMPLES; from pyclustering.container.kdtree import kdtree; from pyclustering.utils import read_sample; # Read data from text file sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3); # Create instance of KD-tree and initialize (fill) it by read data. # In this case the tree is balanced. tree_instance = kdtree(sample); # Search for nearest point search_distance = 0.3; nearest_node = tree_instance.find_nearest_dist_node([1.12, 4.31], search_distance); # Search for nearest point in radius 0.3 nearest_nodes = tree_instance.find_nearest_dist_nodes([1.12, 4.31], search_distance); print("Nearest nodes:", nearest_nodes); ``` -------------------------------- ### SOM-SC Algorithm Usage Example Source: https://pyclustering.github.io/docs/0.10.1/html/d3/d44/classpyclustering_1_1cluster_1_1somsc_1_1somsc.html Demonstrates how to load data, create a SOM-SC instance, process the data, retrieve clusters, and visualize the results. Ensure pyclustering and its samples are imported. ```python from pyclustering.cluster import somsc from pyclustering.utils import read_sample from pyclustering.utils.samples import FCPS_SAMPLES from pyclustering.cluster_visualizer import cluster_visualizer # Load list of points for cluster analysis sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) # Create instance of SOM-SC algorithm to allocated two clusters somsc_instance = somsc(sample, 2) # Run cluster analysis and obtain results somsc_instance.process() clusters = somsc_instance.get_clusters() # Visualize clustering results. visualizer = cluster_visualizer() visualizer.append_clusters(clusters, sample) visualizer.show() ``` -------------------------------- ### Get Captured Objects Source: https://pyclustering.github.io/docs/0.10.1/html/d7/d7b/classpyclustering_1_1nnet_1_1som_1_1som.html Returns the indexes of objects captured by each neuron. ```python capture_objects() ``` -------------------------------- ### BSAS Example Usage Source: https://pyclustering.github.io/docs/0.10.1/html/db/d8b/classpyclustering_1_1cluster_1_1bsas_1_1bsas.html Demonstrates how to use the BSAS clustering algorithm with sample data. It includes reading sample data, initializing the BSAS algorithm, processing the data, and retrieving the clustering results. ```python from pyclustering.cluster.bsas import bsas, bsas_visualizer from pyclustering.utils import read_sample from pyclustering.samples.definitions import SIMPLE_SAMPLES ``` -------------------------------- ### Get Neuron Weights Source: https://pyclustering.github.io/docs/0.10.1/html/d7/d7b/classpyclustering_1_1nnet_1_1som_1_1som.html Returns the weight of each neuron in the self-organized map. ```python weights() ``` -------------------------------- ### KMeans++ Initializer Initialize Method Source: https://pyclustering.github.io/docs/0.10.1/html/db/de0/classpyclustering_1_1cluster_1_1center__initializer_1_1kmeans__plusplus__initializer.html Shows how to call the `initialize` method of the K-Means++ initializer to obtain the initial cluster centers. The `return_index` keyword argument can be used to get the indices of the points instead of the points themselves. ```python initial_centers = initializer.initialize(return_index=False) ``` -------------------------------- ### Get Colors Source: https://pyclustering.github.io/docs/0.10.1/html/d3/df7/dsatur_8py_source.html Retrieves the computed colors for each node after the algorithm has been run. ```APIDOC ## `get_colors` ### Description Returns results of graph coloring. ### Method `get_colors(self)` ### Response #### Success Response Returns a list or dictionary representing the color assigned to each node. ``` -------------------------------- ### Get Cluster Centers Source: https://pyclustering.github.io/docs/0.10.1/html/d2/d6a/classpyclustering_1_1cluster_1_1fcm_1_1fcm.html Retrieves the coordinates of the centers for the allocated clusters. ```APIDOC ## pyclustering.cluster.fcm.fcm.get_centers ### Description Returns a list of centers of the allocated clusters. ### Returns (array_like) Cluster centers. ### See Also process(), get_clusters(), get_membership() ### Definition Definition at line 164 of file fcm.py. ```