Exemplo n.º 1
0
def template_clustering(number_clusters, path, links):
    sample = read_sample(path);
    
    clusters_centroid_link = None;
    clusters_single_link = None;
    clusters_complete_link = None;
    clusters_average_link = None;
    
    visualizer = cluster_visualizer(len(links));
    index_canvas = 0;
    
    if (type_link.CENTROID_LINK in links):
        agglomerative_centroid_link = agglomerative(sample, number_clusters, type_link.CENTROID_LINK);
        
        (ticks, result) = timedcall(agglomerative_centroid_link.process);
        clusters_centroid_link = agglomerative_centroid_link.get_clusters();
        
        visualizer.append_clusters(clusters_centroid_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Centroid', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Centroid", "\tExecution time: ", ticks, "\n");
    
    if (type_link.SINGLE_LINK in links):
        agglomerative_simple_link = agglomerative(sample, number_clusters, type_link.SINGLE_LINK);
        
        (ticks, result) = timedcall(agglomerative_simple_link.process);
        clusters_single_link = agglomerative_simple_link.get_clusters();
        
        visualizer.append_clusters(clusters_single_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Single', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Single", "\tExecution time: ", ticks, "\n");
    
    if (type_link.COMPLETE_LINK in links):
        agglomerative_complete_link = agglomerative(sample, number_clusters, type_link.COMPLETE_LINK);
        
        (ticks, result) = timedcall(agglomerative_complete_link.process);
        clusters_complete_link = agglomerative_complete_link.get_clusters();
        
        visualizer.append_clusters(clusters_complete_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Complete', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Complete", "\tExecution time: ", ticks, "\n");        
    
    if (type_link.AVERAGE_LINK in links):
        agglomerative_average_link = agglomerative(sample, number_clusters, type_link.AVERAGE_LINK);
        
        (ticks, result) = timedcall(agglomerative_average_link.process);
        clusters_average_link = agglomerative_average_link.get_clusters();
        
        visualizer.append_clusters(clusters_average_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Average', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Average", "\tExecution time: ", ticks, "\n");  
    
    visualizer.show();
def template_clustering(number_clusters, path, links):
    sample = read_sample(path);
    
    clusters_centroid_link = None;
    clusters_single_link = None;
    clusters_complete_link = None;
    clusters_average_link = None;
    
    visualizer = cluster_visualizer(len(links), len(links));
    index_canvas = 0;
    
    if (type_link.CENTROID_LINK in links):
        agglomerative_centroid_link = agglomerative(sample, number_clusters, type_link.CENTROID_LINK, True);
        
        (ticks, result) = timedcall(agglomerative_centroid_link.process);
        clusters_centroid_link = agglomerative_centroid_link.get_clusters();
        
        visualizer.append_clusters(clusters_centroid_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Centroid', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Centroid", "\tExecution time: ", ticks, "\n");
    
    if (type_link.SINGLE_LINK in links):
        agglomerative_simple_link = agglomerative(sample, number_clusters, type_link.SINGLE_LINK);
        
        (ticks, result) = timedcall(agglomerative_simple_link.process);
        clusters_single_link = agglomerative_simple_link.get_clusters();
        
        visualizer.append_clusters(clusters_single_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Single', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Single", "\tExecution time: ", ticks, "\n");
    
    if (type_link.COMPLETE_LINK in links):
        agglomerative_complete_link = agglomerative(sample, number_clusters, type_link.COMPLETE_LINK);
        
        (ticks, result) = timedcall(agglomerative_complete_link.process);
        clusters_complete_link = agglomerative_complete_link.get_clusters();
        
        visualizer.append_clusters(clusters_complete_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Complete', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Complete", "\tExecution time: ", ticks, "\n");
    
    if (type_link.AVERAGE_LINK in links):
        agglomerative_average_link = agglomerative(sample, number_clusters, type_link.AVERAGE_LINK);
        
        (ticks, result) = timedcall(agglomerative_average_link.process);
        clusters_average_link = agglomerative_average_link.get_clusters();
        
        visualizer.append_clusters(clusters_average_link, sample, index_canvas);
        visualizer.set_canvas_title('Link: Average', index_canvas);
        index_canvas += 1;
        
        print("Sample: ", path, "Link: Average", "\tExecution time: ", ticks, "\n");
    
    visualizer.show();
Exemplo n.º 3
0
def template_clustering(
        start_centers,
        path,
        tolerance=0.025,
        criterion=splitting_type.BAYESIAN_INFORMATION_CRITERION,
        ccore=False):
    sample = read_sample(path)
    start = time.clock()
    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion,
                             ccore)
    (ticks, _) = timedcall(xmeans_instance.process)

    # clusters = xmeans_instance.get_clusters()
    centers = xmeans_instance.get_centers()
    end = time.clock()
    print(end - start)

    criterion_string = "UNKNOWN"
    if criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION:
        criterion_string = "BAYESIAN INFORMATION CRITERION"
    elif criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH:
        criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH"

    print("Sample: ", ntpath.basename(path), "\nInitial centers: '",
          (start_centers is not None), "', Execution time: '", ticks,
          "', Number of clusters:", len(centers), ",", criterion_string, "\n")
Exemplo n.º 4
0
def planTrace_clustering(start_medoids,
                         data_points,
                         tolerance=0.25,
                         show=False):
    """
    :param start_medoids: is a list of indices, which correspond to the medoids
    :param data_points:
    :param tolerance:
    :param show:
    :return:
    """

    # todo note start mediods is represented by the data point index
    chosen_metric = metric.distance_metric(metric.type_metric.MANHATTAN)
    kmedoids_instance = kmedoids(data_points,
                                 start_medoids,
                                 tolerance,
                                 metric=chosen_metric)
    (ticks, result) = timedcall(kmedoids_instance.process)
    print("execution time in ticks = ", ticks)

    clusters = kmedoids_instance.get_clusters()
    medoids = kmedoids_instance.get_medoids()

    print("----finished clustering")

    # if show is True:
    #     visualizer = cluster_visualizer_multidim()
    #     visualizer.append_clusters(clusters, data_points, 0)
    #     visualizer.append_cluster([data_points[index] for index in start_medoids], marker='*', markersize=15)
    #     visualizer.append_cluster(medoids, data=data_points, marker='*', markersize=15)
    #     visualizer.show()

    return clusters, medoids
Exemplo n.º 5
0
def cluster(number_clusters, iterations, maxneighbours):
    data = read_sample('data.data')
    m_clarans = clarans(data, number_clusters, iterations, maxneighbours)
    (ticks, result) = timedcall(m_clarans.process)
    print("Execution time: ", ticks, "\n")
    clusters = m_clarans.get_clusters()
    draw_clusters(data, clusters)
Exemplo n.º 6
0
def template_clustering(
        number_clusters,
        path,
        branching_factor=5,
        max_node_entries=5,
        initial_diameter=0.0,
        type_measurement=measurement_type.AVERAGE_INTER_CLUSTER_DISTANCE,
        entry_size_limit=200,
        diameter_multiplier=1.5,
        show_result=True):
    sample = read_sample(path)

    birch_instance = birch(sample, number_clusters, branching_factor,
                           max_node_entries, initial_diameter,
                           type_measurement, entry_size_limit,
                           diameter_multiplier)
    (ticks, result) = timedcall(birch_instance.process)

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    clusters = birch_instance.get_clusters()

    if (show_result is True):
        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)
        visualizer.show()

    return (sample, clusters)
Exemplo n.º 7
0
def template_clustering(
        start_centers,
        path,
        tolerance=0.025,
        criterion=splitting_type.BAYESIAN_INFORMATION_CRITERION,
        ccore=False):
    sample = read_sample(path)

    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion,
                             ccore)
    (ticks, result) = timedcall(xmeans_instance.process)

    clusters = xmeans_instance.get_clusters()

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION):
        criterion_string = "BAYESIAN_INFORMATION_CRITERION"
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH):
        criterion_string = "MINIMUM_NOISELESS_DESCRIPTION_LENGTH"

    print("Sample: ", path, "\nInitial centers: '",
          (start_centers is not None), "', Execution time: '", ticks,
          "', Number of clusters:", len(clusters), ",", criterion_string, "\n")

    draw_clusters(sample, clusters)
Exemplo n.º 8
0
def template_clustering(
        start_centers,
        path,
        tolerance=0.025,
        criterion=splitting_type.BAYESIAN_INFORMATION_CRITERION,
        ccore=True):
    sample = read_sample(path)

    xmeans_instance = xmeans(sample,
                             start_centers,
                             20,
                             tolerance,
                             criterion,
                             ccore,
                             repeat=5)
    (ticks, _) = timedcall(xmeans_instance.process)

    clusters = xmeans_instance.get_clusters()
    centers = xmeans_instance.get_centers()

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION):
        criterion_string = "BAYESIAN INFORMATION CRITERION"
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH):
        criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH"

    print("Sample: ", ntpath.basename(path), "\nInitial centers: '",
          (start_centers is not None), "', Execution time: '", ticks,
          "', Number of clusters:", len(clusters), ",", criterion_string, "\n")

    visualizer = cluster_visualizer()
    visualizer.set_canvas_title(criterion_string)
    visualizer.append_clusters(clusters, sample)
    visualizer.append_cluster(centers, None, marker='*')
    visualizer.show()
