示例#1
0
    def templateLengthProcessData(self, file, som_map_size, avg_num_conn, eps,
                                  expected_cluster_length):
        result_testing = False

        # If phases crosses each other because of random part of the network then we should try again.
        for attempt in range(0, 3, 1):
            sample = read_sample(file)
            network = syncsom(sample, som_map_size[0], som_map_size[1])
            network.process(avg_num_conn, collect_dynamic=False, order=eps)

            clusters = network.get_clusters()

            obtained_cluster_sizes = [len(cluster) for cluster in clusters]
            if (len(sample) != sum(obtained_cluster_sizes)):
                continue

            obtained_cluster_sizes.sort()
            expected_cluster_length.sort()
            #print(obtained_cluster_sizes, expected_cluster_length);
            if (obtained_cluster_sizes != expected_cluster_length):
                continue

            # Unit-test is passed
            result_testing = True
            break

        assert result_testing
 def templateClustering(self, file, radius, order, solver, initial, storage_flag, conn_weigh_flag, tolerance, connection, expected_cluster_length, ccore_flag):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):
         sample = read_sample(file);
         network = syncnet(sample, radius, connection, initial, conn_weigh_flag, ccore_flag);
         network.process(order, solver, storage_flag);
         
         clusters = network.get_clusters(tolerance);
         
         obtained_cluster_sizes = [len(cluster) for cluster in clusters];
 
         if (len(obtained_cluster_sizes) != len(expected_cluster_length)):
             continue;
         
         obtained_cluster_sizes.sort();
         expected_cluster_length.sort();
         
         if (obtained_cluster_sizes != expected_cluster_length):
             continue;
         
         # Unit-test is passed
         result_testing = True;
         break;
     
     assert result_testing;
示例#3
0
def template_clustering(file,
                        radius,
                        order,
                        show_dyn=False,
                        show_conn=False,
                        show_clusters=True,
                        ena_conn_weight=False,
                        ccore_flag=False):
    sample = read_sample(file)
    network = syncnet(sample,
                      radius,
                      enable_conn_weight=ena_conn_weight,
                      ccore=ccore_flag)

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

    if (show_dyn == True):
        draw_dynamics(dyn_time,
                      dyn_phase,
                      x_title="Time",
                      y_title="Phase",
                      y_lim=[0, 2 * 3.14])

    if (show_conn == True):
        network.show_network()

    if (show_clusters == True):
        clusters = network.get_clusters(0.1)
        draw_clusters(sample, clusters)
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();
示例#5
0
 def templateLengthProcessData(self, file, som_map_size, avg_num_conn, eps, expected_cluster_length):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):
         sample = read_sample(file);
         network = syncsom(sample, som_map_size[0], som_map_size[1]);
         network.process(avg_num_conn, collect_dynamic = False, order = eps);
         
         clusters = network.get_clusters();
         
         obtained_cluster_sizes = [len(cluster) for cluster in clusters];
         if (len(sample) != sum(obtained_cluster_sizes)):
             continue;
         
         obtained_cluster_sizes.sort();
         expected_cluster_length.sort();
         #print(obtained_cluster_sizes, expected_cluster_length);
         if (obtained_cluster_sizes != expected_cluster_length):
             continue;
         
         # Unit-test is passed
         result_testing = True;
         break;
         
     assert result_testing;
    def templateClustering(self, path, number_clusters,
                           expected_length_clusters, solver, ccore_flag):
        result_testing = False

        # If phases crosses each other because of random part of the network then we should try again.
        for attempt in range(0, 3, 1):
            sample = read_sample(path)
            network = hsyncnet(sample,
                               number_clusters,
                               initial_type.EQUIPARTITION,
                               ccore=ccore_flag)
            # EQUIPARTITION - makes test more stable.

            (t, d) = network.process(order=0.997,
                                     solution=solver,
                                     collect_dynamic=True)
            clusters = network.get_clusters()

            if (sum([len(cluster) for cluster in clusters]) !=
                    sum(expected_length_clusters)):
                continue

            if (sorted([len(cluster)
                        for cluster in clusters]) != expected_length_clusters):
                if (sorted([len(cluster) for cluster in clusters]) !=
                        expected_length_clusters):
                    continue

            # Unit-test is passed
            result_testing = True
            break

        assert result_testing
