1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
"""!
@brief Examples of usage and demonstration of abilities of OPTICS algorithm in cluster analysis.
@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause
"""
import random
from pyclustering.cluster import cluster_visualizer
from pyclustering.cluster.optics import optics, ordering_analyser, ordering_visualizer
from pyclustering.utils import read_sample, timedcall
from pyclustering.samples.definitions import SIMPLE_SAMPLES, FCPS_SAMPLES
def template_clustering(path_sample, eps, minpts, amount_clusters = None, visualize = True, ccore = False):
sample = read_sample(path_sample)
optics_instance = optics(sample, eps, minpts, amount_clusters, ccore)
(ticks, _) = timedcall(optics_instance.process)
print("Sample: ", path_sample, "\t\tExecution time: ", ticks, "\n")
if (visualize is True):
clusters = optics_instance.get_clusters()
noise = optics_instance.get_noise()
visualizer = cluster_visualizer()
visualizer.append_clusters(clusters, sample)
visualizer.append_cluster(noise, sample, marker = 'x')
visualizer.show()
ordering = optics_instance.get_ordering()
analyser = ordering_analyser(ordering)
ordering_visualizer.show_ordering_diagram(analyser, amount_clusters)
def cluster_sample1():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 0.5, 3)
def cluster_sample2():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 3.0, 3)
def cluster_sample3():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 0.7, 3)
def cluster_sample4():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 0.7, 3)
def cluster_sample5():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 0.7, 3)
def cluster_sample6():
template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE6, 1.0, 3)
def cluster_elongate():
template_clustering(SIMPLE_SAMPLES.SAMPLE_ELONGATE, 0.5, 3)
def cluster_lsun():
template_clustering(FCPS_SAMPLES.SAMPLE_LSUN, 0.5, 3)
def cluster_lsun_radius_calculation():
template_clustering(FCPS_SAMPLES.SAMPLE_LSUN, 1.0, 3, 3)
def cluster_target():
template_clustering(FCPS_SAMPLES.SAMPLE_TARGET, 0.5, 2)
def cluster_target_radius_calculation():
template_clustering(FCPS_SAMPLES.SAMPLE_TARGET, 10.0, 2, 6)
def cluster_two_diamonds():
template_clustering(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 0.15, 7)
def cluster_two_diamonds_radius_calculation():
template_clustering(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 1.0, 7, 2)
def cluster_wing_nut():
template_clustering(FCPS_SAMPLES.SAMPLE_WING_NUT, 0.25, 2)
def cluster_wing_nut_radius_calculation():
template_clustering(FCPS_SAMPLES.SAMPLE_WING_NUT, 1.0, 2, 2)
def cluster_chainlink():
template_clustering(FCPS_SAMPLES.SAMPLE_CHAINLINK, 0.15, 3)
def cluster_hepta():
template_clustering(FCPS_SAMPLES.SAMPLE_HEPTA, 1, 3)
def cluster_golf_ball():
template_clustering(FCPS_SAMPLES.SAMPLE_GOLF_BALL, 0.5, 3)
def cluster_atom():
template_clustering(FCPS_SAMPLES.SAMPLE_ATOM, 15, 3)
def cluster_tetra():
template_clustering(FCPS_SAMPLES.SAMPLE_TETRA, 0.4, 3)
def cluster_engy_time():
template_clustering(FCPS_SAMPLES.SAMPLE_ENGY_TIME, 0.2, 20)
def experiment_execution_time(ccore):
template_clustering(FCPS_SAMPLES.SAMPLE_LSUN, 1.0, 3, 3, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_TARGET, 10.0, 2, 6, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 1.0, 7, 2, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_CHAINLINK, 2.0, 3, 2, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_WING_NUT, 1.0, 2, 2, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_HEPTA, 1, 3, None, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_TETRA, 1.0, 3, 4, False, ccore)
template_clustering(FCPS_SAMPLES.SAMPLE_ATOM, 30, 3, 2, False, ccore)
def clustering_random_points(amount, ccore):
sample = [ [ random.random(), random.random() ] for _ in range(amount) ]
optics_instance = optics(sample, 0.05, 20, None, ccore)
(ticks, _) = timedcall(optics_instance.process)
print("Execution time ("+ str(amount) +" 2D-points):", ticks)
def performance_measure_random_points(ccore):
clustering_random_points(1000, ccore)
clustering_random_points(2000, ccore)
clustering_random_points(3000, ccore)
clustering_random_points(4000, ccore)
clustering_random_points(5000, ccore)
clustering_random_points(10000, ccore)
clustering_random_points(20000, ccore)
cluster_sample1()
cluster_sample2()
cluster_sample3()
cluster_sample4()
cluster_sample5()
cluster_sample6()
cluster_elongate()
cluster_lsun()
cluster_lsun_radius_calculation()
cluster_target()
cluster_target_radius_calculation()
cluster_two_diamonds()
cluster_two_diamonds_radius_calculation()
cluster_wing_nut()
cluster_wing_nut_radius_calculation()
cluster_chainlink()
cluster_hepta()
cluster_golf_ball()
cluster_atom()
cluster_tetra()
cluster_engy_time()
experiment_execution_time(False)
experiment_execution_time(True)
performance_measure_random_points(False)
performance_measure_random_points(True)
|