Exemplo n.º 9
0
def clustering_random_points(amount, ccore):
    sample = [ [ random.random(), random.random() ] for _ in range(amount) ]
    
    dbscan_instance = dbscan(sample, 0.05, 20, ccore)
    (ticks, _) = timedcall(dbscan_instance.process)
    
    print("Execution time ("+ str(amount) +" 2D-points):", ticks)
Exemplo n.º 10
0
def template_clustering_random_points_performance(cluster_length,
                                                  amount_clusters, ccore_flag):
    sample = [[random.random(), random.random()]
              for _ in range(cluster_length)]
    for index in range(1, amount_clusters):
        default_offset = 5
        sample += [[
            random.random() + default_offset * index,
            random.random() + default_offset * index
        ] for _ in range(cluster_length)]

    initial_center = [[random.random(), random.random()],
                      [random.random(), random.random()]]

    ticks_array = []
    amount_measures = 5

    for _ in range(amount_measures):
        xmeans_instance = xmeans(sample, initial_center, 20, 0.25,
                                 splitting_type.BAYESIAN_INFORMATION_CRITERION,
                                 ccore_flag)
        (ticks, _) = timedcall(xmeans_instance.process)

        ticks_array.append(ticks)

    print(
        "Random sample: (size:" + str(len(sample)) + ") ', Execution time: '",
        sum(ticks_array) / amount_measures)