示例#7
0
def template_self_organization(file,
                               rows,
                               cols,
                               time,
                               structure,
                               init_type=None,
                               init_radius=None,
                               init_rate=None,
                               umatrix=False,
                               pmatrix=False,
                               awards=False):
    parameters = som_parameters()

    if (init_type is not None):
        parameters.init_type = init_type
    if (init_radius is not None):
        parameters.init_radius = init_radius
    if (init_rate is not None):
        parameters.init_learn_rate = init_rate

    sample = read_sample(file)
    network = som(rows, cols, sample, time, structure, parameters, True)
    network.train()
    network.show_network(False, dataset=False)

    if (umatrix is True):
        network.show_distance_matrix()

    if (pmatrix is True):
        network.show_density_matrix()

    if (awards is True):
        network.show_winner_matrix()
示例#8
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_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()
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    draw_clusters(sample, clusters)
示例#10
0
def template_clustering(number_clusters, path, ccore=True):
    sample = read_sample(path)

    hierarchical_instance = hierarchical(sample, number_clusters, ccore)
    (ticks, result) = timedcall(hierarchical_instance.process)

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

    clusters = hierarchical_instance.get_clusters()
    draw_clusters(sample, clusters)
def template_clustering(start_medoids, path, tolerance = 0.25):
    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");

    draw_clusters(sample, clusters);
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, ccore = ccore_flag);
        
        analyser = network.process(arg_order, collect_dynamic = arg_collect_dynamic);
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
 def templateClusteringResults(self, path, number_clusters, expected_length_clusters, ccore = False):
     sample = read_sample(path);
     
     hierarchical_instance = hierarchical(sample, number_clusters, ccore);
     hierarchical_instance.process();
     
     clusters = hierarchical_instance.get_clusters();
     
     assert sum([len(cluster) for cluster in clusters]) == len(sample);
     assert sum([len(cluster) for cluster in clusters]) == sum(expected_length_clusters);
     assert sorted([len(cluster) for cluster in clusters]) == expected_length_clusters;
 def templateClusteringResults(self, path, number_clusters, link, expected_length_clusters):
     sample = read_sample(path);
     
     agglomerative_instance = agglomerative(sample, number_clusters, link);
     agglomerative_instance.process();
     
     clusters = agglomerative_instance.get_clusters();
     
     assert sum([len(cluster) for cluster in clusters]) == len(sample);
     assert sum([len(cluster) for cluster in clusters]) == sum(expected_length_clusters);
     assert sorted([len(cluster) for cluster in clusters]) == expected_length_clusters;
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, ccore = ccore_flag);
        
        (time, dynamic) = network.process(arg_order, collect_dynamic = arg_collect_dynamic);
        clusters = network.get_clusters();
        
        if (arg_collect_dynamic == True):
            draw_dynamics(time, dynamic, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
        
        draw_clusters(sample, clusters);
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();
    
    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n");
    
    draw_clusters(sample, clusters, [], '.', hide_axes = invisible_axes);
示例#17
0
 def templateClusteringResults(self, path, radius, neighbors, expected_length_clusters, ccore = False):
     sample = read_sample(path);
     
     dbscan_instance = dbscan(sample, radius, neighbors, ccore);
     dbscan_instance.process();
     
     clusters = dbscan_instance.get_clusters();
     noise = dbscan_instance.get_noise();
     
     assert sum([len(cluster) for cluster in clusters]) + len(noise) == len(sample);
     assert sum([len(cluster) for cluster in clusters]) == sum(expected_length_clusters);
     assert sorted([len(cluster) for cluster in clusters]) == expected_length_clusters;
示例#18
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);
示例#19
0
 def templateLengthSomCluster(self, file, som_map_size, avg_num_conn, eps):
     sample = read_sample(file);
     network = syncsom(sample, som_map_size[0], som_map_size[1]);   
     network.process(avg_num_conn, collect_dynamic = False, order = eps);
     
     # Check unique
     som_clusters = network.get_som_clusters();
     indexes = set();
     
     for som_cluster in som_clusters:
         for index in som_cluster:
             assert (index in indexes) is False;
             indexes.add(index);    
