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

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

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

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

    if (show_clusters == True):
        clusters = analyser.allocate_clusters(tolerance)
        print("amout of clusters: ", len(clusters))
        draw_clusters(sample, clusters)
Exemplo n.º 2
0
 def templateVisualizerNoFailures(self, size, velocity, ccore_flag):
     net = sync_network(size, ccore = ccore_flag);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True);
     
     sync_visualizer.animate_correlation_matrix(output_dynamic, velocity);
     sync_visualizer.animate_output_dynamic(output_dynamic, velocity);
     sync_visualizer.show_correlation_matrix(output_dynamic);
     sync_visualizer.show_output_dynamic(output_dynamic);
Exemplo n.º 3
0
 def show_first_layer_dynamic(analyser):
     """!
     @brief Shows output dynamic of the first layer.
     
     @param[in] analyser (syncsegm_analyser): Analyser of output dynamic of the 'syncsegm' oscillatory network.
     
     """
     
     sync_visualizer.show_output_dynamic(analyser.get_first_layer_analyser());
Exemplo n.º 4
0
 def show_first_layer_dynamic(analyser):
     """!
     @brief Shows output dynamic of the first layer.
     
     @param[in] analyser (syncsegm_analyser): Analyser of output dynamic of the 'syncsegm' oscillatory network.
     
     """
     
     sync_visualizer.show_output_dynamic(analyser.get_first_layer_analyser());
Exemplo n.º 5
0
    def templateVisualizerNoFailures(self, size, velocity, ccore_flag):
        net = sync_network(size, ccore=ccore_flag)
        output_dynamic = net.simulate_dynamic(solution=solve_type.FAST,
                                              collect_dynamic=True)

        sync_visualizer.animate(output_dynamic)
        sync_visualizer.animate_correlation_matrix(output_dynamic, velocity)
        sync_visualizer.animate_output_dynamic(output_dynamic, velocity)
        sync_visualizer.show_correlation_matrix(output_dynamic)
        sync_visualizer.show_output_dynamic(output_dynamic)
Exemplo n.º 6
0
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, 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);
Exemplo n.º 7
0
def template_dynamic_sync(num_osc, k = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False):
    network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag);

    if (sim_arg is not None):
        sync_output_dynamic = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn);
    else:
        sync_output_dynamic = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution);

    sync_visualizer.show_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_correlation_matrix(sync_output_dynamic);
    return network;
Exemplo n.º 8
0
def template_dynamic_sync(num_osc, k = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False):
    network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag);

    if (sim_arg is not None):
        sync_output_dynamic = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn);
    else:
        sync_output_dynamic = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution);

    sync_visualizer.show_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_correlation_matrix(sync_output_dynamic);
    return network;
Exemplo n.º 9
0
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, initial_neighbors = int(len(sample) * 0.15), osc_initial_phases = initial_type.EQUIPARTITION, ccore = ccore_flag);
        
        (ticks, analyser) = timedcall(network.process, arg_order, solve_type.FAST, arg_collect_dynamic);
        print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
        
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
Exemplo n.º 10
0
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, initial_neighbors = int(len(sample) * 0.15), osc_initial_phases = initial_type.EQUIPARTITION, ccore = ccore_flag);
        
        (ticks, analyser) = timedcall(network.process, arg_order, solve_type.FAST, arg_collect_dynamic);
        print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
        
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
Exemplo n.º 11
0
 def templateVisualizerNoFailures(size, velocity, ccore_flag):
     net = sync_network(size, ccore = ccore_flag);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True);
     
     sync_visualizer.animate(output_dynamic);
     sync_visualizer.animate_correlation_matrix(output_dynamic, velocity);
     sync_visualizer.animate_output_dynamic(output_dynamic, velocity);
     sync_visualizer.animate_phase_matrix(output_dynamic, 1, size, velocity);
     sync_visualizer.show_correlation_matrix(output_dynamic);
     sync_visualizer.show_output_dynamic(output_dynamic);
     sync_visualizer.show_phase_matrix(output_dynamic, 1, size);
     sync_visualizer.show_order_parameter(output_dynamic);
     sync_visualizer.show_local_order_parameter(output_dynamic, net);
Exemplo n.º 12
0
def template_clustering(file,
                        number_clusters,
                        arg_order=0.999,
                        arg_collect_dynamic=True,
                        ccore_flag=False):
    sample = read_sample(file)
    network = hsyncnet(sample, number_clusters, 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)
Exemplo n.º 13
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True, tolerance = 0.1):
    sample = read_sample(file);
    network = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag);
    
    (ticks, analyser) = timedcall(network.process, order, solve_type.FAST, show_dyn);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn == True):
        sync_visualizer.show_output_dynamic(analyser);
        sync_visualizer.animate_output_dynamic(analyser);
    
    if ( (show_conn == True) and (ccore_flag == False) ):
        network.show_network();
    
    if (show_clusters == True):
        clusters = analyser.allocate_clusters(tolerance);
        draw_clusters(sample, clusters);