Exemplo n.º 11
0
def experiment_execution_one_cluster_dependence(layer_first_size, radius,
                                                order):
    print("Experiment: map size =", layer_first_size[0] * layer_first_size[1],
          "radius =", radius, "order =", order)
    cluster_sizes = [
        10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150
    ]

    for cluster_size in cluster_sizes:
        # generate data sets
        dataset = []
        dataset += [[random(), random()] for _ in range(cluster_size)]

        general_value = 0.0
        amount_attempt = 5
        for _ in range(amount_attempt):
            network = syncsom(dataset, layer_first_size[0],
                              layer_first_size[1], radius)
            (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, False,
                                                       order)
            general_value += ticks

        print("Sample: ", cluster_size, "\t\tExecution time: ",
              general_value / float(amount_attempt))

    print("\n")
Exemplo n.º 12
0
def template_clustering(start_medoids, path, tolerance=0.25, show=True):
    sample = read_sample(path)

    metric = distance_metric(type_metric.EUCLIDEAN_SQUARE, data=sample)
    kmedoids_instance = kmedoids(sample,
                                 start_medoids,
                                 tolerance,
                                 metric=metric)
    (ticks, result) = timedcall(kmedoids_instance.process)

    clusters = kmedoids_instance.get_clusters()
    medoids = kmedoids_instance.get_medoids()
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    if show is True:
        visualizer = cluster_visualizer(1)
        visualizer.append_clusters(clusters, sample, 0)
        visualizer.append_cluster([sample[index] for index in start_medoids],
                                  marker='*',
                                  markersize=15)
        visualizer.append_cluster(medoids,
                                  data=sample,
                                  marker='*',
                                  markersize=15)
        visualizer.show()

    return sample, clusters
def process_kmedoids(sample):
    instance = kmedoids(sample, [
        CURRENT_CLUSTER_SIZE * multiplier
        for multiplier in range(NUMBER_CLUSTERS)
    ])
    (ticks, _) = timedcall(instance.process)
    return ticks
Exemplo n.º 14
0
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 process_xmeans(sample):
    instance = xmeans(
        sample, [[random() + (multiplier * 5),
                  random() + (multiplier + 5)]
                 for multiplier in range(NUMBER_CLUSTERS)])
    (ticks, _) = timedcall(instance.process)
    return ticks
Exemplo n.º 16
0
def template_clustering(
        start_centers,
        path,
        tolerance=0.025,
        criterion=splitting_type.BAYESIAN_INFORMATION_CRITERION,
        ccore=False):
    sample = read_sample(
        '/home/tengmo/crawler_to_server_set_time/crawler/source_code_python2.7/cluster/test.txt'
    )

    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion,
                             ccore)
    (ticks, result) = timedcall(xmeans_instance.process)

    clusters = xmeans_instance.get_clusters()
    centers = xmeans_instance.get_centers()

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION):
        criterion_string = "BAYESIAN INFORMATION CRITERION"
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH):
        criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH"

    #print("Sample: ", path, "\nInitial centers: '", (start_centers is not None), "', Execution time: '", ticks, "', Number of clusters:", len(clusters), ",", criterion_string, "\n");
    print {'length': len(clusters), 'clus': clusters, 'cen': centers}
Exemplo n.º 17
0
def template_clustering(start_centers, path, tolerance=0.25, ccore=False):
    sample = read_sample(path)
    dimension = len(sample[0])

    metric = distance_metric(type_metric.MANHATTAN)

    observer = kmeans_observer()
    kmeans_instance = kmeans(sample,
                             start_centers,
                             tolerance,
                             ccore,
                             observer=observer,
                             metric=metric)
    (ticks, _) = timedcall(kmeans_instance.process)

    clusters = kmeans_instance.get_clusters()
    centers = kmeans_instance.get_centers()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    visualizer = cluster_visualizer_multidim()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()

    if dimension > 3:
        kmeans_visualizer.show_clusters(sample, clusters, centers,
                                        start_centers)
        kmeans_visualizer.animate_cluster_allocation(sample, observer)
Exemplo n.º 18
0
def template_clustering(file,
                        radius,
                        order,
                        show_dyn=False,
                        show_conn=False,
                        show_clusters=True,
                        ena_conn_weight=False,
                        ccore_flag=True,
                        tolerance=0.1):
    sample = read_sample(file)
    network = syncnet(sample,
                      radius,
                      enable_conn_weight=ena_conn_weight,
                      ccore=ccore_flag)

    (ticks, analyser) = timedcall(network.process, order, solve_type.FAST,
                                  show_dyn)
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n")

    if (show_dyn == True):
        sync_visualizer.show_output_dynamic(analyser)
        sync_visualizer.animate(analyser)
        #sync_visualizer.animate_output_dynamic(analyser);
        #sync_visualizer.animate_correlation_matrix(analyser, colormap = 'hsv');

    if ((show_conn == True) and (ccore_flag == False)):
        network.show_network()

    if (show_clusters == True):
        clusters = analyser.allocate_clusters(tolerance)
        print("amout of clusters: ", len(clusters))
        draw_clusters(sample, clusters)