示例#20
0
    def templateLengthSomCluster(self, file, som_map_size, avg_num_conn, eps):
        sample = read_sample(file)
        network = syncsom(sample, som_map_size[0], som_map_size[1])
        network.process(avg_num_conn, collect_dynamic=False, order=eps)

        # Check unique
        som_clusters = network.get_som_clusters()
        indexes = set()

        for som_cluster in som_clusters:
            for index in som_cluster:
                assert (index in indexes) is False
                indexes.add(index)
示例#21
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);
示例#22
0
 def templateLengthProcessData(self, path_to_file, radius, min_number_neighbors, max_number_neighbors, ccore = False):
     for number_neighbors in range(min_number_neighbors, max_number_neighbors, 1):
         sample = read_sample(path_to_file);
         
         dbscan_instance = dbscan(sample, radius, min_number_neighbors, ccore);
         dbscan_instance.process();
         
         clusters = dbscan_instance.get_clusters();
         noise = dbscan_instance.get_noise();
         
         length = len(noise);
         length += sum([len(cluster) for cluster in clusters]);
     
         assert len(sample) == length;
示例#23
0
 def templateLengthProcessData(self, path_to_file, start_centers, expected_cluster_length):
     sample = read_sample(path_to_file);
     
     kmedoids_instance = kmedoids(sample, start_centers, 0.025);
     kmedoids_instance.process();
     
     clusters = kmedoids_instance.get_clusters();
 
     obtained_cluster_sizes = [len(cluster) for cluster in clusters];
     assert len(sample) == sum(obtained_cluster_sizes);
     
     obtained_cluster_sizes.sort();
     expected_cluster_length.sort();
     assert obtained_cluster_sizes == expected_cluster_length;
示例#24
0
    def template_cluster_allocation(self, path, cluster_sizes, number_cluster, number_represent_points = 5, compression = 0.5, ccore_flag = False):
        sample = read_sample(path);
        
        cure_instance = cure(sample, number_cluster, ccore = ccore_flag);
        cure_instance.process();
        clusters = cure_instance.get_clusters();

        obtained_cluster_sizes = [len(cluster) for cluster in clusters];
        
        total_length = sum(obtained_cluster_sizes);
        assert total_length == len(sample);
        
        cluster_sizes.sort();
        obtained_cluster_sizes.sort();
        assert cluster_sizes == obtained_cluster_sizes;
示例#25
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);
示例#26
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");
示例#27
0
    def templateClusterAllocation(self, path, cluster_sizes, number_clusters, branching_factor = 5, max_node_entries = 5, initial_diameter = 0.1, type_measurement = measurement_type.CENTROID_EUCLIDIAN_DISTANCE, entry_size_limit = 200, ccore = True):
        sample = read_sample(path);
        
        cure_instance = birch(sample, number_clusters, branching_factor, max_node_entries, initial_diameter, type_measurement, entry_size_limit, ccore);
        cure_instance.process();
        clusters = cure_instance.get_clusters();

        obtained_cluster_sizes = [len(cluster) for cluster in clusters];
        
        total_length = sum(obtained_cluster_sizes);
        assert total_length == len(sample);
        
        cluster_sizes.sort();
        obtained_cluster_sizes.sort();
        assert cluster_sizes == obtained_cluster_sizes;
示例#28
0
 def templateLengthProcessData(self, path_to_file, radius, cluster_numbers, threshold, expected_cluster_length, ccore = False):
     sample = read_sample(path_to_file);
     
     rock_instance = rock(sample, radius, cluster_numbers, threshold, ccore);
     rock_instance.process();
     clusters = rock_instance.get_clusters();
     
     length = sum([len(cluster) for cluster in clusters]);
     assert len(sample) == length;
     
     obtained_cluster_sizes = [len(cluster) for cluster in clusters];
     obtained_cluster_sizes.sort();
     expected_cluster_length.sort();
     
     assert obtained_cluster_sizes == expected_cluster_length;
