Exemplo n.º 1
0
def template_clustering(sample_file_path, amount_clusters, initializer, show_animation = False):
    sample = read_sample(sample_file_path);
    
    observer = None;
    if (show_animation is True):
        observer = ema_observer();

    initial_means, initial_covariance = ema_initializer(sample, amount_clusters).initialize(initializer);
    ema_instance = ema(sample, amount_clusters, initial_means, initial_covariance, observer=observer);
    ema_instance.process();
    
    clusters = ema_instance.get_clusters();
    covariances = ema_instance.get_covariances();
    means = ema_instance.get_centers();

    cluster_length = [ len(cluster) for cluster in clusters ];

    print("Data '" + sample_file_path + "'");
    print("Clusters: " + str(len(clusters)) + ", Length:" + str(cluster_length));

    if (observer is True):
        ema_visualizer.show_clusters(observer.get_evolution_clusters()[0], sample, observer.get_evolution_covariances()[0], observer.get_evolution_means()[0]);
    
    ema_visualizer.show_clusters(clusters, sample, covariances, means);
    
    if (show_animation is True):
        ema_visualizer.animate_cluster_allocation(sample, observer);
Exemplo n.º 2
0
def template_clustering(sample_file_path, amount_clusters, initializer, show_animation = False):
    sample = read_sample(sample_file_path);
    
    observer = None;
    if (show_animation is True):
        observer = ema_observer();

    initial_means, initial_covariance = ema_initializer(sample, amount_clusters).initialize(initializer);
    ema_instance = ema(sample, amount_clusters, initial_means, initial_covariance, observer=observer);
    ema_instance.process();
    
    clusters = ema_instance.get_clusters();
    covariances = ema_instance.get_covariances();
    means = ema_instance.get_centers();

    cluster_length = [ len(cluster) for cluster in clusters ];

    print("Data '" + sample_file_path + "'");
    print("Clusters: " + str(len(clusters)) + ", Length:" + str(cluster_length));

    if (observer is True):
        ema_visualizer.show_clusters(observer.get_evolution_clusters()[0], sample, observer.get_evolution_covariances()[0], observer.get_evolution_means()[0]);
    
    ema_visualizer.show_clusters(clusters, sample, covariances, means);
    
    if (show_animation is True):
        ema_visualizer.animate_cluster_allocation(sample, observer);
Exemplo n.º 3
0
 def testVisualizerNoFailures(self):
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
     
     means, variances = ema_initializer(sample, 4).initialize(ema_init_type.RANDOM_INITIALIZATION)
     
     observer_instance = ema_observer()
     ema_instance = ema(sample, 4, means, variances, observer_instance)
     ema_instance.process()
     
     clusters = ema_instance.get_clusters()
     means = ema_instance.get_centers()
     covariances = ema_instance.get_covariances()
     
     ema_visualizer.show_clusters(clusters, sample, covariances, means)
     ema_visualizer.animate_cluster_allocation(sample, observer_instance)
Exemplo n.º 4
0
 def testVisualizerNoFailures(self):
     sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
     
     means, variances = ema_initializer(sample, 4).initialize(ema_init_type.RANDOM_INITIALIZATION)
     
     observer_instance = ema_observer()
     ema_instance = ema(sample, 4, means, variances, observer_instance)
     ema_instance.process()
     
     clusters = ema_instance.get_clusters()
     means = ema_instance.get_centers()
     covariances = ema_instance.get_covariances()
     
     ema_visualizer.show_clusters(clusters, sample, covariances, means)
     ema_visualizer.animate_cluster_allocation(sample, observer_instance)