Exemplo n.º 19
0
def template_clustering(file, map_size, radius, sync_order = 0.999, show_dyn = False, show_layer1 = False, show_layer2 = False, show_clusters = True):
    # Read sample
    sample = read_sample(file);

    # Create network
    network = syncsom(sample, map_size[0], map_size[1], radius);
    
    # Run processing
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, show_dyn, sync_order);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    # Show dynamic of the last layer.
    if (show_dyn == True):
        draw_dynamics(dyn_time, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 3.14]);
    
    if (show_clusters == True):
        clusters = network.get_som_clusters();
        
        visualizer = cluster_visualizer();
        visualizer.append_clusters(clusters, network.som_layer.weights);
        visualizer.show();
    
    # Show network stuff.
    if (show_layer1 == True):
        network.show_som_layer();
    
    if (show_layer2 == True):
        network.show_sync_layer();
    
    if (show_clusters == True):
        clusters = network.get_clusters();
        
        visualizer = cluster_visualizer();
        visualizer.append_clusters(clusters, sample);
        visualizer.show();
Exemplo n.º 20
0
def template_clustering(file, map_size, trust_order, sync_order = 0.999, show_dyn = False, show_layer1 = False, show_layer2 = False, show_clusters = True):
    # Read sample
    sample = read_sample(file);

    # Create network
    network = syncsom(sample, map_size[0], map_size[1]);
    
    # Run processing
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, trust_order, show_dyn, sync_order);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    # Show dynamic of the last layer.
    if (show_dyn == True):
        draw_dynamics(dyn_time, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
    
    if (show_clusters == True):
        clusters = network.get_som_clusters();
        draw_clusters(network.som_layer.weights, clusters);
    
    # Show network stuff.
    if (show_layer1 == True):
        network.show_som_layer();
    
    if (show_layer2 == True):
        network.show_sync_layer();
    
    if (show_clusters == True):
        clusters = network.get_clusters();
        draw_clusters(sample, clusters);
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
def template_clustering(number_clusters,
                        path,
                        number_represent_points=5,
                        compression=0.5,
                        draw=True,
                        ccore_flag=False):
    sample = read_sample(path)

    cure_instance = cure(sample, number_clusters, number_represent_points,
                         compression, ccore_flag)
    (ticks, _) = timedcall(cure_instance.process)

    clusters = cure_instance.get_clusters()
    representors = cure_instance.get_representors()
    means = cure_instance.get_means()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")
    #print([len(cluster) for cluster in clusters])

    if draw is True:
        visualizer = cluster_visualizer()

        visualizer.append_clusters(clusters, sample)

        for cluster_index in range(len(clusters)):
            visualizer.append_cluster_attribute(0, cluster_index,
                                                representors[cluster_index],
                                                '*', 10)
            visualizer.append_cluster_attribute(0, cluster_index,
                                                [means[cluster_index]], 'o')

        visualizer.show()
Exemplo n.º 23
0
def clustering_random_points(amount, ccore):
    sample = [ [ random.random(), random.random() ] for _ in range(amount) ];
    
    dbscan_instance = dbscan(sample, 0.05, 20, ccore);
    (ticks, _) = timedcall(dbscan_instance.process);
    
    print("Execution time ("+ str(amount) +" 2D-points):", ticks);
Exemplo n.º 24
0
def template_clustering(number_clusters,
                        path,
                        number_represent_points=5,
                        compression=0.5,
                        draw=True,
                        ccore_flag=False):
    sample = read_sample(path)

    cure_instance = cure(sample, number_clusters, number_represent_points,
                         compression, ccore_flag)
    (ticks, _) = timedcall(cure_instance.process)

    clusters = cure_instance.get_clusters()
    representors = cure_instance.get_representors()
    means = cure_instance.get_means()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    if (draw is True):
        visualizer = cluster_visualizer()

        if (ccore_flag is True):
            visualizer.append_clusters(clusters, sample)

        else:
            visualizer.append_clusters(clusters, None)

        visualizer.append_clusters(representors, marker='*', markersize=10)
        visualizer.append_clusters([means], None, marker='o')
        visualizer.show()
def template_clustering(radius,
                        neighb,
                        path,
                        invisible_axes=False,
                        ccore=True,
                        show=True):
    sample = read_sample(path)

    dbscan_instance = dbscan(sample, radius, neighb, ccore)
    (ticks, _) = timedcall(dbscan_instance.process)

    clusters = dbscan_instance.get_clusters()
    noise = dbscan_instance.get_noise()

    print([len(cluster) for cluster in clusters])

    if show:
        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)
        visualizer.append_cluster(noise, sample, marker='x')
        visualizer.show()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    return sample, clusters, noise
