PyClustering Documentation

repository·master·Indexed 22 days ago

https://github.com/annoviko/pyclustering

A data mining library providing Python and C++ implementations of clustering algorithms, oscillatory networks, and neural networks. It features a hybrid implementation using a C++ core for high performance, falling back to NumPy-optimized Python. The library includes a wide range of algorithms such as K-Means, DBSCAN, and OPTICS, as well as specialized models like the Hodgkin-Huxley and Kuramoto-based networks, graph coloring algorithms, and data containers like KD-Trees.

Tokens
6K
Snippets
12
Records
27
Agent score
77%

What's inside PyClustering

  1. Overview of PyClustering

    master

    PyClustering is an open-source data mining library designed for cluster analysis. It is implemented in both Python and C++ to provide a wide range of clustering algorithms, including bio-inspired oscillatory networks.

    Key features include:

    • Hybrid Implementation: Uses a C++ core by default for maximum performance (especially for differential equation-based oscillatory networks). If no C++ compiler is detected, it falls back to pure Python implementations optimized with NumPy.
    • Parallelism: Optimized C++14 implementations use std::thread on most platforms and the Parallel Patterns Library on Windows.
    • Visualization: Supports 2D and 3D plots of cluster embeddings, image segments, and synchronization process graphs for oscillatory networks.
    • Core Dependencies: Requires NumPy and SciPy for data processing, and MatPlotLib and Pillow for visualization.
  2. Overview of PyClustering namespaces and algorithms

    master

    The C++ PyClustering library is organized into two primary namespaces:

    pyclustering::clst (Cluster Analysis)

    Contains various clustering algorithms, including:

    • Agglomerative (pyclustering::clst::agglomerative)
    • BSAS (pyclustering::clst::bsas)
    • CLIQUE (pyclustering::clst::clique)
    • CURE (pyclustering::clst::cure)
    • DBSCAN (pyclustering::clst::dbscan)
    • Fuzzy C-Means (pyclustering::clst::fcm)
    • G-Means (pyclustering::clst::gmeans)
    • HSyncNet (pyclustering::clst::hsyncnet)
    • K-Means (pyclustering::clst::kmeans)
    • K-Means++ (pyclustering::clst::kmeans_plus_plus)
    • K-Medians (pyclustering::clst::kmedians)
    • K-Medoids (pyclustering::clst::kmedoids)
    • MBSAS (pyclustering::clst::mbsas)
    • OPTICS (pyclustering::clst::optics)
    • ROCK (pyclustering::clst::rock)
    • Silhouette (pyclustering::clst::silhouette, pyclustering::clst::silhouette_ksearch)
    • SOM-SC (pyclustering::clst::somsc)
    • SyncNet (pyclustering::clst::syncnet)
    • TTSAS (pyclustering::clst::ttsas)
    • X-Means (pyclustering::clst::xmeans)

    pyclustering::nnet (Oscillatory Neural Networks)

    Contains oscillatory network models, including:

    • Hodgkin-Huxley model (pyclustering::nnet::hhn_network)
    • LEGION: Local Excitatory Global Inhibitory Oscillatory Network (pyclustering::nnet::legion_network)
    • PCNN: Pulse-Coupled Neural Network (pyclustering::nnet::pcnn)
    • SOM: Self-Organized Map (pyclustering::nnet::som)
    • Sync: Kuramoto model-based network (pyclustering::nnet::sync_network)
    • SyncPR: Kuramoto model for pattern recognition (pyclustering::nnet::syncpr)
  3. Control C/C++ core usage with the ccore flag

    master

    PyClustering algorithms are implemented in both Python and C/C++. By default, the library attempts to use the C/C++ implementation (ccore=True) for better performance. If the C/C++ core is unavailable or if you want to use the pure Python implementation, you can explicitly set the ccore flag to False.

    # As by default - C/C++ part of the library is used
    xmeans_instance_1 = xmeans(data_points, start_centers, 20, ccore=True);
    
    # The same - C/C++ part of the library is used by default
    xmeans_instance_2 = xmeans(data_points, start_centers, 20);
    
    # Switch off core - Python is used
    xmeans_instance_3 = xmeans(data_points, start_centers, 20, ccore=False);
  4. Access Oscillatory and Neural Network models

    master

    Neural network and oscillatory network models are available in the pyclustering.nnet Python module. Some models are implemented in both Python and C++ (ccore::nnet), while others are Python-only.

    Available Models:

    • CNN (Chaotic Neural Network): Python only
    • fSync (Landau-Stuart/Kuramoto based): Python only
    • HHN (Hodgkin-Huxley based): Python and C++
    • Hysteresis Oscillatory Network: Python only
    • LEGION (Local Excitatory Global Inhibitory): Python and C++
    • PCNN (Pulse-Coupled Neural Network): Python and C++
    • SOM (Self-Organized Map): Python and C++
    • Sync (Kuramoto based): Python and C++
    • SyncPR (Pattern Recognition): Python and C++
    • SyncSegm (Image Segmentation): Python and C++
  5. Install pyclustering using Microsoft Visual Studio

    master

    For Windows users, you can build the C++ core using Visual Studio:

    1. Clone the repository: https://github.com/annoviko/pyclustering.git
    2. Open the folder pyclustering/ccore.
    3. Open the Visual Studio project ccore.sln.
    4. Select the solution platform: x86 or x64.
    5. Build the pyclustering-shared project.
    6. Add the pyclustering folder to your Python path or install it using setup.py.
    # install pyclustering library
    $ python3 setup.py install
    
    # optionally - test the library
    $ python3 setup.py test
  6. Build the C++ PyClustering library on Windows

    master

    To build the C++ PyClustering library on Windows, download the release source files and extract them. Navigate to the pyclustering/ccore directory and open the ccore.sln solution file using Visual Studio.

    Build Configurations:

    • Use the Release configuration to build a dynamic library.
    • Use the Release Static Library configuration to build a static library.
  7. Manual installation using Microsoft Visual Studio

    master

    For Windows users, you can build the C++ core using Visual Studio:

    1. Clone the repository.
    2. Open the pyclustering/ccore folder.
    3. Open the ccore.sln project.
    4. Select your platform (x86 or x64).
    5. Build the pyclustering-shared project.
    6. Add the pyclustering folder to your Python path or run python3 setup.py install.
    # install pyclustering library
    $ python3 setup.py install
    
    # optionally - test the library
    $ python3 setup.py test
  8. Build the C++ PyClustering library on Linux or MacOS

    master

    To build the C++ PyClustering library on Linux or MacOS, download the release source files, extract them, and navigate to the pyclustering/ccore directory. You can then use make to build either a shared (dynamic) library or a static library.

    Requirements:

    • A compiler that supports C++14.
    • make utility.
  9. Install pyclustering manually using CMake

    master

    You can use CMake to generate build files and build the pyclustering-shared target.

    # get sources of the pyclustering library, for example, from repository
    $ mkdir pyclustering
    $ cd pyclustering/
    $ git clone https://github.com/annoviko/pyclustering.git .
    
    # generate build files.
    $ mkdir build
    $ cmake ..
    
    # build pyclustering-shared target depending on what was generated (Makefile or MSVC solution)
    # if Makefile has been generated then
    $ make pyclustering-shared
    
    # return to parent folder of the pyclustering library
    $ cd ../
    
    # install pyclustering library
    $ python3 setup.py install
    
    # optionally - test the library
    $ python3 setup.py test