示例#29
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();
示例#30
0
    def templateClusteringResults(self, path, radius, neighbors,
                                  expected_length_clusters, ccore):
        sample = read_sample(path)

        optics_instance = optics(sample, radius, neighbors)
        optics_instance.process()

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

        assert sum([len(cluster)
                    for cluster in clusters]) + len(noise) == len(sample)
        assert sum([len(cluster)
                    for cluster in clusters]) == sum(expected_length_clusters)
        assert sorted([len(cluster)
                       for cluster in clusters]) == expected_length_clusters
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = False):
    sample = read_sample(file);
    network = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag);
    
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, order, solve_type.FAST, show_dyn);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn == True):
        draw_dynamics(dyn_time, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
    
    if (show_conn == True):
        network.show_network();
    
    if (show_clusters == True):
        clusters = network.get_clusters(0.1);
        draw_clusters(sample, clusters);
示例#32
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()

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

    draw_clusters(sample, clusters, [], '.', hide_axes=invisible_axes)
示例#33
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True):
    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();
        draw_clusters(sample, clusters);
示例#34
0
    def templateClusteringResults(self,
                                  path,
                                  number_clusters,
                                  expected_length_clusters,
                                  ccore=False):
        sample = read_sample(path)

        hierarchical_instance = hierarchical(sample, number_clusters, ccore)
        hierarchical_instance.process()

        clusters = hierarchical_instance.get_clusters()

        assert sum([len(cluster) for cluster in clusters]) == len(sample)
        assert sum([len(cluster)
                    for cluster in clusters]) == sum(expected_length_clusters)
        assert sorted([len(cluster)
                       for cluster in clusters]) == expected_length_clusters
示例#35
0
 def templateTestAwardNeurons(self, file, rows, cols, time, expected_result, autostop = False, ccore_flag = False):
     types = [type_conn.func_neighbor, type_conn.grid_eight, type_conn.grid_four, type_conn.honeycomb];
     sample = read_sample(file);
     
     for stucture in types:
         network = som(rows, cols, sample, time, stucture, ccore = ccore_flag); 
         network.train(autostop);
             
         assert sorted(network.awards) == expected_result;
         
         total_capture_points = 0;
         for points in network.capture_objects:
             total_capture_points += len(points);
             
         assert total_capture_points == sum(expected_result);
     
         del network;
def template_clustering(path_sample, eps, minpts):
    sample = read_sample(path_sample);
    
    optics_instance = optics(sample, eps, minpts);
    optics_instance.process();
    
    clusters = optics_instance.get_clusters();
    noise = optics_instance.get_noise();
    
    draw_clusters(sample, clusters, [], '.');
    
    ordering = optics_instance.get_cluster_ordering();
    indexes = [i for i in range(0, len(ordering))];
    
    # visualization of cluster ordering in line with reachability distance.
    plt.bar(indexes, ordering);
    plt.show();
def template_clustering(path_sample, eps, minpts):
    sample = read_sample(path_sample)

    optics_instance = optics(sample, eps, minpts)
    optics_instance.process()

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

    draw_clusters(sample, clusters, [], '.')

    ordering = optics_instance.get_cluster_ordering()
    indexes = [i for i in range(0, len(ordering))]

    # visualization of cluster ordering in line with reachability distance.
    plt.bar(indexes, ordering)
    plt.show()
示例#38
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)
示例#39
0
    def templateLengthProcessData(self,
                                  path_to_file,
                                  start_centers,
                                  expected_cluster_length,
                                  ccore=False):
        sample = read_sample(path_to_file)

        kmeans_instance = kmeans(sample, start_centers, 0.025, ccore)
        kmeans_instance.process()

        clusters = kmeans_instance.get_clusters()

        obtained_cluster_sizes = [len(cluster) for cluster in clusters]
        assert len(sample) == sum(obtained_cluster_sizes)

        obtained_cluster_sizes.sort()
        expected_cluster_length.sort()
        assert obtained_cluster_sizes == expected_cluster_length
