pyclustering.container.kdtree.kdtree_visualizer Class Reference

KD-tree visualizer that provides service to display graphical representation of the tree using matplotlib library. More...

Public Member Functions

def __init__ (self, kdtree_instance)
 Initialize KD-tree visualizer. More...
 
def visualize (self)
 Visualize KD-tree using plot in 2-dimensional data-space.
 

Detailed Description

KD-tree visualizer that provides service to display graphical representation of the tree using matplotlib library.

The visualizer is able to visualize 2D KD-trees only.

There is an example how to visualize balanced KD-tree for TwoDiamonds sample using kdtree_visualizer:

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_TWO_DIAMONDS)
tree_instance = kdtree_balanced(sample)
kdtree_visualizer(tree_instance).visualize()

Output result of the example above (balanced tree) - figure 1:

kd_tree_unbalanced_two_diamonds.png
Fig. 1. Balanced KD-tree for sample 'TwoDiamonds'.

There is one more example to demonstrate unbalanced KD-tree. kdtree class is child class of kdtree_balanced that allows to add points step by step and thus an unbalanced KD-tree can be built.

from pyclustering.container.kdtree import kdtree, kdtree_visualizer
from pyclustering.utils import read_sample
from pyclustering.samples.definitions import FCPS_SAMPLES
sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
tree_instance = kdtree() # Do not use sample in constructor to avoid building of balanced tree.
# Fill KD-tree step by step to obtain unbalanced tree.
for point in sample:
tree_instance.insert(point)
kdtree_visualizer(tree_instance).visualize()

Output result of the example above (unbalanced tree) - figure 2:

kd_tree_unbalanced_two_diamonds.png
Fig. 2. Unbalanced KD-tree for sample 'TwoDiamonds'.

Definition at line 40 of file kdtree.py.

Constructor & Destructor Documentation

◆ __init__()

def pyclustering.container.kdtree.kdtree_visualizer.__init__ (   self,
  kdtree_instance 
)

Initialize KD-tree visualizer.

Parameters
[in]kdtree_instance(kdtree): Instance of a KD-tree that should be visualized.

Definition at line 83 of file kdtree.py.


The documentation for this class was generated from the following file: