Ejemplo n.º 1
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();
Ejemplo n.º 2
0
    def show_clusters(clusters, sample, covariances, means, figure = None, display = True):
        """!
        @brief Draws clusters and in case of two-dimensional dataset draws their ellipses.
        
        @param[in] clusters (list): Clusters that were allocated by the algorithm.
        @param[in] sample (list): Dataset that were used for clustering.
        @param[in] covariances (list): Covariances of the clusters.
        @param[in] means (list): Means of the clusters.
        @param[in] figure (figure): If 'None' then new is figure is creater, otherwise specified figure is used
                    for visualization.
        @param[in] display (bool): If 'True' then figure will be shown by the method, otherwise it should be
                    shown manually using matplotlib function 'plt.show()'.
        
        @return (figure) Figure where clusters were drawn.
        
        """
        
        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)
        
        if figure is None:
            figure = visualizer.show(display = False)
        else:
            visualizer.show(figure = figure, display = False)
        
        if len(sample[0]) == 2:
            ema_visualizer.__draw_ellipses(figure, visualizer, clusters, covariances, means)

        if display is True:
            plt.show()

        return figure
Ejemplo n.º 3
0
    def show_clusters(sample, clusters, representatives, **kwargs):
        """!
        @brief Display BSAS clustering results.

        @param[in] sample (list): Dataset that was used for clustering.
        @param[in] clusters (array_like): Clusters that were allocated by the algorithm.
        @param[in] representatives (array_like): Allocated representatives correspond to clusters.
        @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'figure', 'display', 'offset').

        <b>Keyword Args:</b><br>
            - figure (figure): If 'None' then new is figure is created, otherwise specified figure is used for visualization.
            - display (bool): If 'True' then figure will be shown by the method, otherwise it should be shown manually using matplotlib function 'plt.show()'.
            - offset (uint): Specify axes index on the figure where results should be drawn (only if argument 'figure' is specified).

        @return (figure) Figure where clusters were drawn.

        """

        figure = kwargs.get('figure', None)
        display = kwargs.get('display', True)
        offset = kwargs.get('offset', 0)

        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample, canvas=offset)

        for cluster_index in range(len(clusters)):
            visualizer.append_cluster_attribute(offset, cluster_index, [representatives[cluster_index]], '*', 10)

        return visualizer.show(figure=figure, display=display)
Ejemplo n.º 4
0
    def testVisualizeHugeAmountClusters(self):
        visualizer = cluster_visualizer();
         
        data_clusters = [ [ [ random.random() ] ] for _ in range(0, 100) ];
        visualizer.append_clusters(data_clusters);

        visualizer.show();
Ejemplo n.º 5
0
 def testVisualizeByDataOnly(self):
     visualizer = cluster_visualizer();
      
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     visualizer.append_clusters([ sample ]);
      
     visualizer.show();
Ejemplo n.º 6
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();
Ejemplo n.º 7
0
 def testVisualizeOnExistedFigure(self):
     figure = plt.figure();
      
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
      
     visualizer = cluster_visualizer();
     visualizer.append_clusters([ sample ]);
     visualizer.show(figure);
Ejemplo n.º 8
0
 def testVisualizeRectangeRepresentation3x5(self):
     visualizer = cluster_visualizer(15, 5);
      
     for i in range(15):
         sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
         visualizer.append_clusters([ sample ], None, i, markersize = 5);
      
     visualizer.show();
Ejemplo n.º 9
0
 def testVisualize2DAnd3DClusters(self):
     sample_2d = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     sample_3d = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
       
     visualizer = cluster_visualizer(2, 2);
     visualizer.append_clusters([ sample_2d ], None, 0, markersize = 5);
     visualizer.append_clusters([ sample_3d ], None, 1, markersize = 30);
     visualizer.show();
Ejemplo n.º 10
0
 def testVisualize1DClustersTwoCanvases(self):
     sample_simple7 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE7);
     sample_simple8 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE8);
  
     # Two canvas visualization
     visualizer = cluster_visualizer(2);
     visualizer.append_clusters([ sample_simple7 ], None, 0, markersize = 30);
     visualizer.append_clusters([ sample_simple8 ], None, 1, markersize = 30);
     visualizer.show();
Ejemplo n.º 11
0
 def testVisualize3DClustersTwoCanvases(self):
     sample_tetra = read_sample(FCPS_SAMPLES.SAMPLE_TETRA);
     sample_hepta = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
           
     # Two canvas visualization
     visualizer = cluster_visualizer(2);
     visualizer.append_clusters([ sample_tetra ], None, 0, markersize = 30);
     visualizer.append_clusters([ sample_hepta ], None, 1, markersize = 30);
     visualizer.show();
Ejemplo n.º 12
0
 def testVisualizeRectangeRepresentation2x2(self):
     sample_simple1 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     sample_simple2 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE2);
     sample_simple3 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3);
        
     visualizer = cluster_visualizer(3, 2);
     visualizer.append_clusters([ sample_simple1 ], None, 0, markersize = 5);
     visualizer.append_clusters([ sample_simple2 ], None, 1, markersize = 5);
     visualizer.append_clusters([ sample_simple3 ], None, 2, markersize = 5);
     visualizer.show();
Ejemplo n.º 13
0
 def testVisualizeOnExistedFigureWithContentByDefault(self):
     figure = plt.figure();
     axis = figure.add_subplot(211);
     axis.plot(range(0, 10, 1), range(0, 10, 1), marker = 'o', color = 'blue', ls = '');
     
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     
     visualizer = cluster_visualizer();
     visualizer.append_clusters([ sample ]);
     visualizer.show(figure);
Ejemplo n.º 14
0
    def testVisualize2DClustersOneCanvas(self):
        sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE4);
 
        dbscan_instance = dbscan(sample, 0.7, 3, False);
        dbscan_instance.process();
        clusters = dbscan_instance.get_clusters();
          
        visualizer = cluster_visualizer();
        visualizer.append_clusters(clusters, sample, markersize = 5);
        visualizer.show();
Ejemplo n.º 15
0
 def testVisualize3DClustersOneCanvas(self):
     sample = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
       
     dbscan_instance = dbscan(sample, 0.5, 3, False);
     dbscan_instance.process();
     clusters = dbscan_instance.get_clusters();
       
     visualizer = cluster_visualizer();
     visualizer.append_clusters(clusters, sample, markersize = 30);
     visualizer.show();
Ejemplo n.º 16
0
def display_fcps_clustering_results():
    (simple4, simple4_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 1, 0.999, show_dyn = False, show_conn = False, ccore_flag = True);
    (simple_elongate, simple_elongate_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_ELONGATE, 0.5, 0.999, show_dyn = False, show_conn = False, ccore_flag = True);
    (lsun, lsun_clusters) = template_clustering(FCPS_SAMPLES.SAMPLE_LSUN, 0.45, 0.9995, show_dyn = False, show_conn = False, ccore_flag = True, tolerance = 0.2);

    visualizer = cluster_visualizer(1, 3);
    visualizer.append_clusters(simple4_clusters, simple4, 0);
    visualizer.append_clusters(simple_elongate_clusters, simple_elongate, 1);
    visualizer.append_clusters(lsun_clusters, lsun, 2);

    visualizer.show();
def template_kmeans_plusplus_initializer(path, amount, draw = True):
    sample = read_sample(path);
    centers = kmeans_plusplus_initializer(sample, amount).initialize();
    
    if (draw is True):
        visualizer = cluster_visualizer();
        visualizer.append_cluster(sample);
        visualizer.append_cluster(centers, marker = '*', markersize = 10);
        visualizer.show();
    
    return (sample, centers);
Ejemplo n.º 18
0
    def show_clusters(data, clusters, noise=None):
        """!
        @brief Display BANG clustering results.

        @param[in] data (list): Dataset that was used for clustering.
        @param[in] clusters (array_like): Clusters that were allocated by the algorithm.
        @param[in] noise (array_like): Noise that were allocated by the algorithm.

        """
        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, data)
        visualizer.append_cluster(noise or [], data, marker='x')
        visualizer.show()