Exemplo n.º 26
0
def clustering_random_points(amount_points, amount_centers, ccore):
    sample = [ [ random.random(), random.random() ] for _ in range(amount_points) ]
    centers = [ [ random.random(), random.random() ] for _ in range(amount_centers) ]
    
    kmeans_instance = kmeans(sample, centers, 0.0001, ccore)
    (ticks, _) = timedcall(kmeans_instance.process)
    
    print("Execution time ("+ str(amount_points) +" 2D-points):", ticks)
def clustering_random_points(amount_points, amount_centers, ccore):
    sample = [ [ random.random(), random.random() ] for _ in range(amount_points) ]
    centers = [ [ random.random(), random.random() ] for _ in range(amount_centers) ]
    
    kmeans_instance = kmeans(sample, centers, 0.0001, ccore)
    (ticks, _) = timedcall(kmeans_instance.process)
    
    print("Execution time ("+ str(amount_points) +" 2D-points):", ticks)
Exemplo n.º 28
0
def template_clustering(number_clusters, path, iterations, maxneighbors):
    sample = read_sample(path);

    clarans_instance = clarans(sample, number_clusters, iterations, maxneighbors);
    (ticks, result) = timedcall(clarans_instance.process);

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    clusters = clarans_instance.get_clusters();
    draw_clusters(sample, clusters);
Exemplo n.º 29
0
def template_clustering(number_clusters, path, branching_factor = 5, max_node_entries = 5, initial_diameter = 0.0, type_measurement = measurement_type.CENTROID_EUCLIDIAN_DISTANCE, entry_size_limit = 200, ccore = True):
    sample = read_sample(path);

    birch_instance = birch(sample, number_clusters, branching_factor, max_node_entries, initial_diameter, type_measurement, entry_size_limit, ccore);
    (ticks, result) = timedcall(birch_instance.process);

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    clusters = birch_instance.get_clusters();
    draw_clusters(sample, clusters);
Exemplo n.º 30
0
def template_clustering(number_clusters, path, iterations, maxneighbors):
    sample = read_sample(path);

    clarans_instance = clarans(sample, number_clusters, iterations, maxneighbors);
    (ticks, result) = timedcall(clarans_instance.process);

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    clusters = clarans_instance.get_clusters();
    draw_clusters(sample, clusters);
Exemplo n.º 31
0
def template_clustering(number_clusters, path, branching_factor = 5, max_node_entries = 5, initial_diameter = 0.0, type_measurement = measurement_type.CENTROID_EUCLIDIAN_DISTANCE, entry_size_limit = 200, ccore = True):
    sample = read_sample(path);

    birch_instance = birch(sample, number_clusters, branching_factor, max_node_entries, initial_diameter, type_measurement, entry_size_limit, ccore)
    (ticks, result) = timedcall(birch_instance.process);

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    clusters = birch_instance.get_clusters();
    draw_clusters(sample, clusters);
def template_clustering(start_medians, path, tolerance=0.25):
    sample = read_sample(path)

    kmedians_instance = kmedians(sample, start_medians, tolerance)
    (ticks, result) = timedcall(kmedians_instance.process)

    clusters = kmedians_instance.get_clusters()
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    draw_clusters(sample, clusters)
Exemplo n.º 33
0
def template_clustering(start_centers, path, tolerance = 0.25):
    sample = read_sample(path);
    
    kmedians_instance = kmedians(sample, start_centers, tolerance);
    (ticks, result) = timedcall(kmedians_instance.process);
    
    clusters = kmedians_instance.get_clusters();
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    draw_clusters(sample, clusters);
Exemplo n.º 34
0
def template_clustering_performance(start_centers, path, tolerance = 0.025, criterion = splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore = False):
    sample = read_sample(path)
    
    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion, ccore)
    (ticks, _) = timedcall(xmeans_instance.process)

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION): criterion_string = "BAYESIAN INFORMATION CRITERION";
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH): criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH";
    
    print("Sample: ", ntpath.basename(path), "', Execution time: '", ticks, "',", criterion_string)
def template_clustering_performance(start_centers, path, tolerance = 0.025, criterion = splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore = False):
    sample = read_sample(path)
    
    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion, ccore)
    (ticks, _) = timedcall(xmeans_instance.process)

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION): criterion_string = "BAYESIAN INFORMATION CRITERION";
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH): criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH";
    
    print("Sample: ", ntpath.basename(path), "', Execution time: '", ticks, "',", criterion_string)
Exemplo n.º 36
0
def template_clustering(path, radius, cluster_numbers, threshold, draw = True, ccore = True):
    sample = read_sample(path);
    
    rock_instance = rock(sample, radius, cluster_numbers, threshold, ccore);
    (ticks, result) = timedcall(rock_instance.process);
    
    clusters = rock_instance.get_clusters();
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");
    
    if (draw == True):
        draw_clusters(sample, clusters);
def template_segmentation_image(source, map_som_size = [5, 5], radius = 128.0, sync_order = 0.998, show_dyn = False, show_som_map = False):
    data = read_image(source);
    
    network = syncsom(data, map_som_size[0], map_som_size[1], 1.0);
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, show_dyn, sync_order);
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\t\tWinners: ", network.som_layer.get_winner_number(), "\n");
    
    if (show_dyn is True):
        draw_dynamics(dyn_time, dyn_phase);
    
    clusters = network.get_clusters();
    draw_image_mask_segments(source, clusters);
Exemplo n.º 38
0
def template_segmentation_image(source, map_som_size = [5, 5], average_neighbors = 5, sync_order = 0.998, show_dyn = False, show_som_map = False):
    data = read_image(source);
    
    network = syncsom(data, map_som_size[0], map_som_size[1]);
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, average_neighbors, show_dyn, sync_order);
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\t\tWinners: ", network.som_layer.get_winner_number(), "\n");
    
    if (show_dyn is True):
        draw_dynamics(dyn_time, dyn_phase);
    
    clusters = network.get_clusters();
    draw_image_mask_segments(source, clusters);
Exemplo n.º 39
0
def template_clustering(path, amount_clusters, epouch=100, ccore=True):
    sample = read_sample(path)

    somsc_instance = somsc(sample, amount_clusters, epouch, ccore)
    (ticks, _) = timedcall(somsc_instance.process)

    clusters = somsc_instance.get_clusters()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()
Exemplo n.º 40
0
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, initial_neighbors = int(len(sample) * 0.15), osc_initial_phases = initial_type.EQUIPARTITION, ccore = ccore_flag);
        
        (ticks, analyser) = timedcall(network.process, arg_order, solve_type.FAST, arg_collect_dynamic);
        print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
        
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
Exemplo n.º 41
0
def template_clustering(number_clusters, path, number_represent_points = 5, compression = 0.5, draw = True, ccore_flag = False):
    sample = read_sample(path);
    
    cure_instance = cure(sample, number_clusters, number_represent_points, compression, ccore_flag);
    (ticks, result) = timedcall(cure_instance.process);
    clusters = cure_instance.get_clusters();
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    if (draw is True):
        if (ccore_flag is True):
            draw_clusters(sample, clusters);
        else:
            draw_clusters(None, clusters);
Exemplo n.º 42
0
def template_clustering(radius, neighb, path, invisible_axes = False, ccore = True):
    sample = read_sample(path);
    
    dbscan_instance = dbscan(sample, radius, neighb, ccore);
    (ticks, result) = timedcall(dbscan_instance.process);
    
    clusters = dbscan_instance.get_clusters();
    noise = dbscan_instance.get_noise();
    
    visualizer = cluster_visualizer();
    visualizer.append_clusters(clusters, sample);
    visualizer.append_cluster(noise, sample, marker = 'x');
    visualizer.show();
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");
Exemplo n.º 43
0
def template_clustering(start_medoids, path, tolerance = 0.25, show = True):
    sample = read_sample(path);
    
    kmedoids_instance = kmedoids(sample, start_medoids, tolerance);
    (ticks, result) = timedcall(kmedoids_instance.process);
    
    clusters = kmedoids_instance.get_clusters();
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    if (show is True):
        visualizer = cluster_visualizer(1);
        visualizer.append_clusters(clusters, sample, 0);
        visualizer.show();
    
    return (sample, clusters);
Exemplo n.º 44
0
def template_clustering(start_centers, path, tolerance = 0.025, criterion = splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore = False):
    sample = read_sample(path);
    
    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion, ccore);
    (ticks, result) = timedcall(xmeans_instance.process);
    
    clusters = xmeans_instance.get_clusters();

    criterion_string = "UNKNOWN";
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION): criterion_string = "BAYESIAN_INFORMATION_CRITERION";
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH): criterion_string = "MINIMUM_NOISELESS_DESCRIPTION_LENGTH";
    
    print("Sample: ", path, "\tExecution time: ", ticks, "Number of clusters: ", len(clusters), criterion_string, "\n");

    draw_clusters(sample, clusters);
Exemplo n.º 45
0
def template_clustering(number_clusters, path, branching_factor = 5, max_node_entries = 5, initial_diameter = 0.0, type_measurement = measurement_type.AVERAGE_INTER_CLUSTER_DISTANCE, entry_size_limit = 200, diameter_multiplier = 1.5, show_result = True):
    sample = read_sample(path);

    birch_instance = birch(sample, number_clusters, branching_factor, max_node_entries, initial_diameter, type_measurement, entry_size_limit, diameter_multiplier);
    (ticks, result) = timedcall(birch_instance.process);

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");

    clusters = birch_instance.get_clusters();
    
    if (show_result is True):
        visualizer = cluster_visualizer();
        visualizer.append_clusters(clusters, sample);
        visualizer.show();
    
    return (sample, clusters);
Exemplo n.º 46
0
def template_clustering(start_centers, path, tolerance=0.25, ccore=True):
    sample = read_sample(path)

    kmeans_instance = kmeans(sample, start_centers, tolerance, ccore)
    (ticks, result) = timedcall(kmeans_instance.process)

    clusters = kmeans_instance.get_clusters()
    centers = kmeans_instance.get_centers()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, sample)
    visualizer.append_cluster(start_centers, marker="*", markersize=20)
    visualizer.append_cluster(centers, marker="*", markersize=20)
    visualizer.show()
Exemplo n.º 47
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True, tolerance = 0.1):
    sample = read_sample(file);
    network = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag);
    
    (ticks, analyser) = timedcall(network.process, order, solve_type.FAST, show_dyn);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn == True):
        sync_visualizer.show_output_dynamic(analyser);
        sync_visualizer.animate_output_dynamic(analyser);
    
    if ( (show_conn == True) and (ccore_flag == False) ):
        network.show_network();
    
    if (show_clusters == True):
        clusters = analyser.allocate_clusters(tolerance);
        draw_clusters(sample, clusters);
Exemplo n.º 48
0
def template_clustering(start_medoids, path, tolerance = 0.25, show = True):
    sample = read_sample(path)
    
    kmedoids_instance = kmedoids(sample, start_medoids, tolerance)
    (ticks, result) = timedcall(kmedoids_instance.process)
    
    clusters = kmedoids_instance.get_clusters()
    medoids = kmedoids_instance.get_medoids()
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    if show is True:
        visualizer = cluster_visualizer(1)
        visualizer.append_clusters(clusters, sample, 0)
        visualizer.append_cluster([sample[index] for index in start_medoids], marker='*', markersize=15)
        visualizer.append_cluster(medoids, data=sample, marker='*', markersize=15)
        visualizer.show()
    
    return sample, clusters
Exemplo n.º 49
0
def experiment_execution_one_cluster_dependence(layer_first_size, radius, order):
    print("Experiment: map size =", layer_first_size[0] * layer_first_size[1], "radius =", radius, "order =", order);
    cluster_sizes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150];
    
    for cluster_size in cluster_sizes:
        # generate data sets
        dataset = [];
        dataset += [ [random(), random()] for _ in range(cluster_size) ];
        
        general_value = 0.0;
        amount_attempt = 5;
        for _ in range(amount_attempt):
            network = syncsom(dataset, layer_first_size[0], layer_first_size[1], radius);
            (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, False, order);
            general_value += ticks;
                
        print("Sample: ", cluster_size, "\t\tExecution time: ", general_value / float(amount_attempt));
        
    print("\n");
Exemplo n.º 50
0
def template_clustering_random_points_performance(cluster_length, amount_clusters, ccore_flag):
    sample = [ [ random.random(), random.random() ] for _ in range(cluster_length) ]
    for index in range(1, amount_clusters):
        default_offset = 5
        sample += [ [ random.random() + default_offset * index, random.random() + default_offset * index ] for _ in range(cluster_length) ]
    
    initial_center = [ [ random.random(), random.random() ], [ random.random(), random.random() ] ]
    xmeans_instance = xmeans(sample, initial_center, 20, 0.25, splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore_flag)
    
    ticks_array = []
    amount_measures = 5
    
    for _ in range(amount_measures):
        xmeans_instance = xmeans(sample, initial_center, 20, 0.25, splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore_flag)
        (ticks, _) = timedcall(xmeans_instance.process)
        
        ticks_array.append(ticks)
    
    print("Random sample: (size:" + str(len(sample)) + ") ', Execution time: '", sum(ticks_array) / amount_measures)
Exemplo n.º 51
0
def template_clustering(start_centers, path, tolerance = 0.025, criterion = splitting_type.BAYESIAN_INFORMATION_CRITERION, ccore = False):
    sample = read_sample(path)
    
    xmeans_instance = xmeans(sample, start_centers, 20, tolerance, criterion, ccore)
    (ticks, _) = timedcall(xmeans_instance.process)
    
    clusters = xmeans_instance.get_clusters()
    centers = xmeans_instance.get_centers()

    criterion_string = "UNKNOWN"
    if (criterion == splitting_type.BAYESIAN_INFORMATION_CRITERION): criterion_string = "BAYESIAN INFORMATION CRITERION";
    elif (criterion == splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH): criterion_string = "MINIMUM NOISELESS DESCRIPTION_LENGTH";
    
    print("Sample: ", ntpath.basename(path), "\nInitial centers: '", (start_centers is not None), "', Execution time: '", ticks, "', Number of clusters:", len(clusters), ",", criterion_string, "\n")

    visualizer = cluster_visualizer()
    visualizer.set_canvas_title(criterion_string)
    visualizer.append_clusters(clusters, sample)
    visualizer.append_cluster(centers, None, marker = '*')
    visualizer.show()
Exemplo n.º 52
0
def template_clustering(radius, neighb, path, invisible_axes = False, ccore = True, show = True):
    sample = read_sample(path)
    
    dbscan_instance = dbscan(sample, radius, neighb, ccore)
    (ticks, _) = timedcall(dbscan_instance.process)
    
    clusters = dbscan_instance.get_clusters()
    noise = dbscan_instance.get_noise()
    
    print([len(cluster) for cluster in clusters])
    
    if show:
        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)
        visualizer.append_cluster(noise, sample, marker = 'x')
        visualizer.show()
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")
    
    return sample, clusters, noise
Exemplo n.º 53
0
def template_clustering(start_centers, path, tolerance = 0.25, ccore = False):
    sample = read_sample(path)
    dimension = len(sample[0])

    metric = distance_metric(type_metric.MANHATTAN)

    observer = kmeans_observer()
    kmeans_instance = kmeans(sample, start_centers, tolerance, ccore, observer=observer, metric=metric)
    (ticks, _) = timedcall(kmeans_instance.process)
    
    clusters = kmeans_instance.get_clusters()
    centers = kmeans_instance.get_centers()
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    visualizer = cluster_visualizer_multidim()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()

    if dimension > 3:
        kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers)
        kmeans_visualizer.animate_cluster_allocation(sample, observer)
