SlideShare a Scribd company logo
PyClustering: BANG Tutorial
Pyclustering Library Tutorial
Theme: BANG
Library Version: 0.8.2
Author: Andrei Novikov
E-Mail: pyclustering@yandex.ru
Agenda
● PyClustering BANG Features;
● Input format for BANG;
● Data clustering using BANG;
● Data clustering result visualization;
● Animation of BANG clustering process;
● Image segmentation by BANG;
PyClustering BANG Features
● BANG algorithm provides clustering results that can be
used for further analysis (not only clusters and noise itself):
dendrogram, BANG directory - information about density
distribution, structure, approximate amount of real clusters
and influence of input argument on clustering results.
● BANG visualizer for clustering results, BANG directory and
dendrogram.
● BANG animator for creating animation of BANG clustering
process.
Import BANG
BANG algorithm and its features can be imported from
„pyclustering.cluster.bang“:
from pyclustering.cluster.bang import bang
from pyclustering.cluster.bang import bang_directory
from pyclustering.cluster.bang import bang_visualizer
from pyclustering.cluster.bang import bang_animator
Input data format for BANG
BANG algorithm uses array_like data format, for example,
list where each element is a point that is represented by
coordinates. Here is an example of 1-D data:
dataset = [ [0.25], [0.43], [1.34], [-0.56] ]
Example of 2-D data:
dataset = [ [0.1, 0.2], [0.1, 0.6], [0.2, -1.4] ]
Example of 3-D data:
dataset = [ [0.6, 0.1, 0.4], [0.2, 0.1, 0.9] ]
Clustering by BANG algorithm
BANG uses one general parameter for clustering: level of
division that technically means amount of BANG tree hight
where root is a cell that covers whole data.
from pyclustering.cluster.bang import bang
data = [ [0.1], [0.2], [0.5], [0.3], [1.5], [1.8], [1.3], [1.6], [1.5] ]
levels = 3
instance = bang(data, levels)
instance.process() # perform processing
clusters = instance.get_clusters(); # allocated clusters
noise = instance.get_noise(); # cluster noise
directory = instance.get_directory(); # BANG directory
dendrogram = instance.get_dendrogram() # BANG dendrogram
Output result of BANG
BANG algorithm returns allocated clusters, outliers (noise),
BANG directory and dendrogram:
● Clusters are represented by list of clusters and each cluster
contains object indexes from dataset.
● Outliers are represented by list of object indexes from
dataset.
● BANG directory is a object of class bang_directory.
● Dendrogram is represented by list of dendrogram clusters
where each cluster contains expand order of blocks that
was formed during clustering process.
BANG result visualization
Output result such as clusters and outliers can be shown
by common visualizer „cluster_visualizer“ from
„pyclustering.cluster“ or by BANG visualizer:
instance = bang(sample, levels)
instance.process()
clusters = instance.get_clusters() # allocated clusters
noise = instance.get_noise() # outliers
directory = instance.get_directory() # get BANG directory
# visualize clustering results
bang_visualizer.show_clusters(sample, clusters, noise)
bang_visualizer.show_dendrogram(dendrogram)
bang_visualizer.show_blocks(directory)
BANG visualization – Lsun
Visualization of BANG clustering results. Data: ‚Lsun‘.
BANG blocks and their
densities
BANG dendrogram of
three formed clusters
Allocated clusters by
BANG algorithm
BANG visualization – Chainlink
BANG visualizer is able to display clustering result of N-
dimension data by forming pair xk, xl, where k, l –
dimension indexes.
BANG blocks representation in case 3-dimensional data
BANG visualization - Target
Visualization of BANG clustering results. Data: ‚Target‘.
BANG blocks and their
densities
BANG dendrogram of
three formed clusters
Allocated clusters by
BANG algorithm
Animate BANG clustering process
BANG clustering process can be animated (in case of 2-
dimensional data) using services of class ‚bang_animator‘.
instance = bang(data, levels, density_threshold)
instance.process()
# obtain BANG clustering result for creating animation
clusters = instance.get_clusters()
noise = instance.get_noise()
directory = instance.get_directory()
# show animation
bang_animator(directory, clusters, noise).animate()
# or save animation to file
bang_animator(directory, clusters, noise).animate(movie_filename=bang.mp4)
BANG for segmentation
BANG can consider image as a data where each point
represent pixel with three coordinate (RGB), or with four
coordinate (RGBA). Here is an example of image
segmentation using BANG algorithm:
from pyclustering.utils import draw_image_mask_segments, read_image
from pyclustering.cluster.bang import bang;
data = read_image(file_path_to_image);
bang_instance = bang(data, levels, density_threshold);
bang_instance.process();
clusters = bang_instance.get_clusters();
draw_image_mask_segments(source, clusters);
Image segmentation results
Example of image segmentation of photo from St.-
Petersburg by BANG algorithm using pyclustering.
Shortcoming of BANG segmentation
is not trivial way to set density
Threshold, especially to handle
Images with color gradient
References and Links
● Official pyclustering github repository:
https://github.com/annoviko/pyclustering
● Official pypi pyclustering page:
https://pypi.org/project/pyclustering/
● Official pyclustering web-site:
https://pyclustering.github.io/
Thank you for your attention
Thank you!

More Related Content

PDF
Accelerating Local Search with PostgreSQL (KNN-Search)
DOCX
Project Term2 Computer barun.docx
PDF
Webi Report Function Overview
PPT
PDF
Maximum Likelihood Calibration of the Hercules Data Set
PDF
GeoMesa on Apache Spark SQL with Anthony Fox
PDF
Azure Stream Analytics Project : On-demand real-time analytics
PDF
Laporan Resmi Algoritma dan Struktur Data :
Accelerating Local Search with PostgreSQL (KNN-Search)
Project Term2 Computer barun.docx
Webi Report Function Overview
Maximum Likelihood Calibration of the Hercules Data Set
GeoMesa on Apache Spark SQL with Anthony Fox
Azure Stream Analytics Project : On-demand real-time analytics
Laporan Resmi Algoritma dan Struktur Data :

What's hot (20)

PDF
A practical Introduction to Machine(s) Learning
PDF
NLP on a Billion Documents: Scalable Machine Learning with Apache Spark
PPTX
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
PDF
Machine(s) Learning with Neural Networks
PPT
Applicationof datastructures
PDF
最新のデータベース技術の方向性で思うこと
PDF
Nx tutorial basics
PDF
MongoDB Project: Relational databases to Document-Oriented databases
PDF
Time Series Analysis:Basic Stochastic Signal Recovery
PPTX
parallel programming in the PVM-Reduction operation-advanced system architecture
PPTX
Bloom filters
PDF
On Beyond (PostgreSQL) Data Types
PPT
07 Retrieving Objects
PDF
Vectors data frames
 
PPTX
Image net classification with deep convolutional neural networks
PDF
Bloom filter
PDF
Appendix of downlink coverage probability in heterogeneous cellular networks ...
PDF
Dynomite Nosql
PDF
Gdc2011 direct x 11 rendering in battlefield 3
PPT
Applications of datastructures
A practical Introduction to Machine(s) Learning
NLP on a Billion Documents: Scalable Machine Learning with Apache Spark
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Machine(s) Learning with Neural Networks
Applicationof datastructures
最新のデータベース技術の方向性で思うこと
Nx tutorial basics
MongoDB Project: Relational databases to Document-Oriented databases
Time Series Analysis:Basic Stochastic Signal Recovery
parallel programming in the PVM-Reduction operation-advanced system architecture
Bloom filters
On Beyond (PostgreSQL) Data Types
07 Retrieving Objects
Vectors data frames
 
Image net classification with deep convolutional neural networks
Bloom filter
Appendix of downlink coverage probability in heterogeneous cellular networks ...
Dynomite Nosql
Gdc2011 direct x 11 rendering in battlefield 3
Applications of datastructures
Ad

Similar to Pyclustering tutorial - BANG (20)

PDF
Programming with Python and PostgreSQL
PDF
The Ring programming language version 1.9 book - Part 58 of 210
PPT
Generation of Deepfake images using GAN and Least squares GAN.ppt
PPTX
Module4_GAN.pptxgdgdijehejejjejejejhehjdd
PDF
Feature Engineering - Getting most out of data for predictive models
PPTX
Introduction to Deep Learning and Tensorflow
PPT
ECCV2010: feature learning for image classification, part 4
PPTX
PPT on Data Science Using Python
PDF
GANS Project for Image idetification.pdf
PPTX
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
PPTX
Bucket sort- A Noncomparision Algorithm
PPTX
Python for data analysis
PPTX
Working with images in matlab graphics
KEY
Mongo db勉強会20110730
PDF
Foreground detection using gaussian mixture models matlab
PDF
Feature Engineering - Getting most out of data for predictive models - TDC 2017
PPTX
python for data anal gh i o fytysis creation.pptx
PDF
PDF
Lab 1: Data cleaning, exploration, removal of outliers, Correlation of Contin...
PDF
The Ring programming language version 1.4 book - Part 14 of 30
Programming with Python and PostgreSQL
The Ring programming language version 1.9 book - Part 58 of 210
Generation of Deepfake images using GAN and Least squares GAN.ppt
Module4_GAN.pptxgdgdijehejejjejejejhehjdd
Feature Engineering - Getting most out of data for predictive models
Introduction to Deep Learning and Tensorflow
ECCV2010: feature learning for image classification, part 4
PPT on Data Science Using Python
GANS Project for Image idetification.pdf
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
Bucket sort- A Noncomparision Algorithm
Python for data analysis
Working with images in matlab graphics
Mongo db勉強会20110730
Foreground detection using gaussian mixture models matlab
Feature Engineering - Getting most out of data for predictive models - TDC 2017
python for data anal gh i o fytysis creation.pptx
Lab 1: Data cleaning, exploration, removal of outliers, Correlation of Contin...
The Ring programming language version 1.4 book - Part 14 of 30
Ad

Recently uploaded (20)

PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Artificial Intelligence
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Sustainable Sites - Green Building Construction
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Artificial Intelligence
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Sustainable Sites - Green Building Construction
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Foundation to blockchain - A guide to Blockchain Tech
Categorization of Factors Affecting Classification Algorithms Selection
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Internet of Things (IOT) - A guide to understanding
Fundamentals of Mechanical Engineering.pptx
Fundamentals of safety and accident prevention -final (1).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems

Pyclustering tutorial - BANG

  • 1. PyClustering: BANG Tutorial Pyclustering Library Tutorial Theme: BANG Library Version: 0.8.2 Author: Andrei Novikov E-Mail: [email protected]
  • 2. Agenda ● PyClustering BANG Features; ● Input format for BANG; ● Data clustering using BANG; ● Data clustering result visualization; ● Animation of BANG clustering process; ● Image segmentation by BANG;
  • 3. PyClustering BANG Features ● BANG algorithm provides clustering results that can be used for further analysis (not only clusters and noise itself): dendrogram, BANG directory - information about density distribution, structure, approximate amount of real clusters and influence of input argument on clustering results. ● BANG visualizer for clustering results, BANG directory and dendrogram. ● BANG animator for creating animation of BANG clustering process.
  • 4. Import BANG BANG algorithm and its features can be imported from „pyclustering.cluster.bang“: from pyclustering.cluster.bang import bang from pyclustering.cluster.bang import bang_directory from pyclustering.cluster.bang import bang_visualizer from pyclustering.cluster.bang import bang_animator
  • 5. Input data format for BANG BANG algorithm uses array_like data format, for example, list where each element is a point that is represented by coordinates. Here is an example of 1-D data: dataset = [ [0.25], [0.43], [1.34], [-0.56] ] Example of 2-D data: dataset = [ [0.1, 0.2], [0.1, 0.6], [0.2, -1.4] ] Example of 3-D data: dataset = [ [0.6, 0.1, 0.4], [0.2, 0.1, 0.9] ]
  • 6. Clustering by BANG algorithm BANG uses one general parameter for clustering: level of division that technically means amount of BANG tree hight where root is a cell that covers whole data. from pyclustering.cluster.bang import bang data = [ [0.1], [0.2], [0.5], [0.3], [1.5], [1.8], [1.3], [1.6], [1.5] ] levels = 3 instance = bang(data, levels) instance.process() # perform processing clusters = instance.get_clusters(); # allocated clusters noise = instance.get_noise(); # cluster noise directory = instance.get_directory(); # BANG directory dendrogram = instance.get_dendrogram() # BANG dendrogram
  • 7. Output result of BANG BANG algorithm returns allocated clusters, outliers (noise), BANG directory and dendrogram: ● Clusters are represented by list of clusters and each cluster contains object indexes from dataset. ● Outliers are represented by list of object indexes from dataset. ● BANG directory is a object of class bang_directory. ● Dendrogram is represented by list of dendrogram clusters where each cluster contains expand order of blocks that was formed during clustering process.
  • 8. BANG result visualization Output result such as clusters and outliers can be shown by common visualizer „cluster_visualizer“ from „pyclustering.cluster“ or by BANG visualizer: instance = bang(sample, levels) instance.process() clusters = instance.get_clusters() # allocated clusters noise = instance.get_noise() # outliers directory = instance.get_directory() # get BANG directory # visualize clustering results bang_visualizer.show_clusters(sample, clusters, noise) bang_visualizer.show_dendrogram(dendrogram) bang_visualizer.show_blocks(directory)
  • 9. BANG visualization – Lsun Visualization of BANG clustering results. Data: ‚Lsun‘. BANG blocks and their densities BANG dendrogram of three formed clusters Allocated clusters by BANG algorithm
  • 10. BANG visualization – Chainlink BANG visualizer is able to display clustering result of N- dimension data by forming pair xk, xl, where k, l – dimension indexes. BANG blocks representation in case 3-dimensional data
  • 11. BANG visualization - Target Visualization of BANG clustering results. Data: ‚Target‘. BANG blocks and their densities BANG dendrogram of three formed clusters Allocated clusters by BANG algorithm
  • 12. Animate BANG clustering process BANG clustering process can be animated (in case of 2- dimensional data) using services of class ‚bang_animator‘. instance = bang(data, levels, density_threshold) instance.process() # obtain BANG clustering result for creating animation clusters = instance.get_clusters() noise = instance.get_noise() directory = instance.get_directory() # show animation bang_animator(directory, clusters, noise).animate() # or save animation to file bang_animator(directory, clusters, noise).animate(movie_filename=bang.mp4)
  • 13. BANG for segmentation BANG can consider image as a data where each point represent pixel with three coordinate (RGB), or with four coordinate (RGBA). Here is an example of image segmentation using BANG algorithm: from pyclustering.utils import draw_image_mask_segments, read_image from pyclustering.cluster.bang import bang; data = read_image(file_path_to_image); bang_instance = bang(data, levels, density_threshold); bang_instance.process(); clusters = bang_instance.get_clusters(); draw_image_mask_segments(source, clusters);
  • 14. Image segmentation results Example of image segmentation of photo from St.- Petersburg by BANG algorithm using pyclustering. Shortcoming of BANG segmentation is not trivial way to set density Threshold, especially to handle Images with color gradient
  • 15. References and Links ● Official pyclustering github repository: https://github.com/annoviko/pyclustering ● Official pypi pyclustering page: https://pypi.org/project/pyclustering/ ● Official pyclustering web-site: https://pyclustering.github.io/
  • 16. Thank you for your attention Thank you!