Ejemplo n.º 19
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);
Ejemplo n.º 20
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");
Ejemplo n.º 21
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()
Ejemplo n.º 22
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);
Ejemplo n.º 23
0
def xmeans_clustering(
        data: np.ndarray,
        kmin: [int, None] = 1,
        kmax: [int, None] = 20,
        tolerance: float = 0.025,
        criterion: enumerate = splitting_type.BAYESIAN_INFORMATION_CRITERION,
        ccore: bool = True,
        logger=Logger(name='clustering'),
        visualize: bool = False) -> np.ndarray:

    # Initial centers - KMeans algorithm
    kmeans = KMeans(n_clusters=kmin)
    kmeans.fit(data)
    initial_centers = kmeans.cluster_centers_

    # X-Means algorithm
    xmeans_instance = xmeans(data=data,
                             initial_centers=initial_centers,
                             kmax=kmax,
                             tolerance=tolerance,
                             criterion=criterion,
                             ccore=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"

    if logger is not None:
        logger.debug(
            "Initial centers: {},\n Execution time: {},\n Number of clusters: {},\n criterion: {}"
            .format(initial_centers is not None, ticks, len(clusters),
                    criterion_string))

    if visualize:
        visualizer = cluster_visualizer()
        visualizer.set_canvas_title(criterion_string)
        visualizer.append_clusters(clusters, data)
        visualizer.append_cluster(centers, None, marker='*')
        visualizer.show()

    return clusters
Ejemplo n.º 24
0
def find_optimal_amout_clusters(sample_path, kmin, kmax, algorithm):
    sample = read_sample(sample_path)
    search_instance = silhouette_ksearch(sample, kmin, kmax, algorithm=algorithm).process()

    amount = search_instance.get_amount()
    scores = search_instance.get_scores()

    print("Sample: '%s', Scores: '%s'" % (sample_path, str(scores)))

    initial_centers = kmeans_plusplus_initializer(sample, amount).initialize()
    kmeans_instance = kmeans(sample, initial_centers).process()

    clusters = kmeans_instance.get_clusters()

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()
Ejemplo n.º 25
0
    def show_feature_destibution(self, data=None):
        visualizer = cluster_visualizer()

        print("amount of nodes: ", self.__amount_nodes)

        if (data is not None):
            visualizer.append_cluster(data, marker='x')

        for level in range(0, self.height):
            level_nodes = self.get_level_nodes(level)

            centers = [node.feature.get_centroid() for node in level_nodes]
            visualizer.append_cluster(centers,
                                      None,
                                      markersize=(self.height - level + 1) * 5)

        visualizer.show()
Ejemplo n.º 26
0
 def testVisualizeClusterWithAttributes(self):
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     cure_instance = cure(sample, 2, 5, 0.5, False);
     cure_instance.process();
     
     clusters = cure_instance.get_clusters();
     representors = cure_instance.get_representors();
     means = cure_instance.get_means();
     
     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();
Ejemplo n.º 27
0
def find_optimal_amout_clusters(sample_path, kmin, kmax, algorithm):
    sample = read_sample(sample_path)
    search_instance = silhouette_ksearch(sample, kmin, kmax, algorithm=algorithm).process()

    amount = search_instance.get_amount()
    scores = search_instance.get_scores()

    print("Sample: '%s', Scores: '%s'" % (sample_path, str(scores)))

    initial_centers = kmeans_plusplus_initializer(sample, amount).initialize()
    kmeans_instance = kmeans(sample, initial_centers).process()

    clusters = kmeans_instance.get_clusters()

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()
Ejemplo n.º 28
0
 def testVisualizeClusterWithAttributes(self):
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     cure_instance = cure(sample, 2, 5, 0.5, False);
     cure_instance.process();
     
     clusters = cure_instance.get_clusters();
     representors = cure_instance.get_representors();
     means = cure_instance.get_means();
     
     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();
Ejemplo n.º 29
0
    def show_clusters(sample,
                      clusters,
                      centers,
                      initial_centers=None,
                      **kwargs):
        """!
        @brief Display K-Means clustering results.
        @details Allocated figure by this method should be closed using `close()` method of this visualizer.
        
        @param[in] sample (list): Dataset that was used for clustering.
        @param[in] clusters (array_like): Clusters that were allocated by the algorithm.
        @param[in] centers (array_like): Centers that were allocated by the algorithm.
        @param[in] initial_centers (array_like): Initial centers that were used by the algorithm, if 'None' then initial centers are not displyed.
        @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'figure', 'display', 'offset').
        
        <b>Keyword Args:</b><br>
            - figure (figure): If 'None' then new is figure is created, otherwise specified figure is used for visualization.
            - display (bool): If 'True' then figure will be shown by the method, otherwise it should be shown manually using matplotlib function 'plt.show()'.
            - offset (uint): Specify axes index on the figure where results should be drawn (only if argument 'figure' is specified).
        
        @return (figure) Figure where clusters were drawn.
        
        """

        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)

        offset = kwargs.get('offset', 0)
        figure = kwargs.get('figure', None)
        display = kwargs.get('display', True)

        if figure is None:
            figure = visualizer.show(display=False)
        else:
            visualizer.show(figure=figure, display=False)

        kmeans_visualizer.__draw_centers(figure, offset, visualizer, centers,
                                         initial_centers)
        kmeans_visualizer.__draw_rays(figure, offset, visualizer, sample,
                                      clusters, centers)

        if display is True:
            plt.show()

        return figure
    def optics_temp(self, point_list):
        # data = np.array( point_list)
        sample = point_list
        start = time.time()
        optics_instance = optics(sample, 0.5, 6, ccore=True)
        optics_instance.process()
        clusters = optics_instance.get_clusters()
        end = time.time()
        print("imte", end - start)

        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)
Ejemplo n.º 31
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, outlier_detector = 0, 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, outlier_detector);
    (ticks, result) = timedcall(birch_instance.process);

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

    clusters = birch_instance.get_clusters();
    noise = birch_instance.get_noise();
    
    if (show_result is True):
        visualizer = cluster_visualizer();
        visualizer.append_clusters(clusters, sample);
        visualizer.append_cluster(noise, sample, marker = 'x');
        visualizer.show();
    
    return (sample, clusters, noise);
Ejemplo n.º 32
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
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, marker = '*', markersize = 15);
        visualizer.show();
    
    return (sample, clusters);
Ejemplo n.º 34
0
def template_clustering(start_medoids,
                        path,
                        tolerance=0.25,
                        show=True,
                        **kwargs):
    ccore = kwargs.get('ccore', True)
    data_type = kwargs.get('data_type', 'points')

    original_data = read_sample(path)
    sample = original_data
    if data_type == 'distance_matrix':
        sample = calculate_distance_matrix(sample)

    metric = distance_metric(type_metric.EUCLIDEAN_SQUARE, data=sample)

    kmedoids_instance = kmedoids(sample,
                                 start_medoids,
                                 tolerance,
                                 metric=metric,
                                 ccore=ccore,
                                 data_type=data_type)
    (ticks, result) = timedcall(kmedoids_instance.process)

    clusters = kmedoids_instance.get_clusters()
    print("Iterations:", kmedoids_instance.get_iterations())
    print([len(cluster) for cluster in clusters])
    print(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, original_data, 0)
        visualizer.append_cluster(
            [original_data[index] for index in start_medoids],
            marker='*',
            markersize=15)
        visualizer.append_cluster(medoids,
                                  data=original_data,
                                  marker='*',
                                  markersize=15)
        visualizer.show()

    return original_data, clusters
Ejemplo n.º 35
0
 def frame_generation(index_dynamic):
     figure.clf()
     if title is not None:
         figure.suptitle(title, fontsize = 26, fontweight = 'bold')
     
     ax1 = figure.add_subplot(121, projection='polar')
     
     clusters = analyser.allocate_clusters(eps = tolerance, iteration = index_dynamic)
     dynamic = analyser.output[index_dynamic]
     
     visualizer = cluster_visualizer(size_row = 2)
     visualizer.append_clusters(clusters, dataset)
     
     artist1, = ax1.plot(dynamic, [1.0] * len(dynamic), marker='o', color='blue', ls='')
     
     visualizer.show(figure, display = False)
     artist2 = figure.gca()
     
     return [ artist1, artist2 ]
def kmeans_plusplus_initializer_collection():
    (sample1, centers1) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 2, False);
    (sample2, centers2) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 3, False);
    (sample3, centers3) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 4, False);
    (sample4, centers4) = template_kmeans_plusplus_initializer(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 2, False);
    
    visualizer = cluster_visualizer(4, 2);
    visualizer.append_cluster(sample1, canvas = 0);
    visualizer.append_cluster(centers1, canvas = 0, marker = '*', markersize = 10);
    
    visualizer.append_cluster(sample2, canvas = 1);
    visualizer.append_cluster(centers2, canvas = 1, marker = '*', markersize = 10);
    
    visualizer.append_cluster(sample3, canvas = 2);
    visualizer.append_cluster(centers3, canvas = 2, marker = '*', markersize = 10);
    
    visualizer.append_cluster(sample4, canvas = 3);
    visualizer.append_cluster(centers4, canvas = 3, marker = '*', markersize = 10);
    visualizer.show();
def kmeans_plusplus_initializer_collection():
    (sample1, centers1) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 2, False)
    (sample2, centers2) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 3, False)
    (sample3, centers3) = template_kmeans_plusplus_initializer(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 4, False)
    (sample4, centers4) = template_kmeans_plusplus_initializer(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 2, False)
    
    visualizer = cluster_visualizer(4, 2)
    visualizer.append_cluster(sample1, canvas=0)
    visualizer.append_cluster(centers1, canvas=0, marker='*', markersize=10)
    
    visualizer.append_cluster(sample2, canvas=1)
    visualizer.append_cluster(centers2, canvas=1, marker='*', markersize=10)
    
    visualizer.append_cluster(sample3, canvas=2)
    visualizer.append_cluster(centers3, canvas=2, marker='*', markersize=10)
    
    visualizer.append_cluster(sample4, canvas=3)
    visualizer.append_cluster(centers4, canvas=3, marker='*', markersize=10)
    visualizer.show()
Ejemplo n.º 38
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")
Ejemplo n.º 39
0
def display_simple_dbscan_results():
        (simple1, simple1_clusters, _) = template_clustering(0.4, 2, SIMPLE_SAMPLES.SAMPLE_SIMPLE1)
        (simple2, simple2_clusters, _) = template_clustering(1, 2, SIMPLE_SAMPLES.SAMPLE_SIMPLE2)
        (simple3, simple3_clusters, _) = template_clustering(0.7, 3, SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
        (simple4, simple4_clusters, _) = template_clustering(0.7, 3, SIMPLE_SAMPLES.SAMPLE_SIMPLE4)
        (simple5, simple5_clusters, _) = template_clustering(0.7, 3, SIMPLE_SAMPLES.SAMPLE_SIMPLE5)
        (simple6, simple6_clusters, _) = template_clustering(1, 2, SIMPLE_SAMPLES.SAMPLE_SIMPLE6)
        (simple7, simple7_clusters, _) = template_clustering(1.0, 3, SIMPLE_SAMPLES.SAMPLE_SIMPLE7)
        (simple8, simple8_clusters, _) = template_clustering(1.0, 3, SIMPLE_SAMPLES.SAMPLE_SIMPLE8)

        visualizer = cluster_visualizer(8, 4)
        visualizer.append_clusters(simple1_clusters, simple1, 0)
        visualizer.append_clusters(simple2_clusters, simple2, 1)
        visualizer.append_clusters(simple3_clusters, simple3, 2)
        visualizer.append_clusters(simple4_clusters, simple4, 3)
        visualizer.append_clusters(simple5_clusters, simple5, 4)
        visualizer.append_clusters(simple6_clusters, simple6, 5)
        visualizer.append_clusters(simple7_clusters, simple7, 6)
        visualizer.append_clusters(simple8_clusters, simple8, 7)
        visualizer.show()
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()
Ejemplo n.º 41
0
def display_fcps_clustering_results():
    (lsun, lsun_clusters) = template_clustering([10, 275, 385], FCPS_SAMPLES.SAMPLE_LSUN, 0.1, False);
    (target, target_clusters) = template_clustering([10, 160, 310, 460, 560, 700], FCPS_SAMPLES.SAMPLE_TARGET, 0.1, False);
    (two_diamonds, two_diamonds_clusters) = template_clustering([10, 650], FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 0.1, False);
    (wing_nut, wing_nut_clusters) = template_clustering([19, 823], FCPS_SAMPLES.SAMPLE_WING_NUT, 0.1, False);
    (chainlink, chainlink_clusters) = template_clustering([30, 900], FCPS_SAMPLES.SAMPLE_CHAINLINK, 0.1, False);
    (hepta, hepta_clusters) = template_clustering([0, 35, 86, 93, 125, 171, 194], FCPS_SAMPLES.SAMPLE_HEPTA, 0.1, False);
    (tetra, tetra_clusters) = template_clustering([0, 131, 214, 265], FCPS_SAMPLES.SAMPLE_TETRA, 0.1, False);
    (atom, atom_clusters) = template_clustering([0, 650], FCPS_SAMPLES.SAMPLE_ATOM, 0.1, False);
    
    visualizer = cluster_visualizer(8, 4);
    visualizer.append_clusters(lsun_clusters, lsun, 0);
    visualizer.append_clusters(target_clusters, target, 1);
    visualizer.append_clusters(two_diamonds_clusters, two_diamonds, 2);
    visualizer.append_clusters(wing_nut_clusters, wing_nut, 3);
    visualizer.append_clusters(chainlink_clusters, chainlink, 4);
    visualizer.append_clusters(hepta_clusters, hepta, 5);
    visualizer.append_clusters(tetra_clusters, tetra, 6);
    visualizer.append_clusters(atom_clusters, atom, 7);
    visualizer.show();
Ejemplo n.º 42
0
def display_fcps_clarans_results():
    (lsun, lsun_clusters) = template_clustering(3, FCPS_SAMPLES.SAMPLE_LSUN, 10, 5);
    (target, target_clusters) = template_clustering(6, FCPS_SAMPLES.SAMPLE_TARGET, 10, 5);
    (two_diamonds, two_diamonds_clusters) = template_clustering(2, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 2, 2);
    (wing_nut, wing_nut_clusters) = template_clustering(2, FCPS_SAMPLES.SAMPLE_WING_NUT, 2, 2);
    (chainlink, chainlink_clusters) = template_clustering(2, FCPS_SAMPLES.SAMPLE_CHAINLINK, 2, 2);
    (hepta, hepta_clusters) = template_clustering(7, FCPS_SAMPLES.SAMPLE_HEPTA, 2, 2);
    (tetra, tetra_clusters) = template_clustering(4, FCPS_SAMPLES.SAMPLE_TETRA, 2, 2);
    (atom, atom_clusters) = template_clustering(2, FCPS_SAMPLES.SAMPLE_ATOM, 2, 2);

    visualizer = cluster_visualizer(8, 4)
    visualizer.append_clusters(lsun_clusters, lsun, 0)
    visualizer.append_clusters(target_clusters, target, 1)
    visualizer.append_clusters(two_diamonds_clusters, two_diamonds, 2)
    visualizer.append_clusters(wing_nut_clusters, wing_nut, 3)
    visualizer.append_clusters(chainlink_clusters, chainlink, 4)
    visualizer.append_clusters(hepta_clusters, hepta, 5)
    visualizer.append_clusters(tetra_clusters, tetra, 6)
    visualizer.append_clusters(atom_clusters, atom, 7)
    visualizer.show()
Ejemplo n.º 43
0
def display_fcps_clustering_results():
    (lsun, lsun_clusters, _) = template_clustering(3, FCPS_SAMPLES.SAMPLE_LSUN, show_result = False);
    (target, target_clusters, _) = template_clustering(6, FCPS_SAMPLES.SAMPLE_TARGET, show_result = False);
    (two_diamonds, two_diamonds_clusters, _) = template_clustering(2, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, show_result = False);
    (wing_nut, wing_nut_clusters, _) = template_clustering(2, FCPS_SAMPLES.SAMPLE_WING_NUT, show_result = False);
    (chainlink, chainlink_clusters, _) = template_clustering(2, FCPS_SAMPLES.SAMPLE_CHAINLINK, show_result = False);
    (hepta, hepta_clusters, _) = template_clustering(7, FCPS_SAMPLES.SAMPLE_HEPTA, show_result = False);
    (tetra, tetra_clusters, _) = template_clustering(4, FCPS_SAMPLES.SAMPLE_TETRA, show_result = False);
    (atom, atom_clusters, _) = template_clustering(2, FCPS_SAMPLES.SAMPLE_ATOM, show_result = False);
    
    visualizer = cluster_visualizer(8, 4);
    visualizer.append_clusters(lsun_clusters, lsun, 0);
    visualizer.append_clusters(target_clusters, target, 1);
    visualizer.append_clusters(two_diamonds_clusters, two_diamonds, 2);
    visualizer.append_clusters(wing_nut_clusters, wing_nut, 3);
    visualizer.append_clusters(chainlink_clusters, chainlink, 4);
    visualizer.append_clusters(hepta_clusters, hepta, 5);
    visualizer.append_clusters(tetra_clusters, tetra, 6);
    visualizer.append_clusters(atom_clusters, atom, 7);
    visualizer.show();
Ejemplo n.º 44
0
 def frame_generation(index_iteration):
     figure.clf()
     
     figure.suptitle("Clustering genetic algorithm (iteration: " + str(index_iteration) + ")", fontsize=18, fontweight='bold')
     
     visualizer = cluster_visualizer(4, 2, ["The best pop. on step #" + str(index_iteration), "The best population"])
     
     local_minimum_clusters = ga_math.get_clusters_representation(observer.get_population_best()['chromosome'][index_iteration])
     visualizer.append_clusters(local_minimum_clusters, data, 0)
     
     global_minimum_clusters = ga_math.get_clusters_representation(observer.get_global_best()['chromosome'][index_iteration])
     visualizer.append_clusters(global_minimum_clusters, data, 1)
     
     ax1 = plt.subplot2grid((2, 2), (1, 0), colspan=2)
     ga_visualizer.show_evolution(observer, 0, index_iteration + 1, ax1, False)
     
     visualizer.show(figure, shift=0, display=False)
     figure.subplots_adjust(top=0.85)
     
     return [figure.gca()]
Ejemplo n.º 45
0
def display_fcps_clustering_results():
    (lsun, lsun_clusters, _) = template_clustering(0.5, 3, FCPS_SAMPLES.SAMPLE_LSUN, False, True, False)
    (target, target_clusters, _) = template_clustering(0.5, 2, FCPS_SAMPLES.SAMPLE_TARGET, False, True, False)
    (two_diamonds, two_diamonds_clusters, _) = template_clustering(0.15, 7, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False)
    (wing_nut, wing_nut_clusters, _) = template_clustering(0.25, 2, FCPS_SAMPLES.SAMPLE_WING_NUT, False, True, False)
    (chainlink, chainlink_clusters, _) = template_clustering(0.5, 3, FCPS_SAMPLES.SAMPLE_CHAINLINK, False, True, False)
    (hepta, hepta_clusters, _) = template_clustering(1, 3, FCPS_SAMPLES.SAMPLE_HEPTA, False, True, False)
    (tetra, tetra_clusters, _) = template_clustering(0.4, 3, FCPS_SAMPLES.SAMPLE_TETRA, False, True, False)
    (atom, atom_clusters, _) = template_clustering(15, 3, FCPS_SAMPLES.SAMPLE_ATOM, False, True, False)
    
    visualizer = cluster_visualizer(8, 4)
    visualizer.append_clusters(lsun_clusters, lsun, 0)
    visualizer.append_clusters(target_clusters, target, 1)
    visualizer.append_clusters(two_diamonds_clusters, two_diamonds, 2)
    visualizer.append_clusters(wing_nut_clusters, wing_nut, 3)
    visualizer.append_clusters(chainlink_clusters, chainlink, 4)
    visualizer.append_clusters(hepta_clusters, hepta, 5)
    visualizer.append_clusters(tetra_clusters, tetra, 6)
    visualizer.append_clusters(atom_clusters, atom, 7)
    visualizer.show()
Ejemplo n.º 46
0
def template_clustering(data_path, intervals, density_threshold, **kwargs):
    print("Sample: '%s'." % os.path.basename(data_path))

    data = read_sample(data_path)

    clique_instance = clique(data, intervals, density_threshold)
    clique_instance.process()

    clusters = clique_instance.get_clusters()
    noise = clique_instance.get_noise()
    cells = clique_instance.get_cells()

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

    clique_visualizer.show_grid(cells, data)

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, data)
    visualizer.append_cluster(noise, data, marker='x')
    visualizer.show()
Ejemplo n.º 47
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 (False):
        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);
Ejemplo n.º 48
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
Ejemplo n.º 49
0
def display_fcps_clustering_results():
    (lsun, lsun_clusters) = template_clustering([10, 275, 385], FCPS_SAMPLES.SAMPLE_LSUN, 0.1, False)
    (target, target_clusters) = template_clustering([10, 160, 310, 460, 560, 700], FCPS_SAMPLES.SAMPLE_TARGET, 0.1, False)
    (two_diamonds, two_diamonds_clusters) = template_clustering([10, 650], FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, 0.1, False)
    (wing_nut, wing_nut_clusters) = template_clustering([19, 823], FCPS_SAMPLES.SAMPLE_WING_NUT, 0.1, False)
    (chainlink, chainlink_clusters) = template_clustering([30, 900], FCPS_SAMPLES.SAMPLE_CHAINLINK, 0.1, False)
    (hepta, hepta_clusters) = template_clustering([0, 35, 86, 93, 125, 171, 194], FCPS_SAMPLES.SAMPLE_HEPTA, 0.1, False)
    (tetra, tetra_clusters) = template_clustering([0, 131, 214, 265], FCPS_SAMPLES.SAMPLE_TETRA, 0.1, False)
    (atom, atom_clusters) = template_clustering([0, 650], FCPS_SAMPLES.SAMPLE_ATOM, 0.1, False)
    
    visualizer = cluster_visualizer(8, 4)
    visualizer.append_clusters(lsun_clusters, lsun, 0)
    visualizer.append_clusters(target_clusters, target, 1)
    visualizer.append_clusters(two_diamonds_clusters, two_diamonds, 2)
    visualizer.append_clusters(wing_nut_clusters, wing_nut, 3)
    visualizer.append_clusters(chainlink_clusters, chainlink, 4)
    visualizer.append_clusters(hepta_clusters, hepta, 5)
    visualizer.append_clusters(tetra_clusters, tetra, 6)
    visualizer.append_clusters(atom_clusters, atom, 7)
    visualizer.show()
Ejemplo n.º 50
0
def initialize_kmedoids_model(
        path_to_points="./lib/us_metros_scraped_geocoords.tsv"):

    import numpy as np
    from sklearn.cluster import KMeans

    coords = []
    labels = []
    if isinstance(path_to_points, str):
        for row in load_csv(path_to_points, delimiter="\t"):
            try:
                coords.append(
                    list(deg2dec((row["latitude"], row["longitude"]))))
                labels.append(row["parent"])
            except Exception as e:
                print(e)
    else:
        coords = path_to_points
    arr = np.array([c for c in coords if c and len(c) == 2])
    print(f"Points: {len(arr)}")
    k = 32
    from pyclustering.cluster.kmedoids import kmedoids

    # Load list of points for cluster analysis.

    # Set random initial medoids.
    initial_medoids = random.sample(range(0, len(arr)), k=k)
    # Create instance of K-Medoids algorithm.
    kmedoids_instance = kmedoids(arr, initial_medoids)
    # Run cluster analysis and obtain results.
    kmedoids_instance.process()
    clusters = kmedoids_instance.get_clusters()
    # Show allocated clusters.
    print(clusters)
    # return kmedoids_instance
    # Display clusters.
    from pyclustering.cluster import cluster_visualizer

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, arr)
    visualizer.show()
Ejemplo n.º 51
0
def display_fcps_dependence_clustering_results():
    (two_diamonds, two_diamonds_clusters_1, _) = template_clustering(0.15, 4, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_2, _) = template_clustering(0.15, 5, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_3, _) = template_clustering(0.15, 6, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_4, _) = template_clustering(0.15, 7, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    
    (two_diamonds, two_diamonds_clusters_5, _) = template_clustering(0.10, 6, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_6, _) = template_clustering(0.12, 6, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_7, _) = template_clustering(0.15, 6, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    (two_diamonds, two_diamonds_clusters_8, _) = template_clustering(0.17, 6, FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS, False, True, False);
    
    visualizer = cluster_visualizer(8, 4);
    visualizer.append_clusters(two_diamonds_clusters_1, two_diamonds, 0);
    visualizer.append_clusters(two_diamonds_clusters_2, two_diamonds, 1);
    visualizer.append_clusters(two_diamonds_clusters_3, two_diamonds, 2);
    visualizer.append_clusters(two_diamonds_clusters_4, two_diamonds, 3);
    visualizer.append_clusters(two_diamonds_clusters_5, two_diamonds, 4);
    visualizer.append_clusters(two_diamonds_clusters_6, two_diamonds, 5);
    visualizer.append_clusters(two_diamonds_clusters_7, two_diamonds, 6);
    visualizer.append_clusters(two_diamonds_clusters_8, two_diamonds, 7);
    visualizer.show();
Ejemplo n.º 52
0
    def testVisualizeClusterWithAttributesNumpy(self):
        sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1,
                             return_type='numpy')
        cure_instance = cure(sample, 2, 5, 0.5, False)
        cure_instance.process()

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

        visualizer = cluster_visualizer()
        visualizer.append_clusters(clusters, sample)

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

        visualizer.show()
Ejemplo n.º 53
0
def display_simple_clarans_results():
        (simple1, simple1_clusters) = template_clustering(2, SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 10, 3);
        (simple2, simple2_clusters) = template_clustering(3, SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 10, 3);
        (simple3, simple3_clusters) = template_clustering(4, SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 10, 3);
        (simple4, simple4_clusters) = template_clustering(5, SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 10, 4);
        (simple5, simple5_clusters) = template_clustering(4, SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 10, 5);
        (simple6, simple6_clusters) = template_clustering(2, SIMPLE_SAMPLES.SAMPLE_SIMPLE6, 10, 3);
        (simple7, simple7_clusters) = template_clustering(2, SIMPLE_SAMPLES.SAMPLE_SIMPLE7, 10, 3);
        (simple8, simple8_clusters) = template_clustering(4, SIMPLE_SAMPLES.SAMPLE_SIMPLE8, 15, 5);


        visualizer = cluster_visualizer(8, 4)
        visualizer.append_clusters(simple1_clusters, simple1, 0)
        visualizer.append_clusters(simple2_clusters, simple2, 1)
        visualizer.append_clusters(simple3_clusters, simple3, 2)
        visualizer.append_clusters(simple4_clusters, simple4, 3)
        visualizer.append_clusters(simple5_clusters, simple5, 4)
        visualizer.append_clusters(simple6_clusters, simple6, 5)
        visualizer.append_clusters(simple7_clusters, simple7, 6)
        visualizer.append_clusters(simple8_clusters, simple8, 7)
        visualizer.show()
Ejemplo n.º 54
0
def template_clustering(path_sample, eps, minpts, amount_clusters = None, visualize = True):
    sample = read_sample(path_sample);
    
    optics_instance = optics(sample, eps, minpts, amount_clusters);
    (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);
Ejemplo n.º 55
0
def display_simple_clustering_results():
    (simple1,
     simple1_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1,
                                             visualize=False)
    (simple2,
     simple2_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2,
                                             visualize=False)
    (simple3,
     simple3_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3,
                                             visualize=False)
    (simple4,
     simple4_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4,
                                             visualize=False)
    (simple5,
     simple5_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5,
                                             visualize=False)
    (simple6,
     simple6_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE6,
                                             visualize=False)
    (simple7,
     simple7_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE7,
                                             visualize=False)
    (simple8,
     simple8_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE8,
                                             visualize=False)
    (simple9,
     simple9_clusters) = template_clustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE9,
                                             visualize=False)

    visualizer = cluster_visualizer(9, 3)
    visualizer.append_clusters(simple1_clusters, simple1, 0, markersize=3)
    visualizer.append_clusters(simple2_clusters, simple2, 1, markersize=3)
    visualizer.append_clusters(simple3_clusters, simple3, 2, markersize=3)
    visualizer.append_clusters(simple4_clusters, simple4, 3, markersize=3)
    visualizer.append_clusters(simple5_clusters, simple5, 4, markersize=3)
    visualizer.append_clusters(simple6_clusters, simple6, 5, markersize=6)
    visualizer.append_clusters(simple7_clusters, simple7, 6, markersize=6)
    visualizer.append_clusters(simple8_clusters, simple8, 7, markersize=6)
    visualizer.append_clusters(simple9_clusters, simple9, 8, markersize=6)
    visualizer.show()
Ejemplo n.º 56
0
def template_clustering(radius, neighb, path, invisible_axes = False, ccore = False, show = True, tempos = tempos_dbscan):
    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")

    tempos_dbscan.append(ticks)

    return sample, clusters, noise
Ejemplo n.º 57
0
 def testVisualize2DClustersThreeCanvases(self):
     sample_simple1 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
     sample_simple2 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE2);
     sample_simple3 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3);
           
     dbscan_instance = dbscan(sample_simple1, 0.4, 2, False);
     dbscan_instance.process();
     clusters_sample1 = dbscan_instance.get_clusters();
           
     dbscan_instance = dbscan(sample_simple2, 1, 2, False);
     dbscan_instance.process();
     clusters_sample2 = dbscan_instance.get_clusters();
   
     dbscan_instance = dbscan(sample_simple3, 0.7, 3, False);
     dbscan_instance.process();
     clusters_sample3 = dbscan_instance.get_clusters();
           
     visualizer = cluster_visualizer(3);
     visualizer.append_clusters(clusters_sample1, sample_simple1, 0, markersize = 5);
     visualizer.append_clusters(clusters_sample2, sample_simple2, 1, markersize = 5);
     visualizer.append_clusters(clusters_sample3, sample_simple3, 2, markersize = 5);
     visualizer.show();
        def template_clustering(start_medoids,
                                sample,
                                tolerance=0.25,
                                show=True):

            kmedoids_instance = kmedoids(sample, start_medoids, tolerance)
            (ticks, result) = timedcall(kmedoids_instance.process)

            clusters = kmedoids_instance.get_clusters()
            medoids = kmedoids_instance.get_medoids()
            print("Execution 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, marker='*', markersize=5)
                visualizer.show()
            return medoids
Ejemplo n.º 59
0
 def show_feature_destibution(self, data = None):
     """!
     @brief Shows feature distribution.
     @details Only features in 1D, 2D, 3D space can be visualized.
     
     @param[in] data (list): List of points that will be used for visualization, if it not specified than feature will be displayed only.
     
     """
     visualizer = cluster_visualizer();
     
     print("amount of nodes: ", self.__amount_nodes);
     
     if (data is not None):
         visualizer.append_cluster(data, marker = 'x');
     
     for level in range(0, self.height):
         level_nodes = self.get_level_nodes(level);
         
         centers = [ node.feature.get_centroid() for node in level_nodes ];
         visualizer.append_cluster(centers, None, markersize = (self.height - level + 1) * 5);
     
     visualizer.show();