Exemplo n.º 14
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True, tolerance = 0.1):
    sample = read_sample(file)
    syncnet_instance = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag)

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

    if show_dyn == True:
        sync_visualizer.show_output_dynamic(analyser)
        sync_visualizer.animate(analyser)
        sync_visualizer.show_local_order_parameter(analyser, syncnet_instance)
        #sync_visualizer.animate_output_dynamic(analyser);
        #sync_visualizer.animate_correlation_matrix(analyser, colormap = 'hsv')
     
    if show_conn == True:
        syncnet_instance.show_network()
     
    if show_clusters == True:
        clusters = analyser.allocate_clusters(tolerance)
        print("Amount of allocated clusters: ", len(clusters))
        draw_clusters(sample, clusters)
    
    print("----------------------------\n")
    return (sample, clusters)
Exemplo n.º 15
0
def template_clustering(file, radius, order, show_dyn = False, show_conn = False, show_clusters = True, ena_conn_weight = False, ccore_flag = True, tolerance = 0.1):
    sample = read_sample(file)
    syncnet_instance = syncnet(sample, radius, enable_conn_weight = ena_conn_weight, ccore = ccore_flag)

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

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

    network = syncnet(data, color_radius, ccore = True);
    print("Network has been created");
    
    (ticks, analyser) = timedcall(network.process, 0.9995, solve_type.FAST, show_dyn);
    
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn is True):
        sync_visualizer.show_output_dynamic(analyser);
    
    clusters = analyser.allocate_clusters();
    real_clusters = [cluster for cluster in clusters if len(cluster) > noise_size];
    
    draw_image_mask_segments(source, real_clusters);
    
    if (object_radius is None):
        return;
    
    # continue analysis
    pointer_image = Image.open(source);
    image_size = pointer_image.size;
    
    object_colored_clusters = [];
    object_colored_dynamics = [];
    total_dyn = [];
    
    for cluster in clusters:
        coordinates = [];
        for index in cluster:
            y = floor(index / image_size[0]);
            x = index - y * image_size[0];
            
            coordinates.append([x, y]);
        
        print(coordinates);
        
        # perform clustering analysis of the colored objects
        if (network is not None):
            del network;
            network = None;
        
        if (len(coordinates) < noise_size):
            continue;
        
        network = syncnet(coordinates, object_radius, ccore = True);
        analyser = network.process(0.999, solve_type.FAST, show_dyn);
        
        if (show_dyn is True):
            object_colored_dynamics.append( (analyser.time, analyser.output) );
        
        object_clusters = analyser.allocate_clusters();
        
        # decode it
        real_description_clusters = [];
        for object_cluster in object_clusters:
            real_description = [];
            for index_object in object_cluster:
                real_description.append(cluster[index_object]);
            
            real_description_clusters.append(real_description);
            
            if (len(real_description) > noise_size):
                object_colored_clusters.append(real_description);
            
        # draw_image_mask_segments(source, [ cluster ]);
        # draw_image_mask_segments(source, real_description_clusters);
    
    draw_image_mask_segments(source, object_colored_clusters);
    
    if (show_dyn is True):
        draw_dynamics_set(object_colored_dynamics, None, None, None, [0, 2 * 3.14], False, False);
Exemplo n.º 17
0
def template_segmentation_image(source, color_radius, object_radius, noise_size, show_dyn):    
    data = read_image(source);
    print("Pixel dimension: ", len(data[0]));

    network = syncnet(data, color_radius, ccore = True);
    print("Network has been created");
    
    (ticks, analyser) = timedcall(network.process, 0.9995, solve_type.FAST, show_dyn);
    
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\n");
    
    if (show_dyn is True):
        sync_visualizer.show_output_dynamic(analyser);
    
    clusters = analyser.allocate_clusters();
    real_clusters = [cluster for cluster in clusters if len(cluster) > noise_size];
    
    draw_image_mask_segments(source, real_clusters);
    
    if (object_radius is None):
        return;
    
    # continue analysis
    pointer_image = Image.open(source);
    image_size = pointer_image.size;
    
    object_colored_clusters = [];
    object_colored_dynamics = [];
    total_dyn = [];
    
    for cluster in clusters:
        coordinates = [];
        for index in cluster:
            y = floor(index / image_size[0]);
            x = index - y * image_size[0];
            
            coordinates.append([x, y]);
        
        print(coordinates);
        
        # perform clustering analysis of the colored objects
        if (network is not None):
            del network;
            network = None;
        
        if (len(coordinates) < noise_size):
            continue;
        
        network = syncnet(coordinates, object_radius, ccore = True);
        analyser = network.process(0.999, solve_type.FAST, show_dyn);
        
        if (show_dyn is True):
            object_colored_dynamics.append( (analyser.time, analyser.output) );
        
        object_clusters = analyser.allocate_clusters();
        
        # decode it
        real_description_clusters = [];
        for object_cluster in object_clusters:
            real_description = [];
            for index_object in object_cluster:
                real_description.append(cluster[index_object]);
            
            real_description_clusters.append(real_description);
            
            if (len(real_description) > noise_size):
                object_colored_clusters.append(real_description);
            
        # draw_image_mask_segments(source, [ cluster ]);
        # draw_image_mask_segments(source, real_description_clusters);
    
    draw_image_mask_segments(source, object_colored_clusters);
    
    if (show_dyn is True):
        draw_dynamics_set(object_colored_dynamics, None, None, None, [0, 2 * 3.14], False, False);