示例#40
0
 def templateTestWinners(self, ccore_flag):
     types = [type_conn.func_neighbor, type_conn.grid_eight, type_conn.grid_four, type_conn.honeycomb];
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3);
         
     for stucture in types:
         network = som(5, 5, sample, 100, stucture, ccore = ccore_flag);
         network.train();
             
         assert sum(network.awards) == 60;
             
         points = list();
         for i in range(network.size):
             if (network.awards[i] > 0):
                 points += network.capture_objects[i];
             
         assert len(points) == len(sample);
             
         points = sorted(points);
         for i in range(len(points)):
             assert points[i] == i;
示例#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)
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, ccore=ccore_flag)

    (time, dynamic) = network.process(arg_order,
                                      collect_dynamic=arg_collect_dynamic)
    clusters = network.get_clusters()

    if (arg_collect_dynamic == True):
        draw_dynamics(time,
                      dynamic,
                      x_title="Time",
                      y_title="Phase",
                      y_lim=[0, 2 * 3.14])

    draw_clusters(sample, clusters)
示例#43
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(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)
示例#45
0
    def templateLengthProcessData(self,
                                  path_to_file,
                                  radius,
                                  min_number_neighbors,
                                  max_number_neighbors,
                                  ccore=False):
        for number_neighbors in range(min_number_neighbors,
                                      max_number_neighbors, 1):
            sample = read_sample(path_to_file)

            dbscan_instance = dbscan(sample, radius, min_number_neighbors,
                                     ccore)
            dbscan_instance.process()

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

            length = len(noise)
            length += sum([len(cluster) for cluster in clusters])

            assert len(sample) == length
示例#46
0
    def templateLengthProcessData(self,
                                  path_to_file,
                                  radius,
                                  cluster_numbers,
                                  threshold,
                                  expected_cluster_length,
                                  ccore=False):
        sample = read_sample(path_to_file)

        rock_instance = rock(sample, radius, cluster_numbers, threshold, ccore)
        rock_instance.process()
        clusters = rock_instance.get_clusters()

        length = sum([len(cluster) for cluster in clusters])
        assert len(sample) == length

        obtained_cluster_sizes = [len(cluster) for cluster in clusters]
        obtained_cluster_sizes.sort()
        expected_cluster_length.sort()

        assert obtained_cluster_sizes == expected_cluster_length
示例#47
0
def template_self_organization(file, rows, cols, time, structure, init_type = None, init_radius = None, init_rate = None, umatrix = False, pmatrix = False, awards = False):
    parameters = som_parameters();
    
    if (init_type is not None):
        parameters.init_type = init_type;
    if (init_radius is not None):
        parameters.init_radius = init_radius;
    if (init_rate is not None):
        parameters.init_learn_rate = init_rate;
    
    sample = read_sample(file);
    network = som(rows, cols, sample, time, structure, parameters, True);
    network.train();
    network.show_network(False, dataset = False);
    
    if (umatrix is True):
        network.show_distance_matrix();
        
    if (pmatrix is True): 
        network.show_density_matrix();
    
    if (awards is True):
        network.show_winner_matrix();
示例#48
0
 def templateClustering(self, path, number_clusters, expected_length_clusters, solver, ccore_flag):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):
         sample = read_sample(path);
         network = hsyncnet(sample, number_clusters, initial_type.EQUIPARTITION, ccore = ccore_flag); # EQUIPARTITION - makes test more stable.
         
         analyser = network.process(order = 0.997, solution = solver, collect_dynamic = True);
         clusters = analyser.allocate_clusters(0.1);
         
         if (sum([len(cluster) for cluster in clusters]) != sum(expected_length_clusters)):
             continue;
         
         if (sorted([len(cluster) for cluster in clusters]) != expected_length_clusters):
             if (sorted([len(cluster) for cluster in clusters]) != expected_length_clusters):
                 continue;
         
         # Unit-test is passed
         result_testing = True;
         break;
     
     assert result_testing;
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)