Exemplo n.º 54
0
def template_clustering(number_clusters, path, number_represent_points=5, compression=0.5, draw=True, ccore_flag=True):
    sample = read_sample(path)
    
    cure_instance = cure(sample, number_clusters, number_represent_points, compression, ccore_flag)
    (ticks, _) = timedcall(cure_instance.process)
    
    clusters = cure_instance.get_clusters()
    representors = cure_instance.get_representors()
    means = cure_instance.get_means()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")
    #print([len(cluster) for cluster in clusters])

    if draw is True:
        visualizer = cluster_visualizer()

        visualizer.append_clusters(clusters, sample)

        for cluster_index in range(len(clusters)):
            visualizer.append_cluster_attribute(0, cluster_index, representors[cluster_index], '*', 10)
            visualizer.append_cluster_attribute(0, cluster_index, [ means[cluster_index] ], 'o')

        visualizer.show()
Exemplo n.º 55
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True, tolerance = 0.1):
    sample = read_sample(file)
    syncnet_instance = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag)

    (ticks, analyser) = timedcall(syncnet_instance.process, order, solve_type.FAST, show_dyn)
    print("Sample: ", file, "\t\tExecution time: ", ticks)

    if show_dyn == True:
        sync_visualizer.show_output_dynamic(analyser)
        sync_visualizer.animate(analyser)
        sync_visualizer.show_local_order_parameter(analyser, syncnet_instance)
        #sync_visualizer.animate_output_dynamic(analyser);
        #sync_visualizer.animate_correlation_matrix(analyser, colormap = 'hsv')
     
    if show_conn == True:
        syncnet_instance.show_network()
     
    if show_clusters == True:
        clusters = analyser.allocate_clusters(tolerance)
        print("Amount of allocated clusters: ", len(clusters))
        draw_clusters(sample, clusters)
    
    print("----------------------------\n")
    return (sample, clusters)
Exemplo n.º 56
0
def template_segmentation_image(source, color_radius, object_radius, noise_size, show_dyn):    
    data = read_image(source);
    print("Pixel dimension: ", len(data[0]));

    network = syncnet(data, color_radius, ccore = True);
    print("Network has been created");
    
    (ticks, analyser) = timedcall(network.process, 0.9995, solve_type.FAST, show_dyn);
    
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn is True):
        sync_visualizer.show_output_dynamic(analyser);
    
    clusters = analyser.allocate_clusters();
    real_clusters = [cluster for cluster in clusters if len(cluster) > noise_size];
    
    draw_image_mask_segments(source, real_clusters);
    
    if (object_radius is None):
        return;
    
    # continue analysis
    pointer_image = Image.open(source);
    image_size = pointer_image.size;
    
    object_colored_clusters = [];
    object_colored_dynamics = [];
    total_dyn = [];
    
    for cluster in clusters:
        coordinates = [];
        for index in cluster:
            y = floor(index / image_size[0]);
            x = index - y * image_size[0];
            
            coordinates.append([x, y]);
        
        print(coordinates);
        
        # perform clustering analysis of the colored objects
        if (network is not None):
            del network;
            network = None;
        
        if (len(coordinates) < noise_size):
            continue;
        
        network = syncnet(coordinates, object_radius, ccore = True);
        analyser = network.process(0.999, solve_type.FAST, show_dyn);
        
        if (show_dyn is True):
            object_colored_dynamics.append( (analyser.time, analyser.output) );
        
        object_clusters = analyser.allocate_clusters();
        
        # decode it
        real_description_clusters = [];
        for object_cluster in object_clusters:
            real_description = [];
            for index_object in object_cluster:
                real_description.append(cluster[index_object]);
            
            real_description_clusters.append(real_description);
            
            if (len(real_description) > noise_size):
                object_colored_clusters.append(real_description);
            
        # draw_image_mask_segments(source, [ cluster ]);
        # draw_image_mask_segments(source, real_description_clusters);
    
    draw_image_mask_segments(source, object_colored_clusters);
    
    if (show_dyn is True):
        draw_dynamics_set(object_colored_dynamics, None, None, None, [0, 2 * 3.14], False, False);
Exemplo n.º 57
0
def process_syncnet(sample):
    instance = syncnet(sample, 3.0, initial_phases = initial_type.EQUIPARTITION)
    (ticks, _) = timedcall(instance.process)
    return ticks
Exemplo n.º 58
0
def process_syncsom(sample):
    instance = syncsom(sample, 1, NUMBER_CLUSTERS)
    (ticks, _) = timedcall(instance.process, 0, False, 0.998)
    return ticks
Exemplo n.º 59
0
def process_xmeans(sample):
    instance = xmeans(sample, [ [random() + (multiplier * 5), random() + (multiplier + 5)] for multiplier in range(NUMBER_CLUSTERS) ])
    (ticks, _) = timedcall(instance.process)
    return ticks