def cluster_set(data_obj, centers, iterations, name):
    print(name)
    data_obj.labels = [0 for i in buildings.coords]
    clustering = deepcopy(data_obj)
    num = len(centers)
    print("A")
    #clustering.c_positions = [ trivial_gen.gauss_point(i,0.001) for i in centers]
    clustering.c_positions = centers
    clustering.c_number = num
    clustering = partitioning.k_means(clustering,
                                      initialisation="default_pos",
                                      iterations=iterations)
    visualise(clustering, name)

    print("B")
    comparison = deepcopy(data_obj)
    comparison.c_number = num
    comparison = partitioning.k_means(comparison,
                                      initialisation="kmeans_++",
                                      iterations=iterations)
    comparison.labes = [i + 1 for i in clustering.labels]

    out = {}
    out["number"] = len(centers)
    out["comparison"] = comparative.scikit_all_scores_dict(
        clustering, comparison)
    out["default_pos"] = standalone.standard_scores_dict(clustering)
    out["kmeans_++"] = standalone.standard_scores_dict(comparison)
    return out
Example #2
0
def test_on_random_sized():
    data_obj = trivial_gen.balanced_random_size_gauss_blobs(
        10.0, 2.0, 5, 100, 5, 0.5)
    data_obj = partitioning.k_means(data_obj)
    visu.plot_coords_label_color(data_obj)
    visu.plot_centers_by_label_color(data_obj)
    plt.show()
Example #3
0
def croissants():
    data = trivial_gen.croissants(100, 5.0, 0.5)
    visu.plot_coords_label_color(data)
    visu.plot_centers_by_label_color(data)
    plt.show()
    data = partitioning.k_means(data, initialisation="kmeans_++")
    visu.plot_coords_label_color(data)
    visu.plot_centers_by_label_color(data)
    plt.show()
Example #4
0
def test_rand_indexes_on_single_data(rand_test_data, initialisation, marker):
    rand_indexes = []
    for i in range(100):
        data_obj = deepcopy(rand_test_data)
        uncaught = True
        while uncaught:
            try:
                data_obj = partitioning.k_means(data_obj,
                                                initialisation=initialisation,
                                                iterations=10)
                rand_indexes.append(
                    comparative.scikit_rand_index(data_obj, rand_test_data))
                uncaught = False
            except ZeroDivisionError:
                uncaught = True
    rand_indexes.sort()
    plt.plot(list(range(100)), rand_indexes, marker, label=initialisation)
Example #5
0
def sample_process():
    data_obj = trivial_gen.balanced_multiple_gauss_blobs(5.0, 2.0, 10, 2, 0.6)
    _screenshot(data_obj)
    partitioning.k_means(data_obj, iterations=3, on_step=_screenshot)
Example #6
0
import py_osm_cluster.visualisation.visualisation as visu
import py_osm_cluster.visualisation.animation as anim
import matplotlib.pyplot as plt

parser = Parser("osm_data/krakow/krakow_center.osm")

all_buildings = parser.get_buildings_data_obj()
all_buildings.labels = [0 for i in all_buildings.coords]
churches = Coords()

for i in list(parser.ways.values()):
    if "building" in i.tags and i.tags["building"] == "church":
        churches.coords.append(list(i.geom.centroid.coords)[0])
churches.labels = [1 for i in churches.coords]

#print(churches)
#print(all_buildings)
all_buildings.c_number = len(churches.coords)

all_buildings.c_positions = churches.coords
all_buildings = partitioning.k_means(all_buildings,
                                     iterations=1,
                                     initialisation="default_pos")
print(all_buildings)
#all_buildings = partitioning.k_means(all_buildings,iterations=20,initialisation="kmeans_++")
#all_buildings = hierarchical.agglomerative(all_buildings,linkage="c-link")

visu.plot_coords_label_color(all_buildings)
visu.plot_coords_label_color(churches)
plt.show()
from py_osm_cluster.parser.parser import Parser

from py_osm_cluster.cluster import scikit
from py_osm_cluster.cluster import partitioning

from py_osm_cluster.eval import comparative as comparative
from py_osm_cluster.eval import standalone as standalone
from py_osm_cluster.cluster import hierarchical

import py_osm_cluster.visualisation.visualisation as visu
import py_osm_cluster.visualisation.animation as anim
import matplotlib.pyplot as plt

parser = Parser("osm_data/near_krakow/wegrzce_bibice.osm")

churches = Coords()
for i in list(parser.ways.values()):
	if "building" in i.tags and i.tags["building"]=="church":
		churches.coords.append(list(i.geom.centroid.coords)[0])
churches.labels = [1 for i in churches.coords]

data = parser.get_buildings_data_obj()
data.c_number = 10
data.labels =[0 for i in data.coords]
data = partitioning.k_means(data,initialisation="kmeans_++",iterations=25)

print(data)
visu.plot_coords_label_color(data)
visu.plot_coords_label_color(churches)
plt.show()
Example #8
0
import py_osm_cluster.visualisation.visualisation as visu
import matplotlib.pyplot as plt


def pront(data_obj,name):
	print("scikit_silhouette_score :"+str(standalone.scikit_silhouette_score(data_obj)))
	print("scikit_calinski_harabaz_score :"+str(standalone.scikit_calinski_harabaz_score(data_obj)))
	print("dunn_index :"+str(standalone.dunn_index(data_obj)))
	print(result_to_string(standalone.general_evaluate_clustered_object(data_obj)))
	visu.plot_coords_label_color(data_obj)
	visu.plot_centers_by_label_color(data_obj)
	plt.savefig(name+".png")
	plt.close()

def result_to_string(dictionary):
	out =""
	for key in dictionary:
		out = out + str(key) + "\n"
		for key_2 in dictionary[key]:
			out = out +"   " +str(key_2) + ": " + str(dictionary[key][key_2]) +"\n"
	return out

coords = trivial_gen.balanced_multiple_gauss_blobs(10.0,2.0,20,5,1.0)
pront(coords,"base")

print("!!!!!!!!!!!!!!!!!1")

newcoords = deepcopy(coords)
newcoords = partitioning.k_means(newcoords,initialisation="forgy")
pront(newcoords,"k_means")
from py_osm_cluster.util.coords import Coords as C
from py_osm_cluster.generator import trivial_gen as trivial_gen
from py_osm_cluster.eval import standalone as standalone

import py_osm_cluster.visualisation.visualisation as visu
import py_osm_cluster.visualisation.animation as anim
import matplotlib.pyplot as plt

from py_osm_cluster.cluster import partitioning

data_obj = C()
for i in range(3):
    for j in range(3):
        data_obj.coords.append((float(i), float(j)))
        data_obj.labels.append(i)
data_obj.c_number = 3

data_2 = trivial_gen.multiple_gauss_blobs(10.0, 20, 5, 0.5)
print(standalone.dunn_index(data_2))
visu.plot_coords_label_color(data_2)
plt.show()

data_2 = partitioning.k_means(data_2)
print(standalone.dunn_index(data_2))
visu.plot_coords_label_color(data_2)
plt.show()