Пример #1
0
def template_dynamic_legion(num_osc,
                            steps,
                            time,
                            conn_type,
                            stimulus,
                            params=None,
                            separate_repr=True,
                            ccore_flag=True):
    net = legion_network(num_osc, params, conn_type, ccore=ccore_flag)
    print("Created")

    dynamic = net.simulate(steps, time, stimulus, solution=solve_type.RK4)
    print("Simulated")

    draw_dynamics(dynamic.time,
                  dynamic.output,
                  x_title="Time",
                  y_title="x(t)",
                  separate=separate_repr)
    draw_dynamics(dynamic.time,
                  dynamic.inhibitor,
                  x_title="Time",
                  y_title="z(t)")

    ensembles = dynamic.allocate_sync_ensembles(0.1)
    print(ensembles)
Пример #2
0
def template_segmentation_image(image_file, parameters, steps, time, ccore_flag = True):
    image = read_image(image_file);
    stimulus = rgb2gray(image);
    
    for pixel_index in range(len(stimulus)):
        if (stimulus[pixel_index] < 235): stimulus[pixel_index] = 1;
        else: stimulus[pixel_index] = 0;
    
    if (parameters is None):
        parameters = legion_parameters();
    
    net = legion_network(len(stimulus), parameters, conn_type.GRID_FOUR, ccore = ccore_flag);
    output_dynamic = net.simulate(steps, time, stimulus);
    
    ensembles = output_dynamic.allocate_sync_ensembles();
    
    draw_image_mask_segments(image_file, ensembles);
    # draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)", separate = ensembles);
    
    # just for checking correctness of results - let's use classical algorithm
    dbscan_instance = dbscan(image, 3, 4, True);
    dbscan_instance.process();
    trustable_clusters = dbscan_instance.get_clusters();
    
    draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)", separate = trustable_clusters);
Пример #3
0
def template_clustering(file, map_size, trust_order, sync_order = 0.999, show_dyn = False, show_layer1 = False, show_layer2 = False, show_clusters = True):
    # Read sample
    sample = read_sample(file);

    # Create network
    network = syncsom(sample, map_size[0], map_size[1]);
    
    # Run processing
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, trust_order, show_dyn, sync_order);
    print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
    
    # Show dynamic of the last layer.
    if (show_dyn == True):
        draw_dynamics(dyn_time, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
    
    if (show_clusters == True):
        clusters = network.get_som_clusters();
        draw_clusters(network.som_layer.weights, clusters);
    
    # Show network stuff.
    if (show_layer1 == True):
        network.show_som_layer();
    
    if (show_layer2 == True):
        network.show_sync_layer();
    
    if (show_clusters == True):
        clusters = network.get_clusters();
        draw_clusters(sample, clusters);
def template_graph_coloring(filename,
                            alpha,
                            eps,
                            steps,
                            time,
                            title=None,
                            tolerance=0.1,
                            threshold_steps=10):
    if (title is None): title = filename

    graph = read_graph(filename)
    network = hysteresisgcolor(graph.data, alpha, eps)

    output_dynamic = network.simulate(steps, time)
    draw_dynamics(output_dynamic.time,
                  output_dynamic.output,
                  x_title="Time",
                  y_title="State")

    clusters = output_dynamic.allocate_clusters(tolerance, threshold_steps)
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index])

    coloring_map = output_dynamic.allocate_map_coloring(
        tolerance, threshold_steps)
    draw_graph(graph, coloring_map)
Пример #5
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();
Пример #6
0
def template_segmentation_image(image_file, parameters, steps, time, ccore_flag = True):
    image = read_image(image_file);
    stimulus = rgb2gray(image);
    
    for pixel_index in range(len(stimulus)):
        if (stimulus[pixel_index] < 235): stimulus[pixel_index] = 1;
        else: stimulus[pixel_index] = 0;
    
    if (parameters is None):
        parameters = legion_parameters();
    
    net = legion_network(len(stimulus), parameters, conn_type.GRID_FOUR, ccore = ccore_flag);
    output_dynamic = net.simulate(steps, time, stimulus);
    
    ensembles = output_dynamic.allocate_sync_ensembles();
    
    draw_image_mask_segments(image_file, ensembles);
    # draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)", separate = ensembles);
    
    # just for checking correctness of results - let's use classical algorithm
    dbscan_instance = dbscan(image, 3, 4, True);
    dbscan_instance.process();
    trustable_clusters = dbscan_instance.get_clusters();
    
    draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)", separate = trustable_clusters);
Пример #7
0
 def show_output_dynamic(hysteresis_output_dynamic):
     """!
     @brief Shows output dynamic (output of each oscillator) during simulation.
     
     @param[in] hysteresis_output_dynamic (hysteresis_dynamic): Output dynamic of the hysteresis oscillatory network.
     
     """
     
     draw_dynamics(hysteresis_output_dynamic.time, hysteresis_output_dynamic.output, x_title = "Time", y_title = "x(t)");
Пример #8
0
 def show_output_dynamic(hysteresis_output_dynamic):
     """!
     @brief Shows output dynamic (output of each oscillator) during simulation.
     
     @param[in] hysteresis_output_dynamic (hysteresis_dynamic): Output dynamic of the hysteresis oscillatory network.
     
     """
     
     draw_dynamics(hysteresis_output_dynamic.time, hysteresis_output_dynamic.output, x_title = "Time", y_title = "x(t)");
Пример #9
0
 def show_output_dynamic(sync_output_dynamic):
     """!
     @brief Shows output dynamic (output of each oscillator) during simulation.
     
     @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
     
     """
     
     draw_dynamics(sync_output_dynamic.time, sync_output_dynamic.output, x_title = "t", y_title = "phase", y_lim = [0, 2 * 3.14]);
Пример #10
0
 def show_output_dynamic(pcnn_output_dynamic, separate_representation = False):
     """!
     @brief Shows output dynamic (output of each oscillator) during simulation.
     
     @param[in] pcnn_output_dynamic (pcnn_dynamic): Output dynamic of the pulse-coupled neural network.
     @param[in] separate_representation (list): Consists of lists of oscillators where each such list consists of oscillator indexes that will be shown on separated stage.
     
     """
     
     draw_dynamics(pcnn_output_dynamic.time, pcnn_output_dynamic.output, x_title = "t", y_title = "y(t)", separate = separate_representation);
Пример #11
0
 def show_output_dynamic(pcnn_output_dynamic, separate_representation = False):
     """!
     @brief Shows output dynamic (output of each oscillator) during simulation.
     
     @param[in] pcnn_output_dynamic (pcnn_dynamic): Output dynamic of the pulse-coupled neural network.
     @param[in] separate_representation (list): Consists of lists of oscillators where each such list consists of oscillator indexes that will be shown on separated stage.
     
     """
     
     draw_dynamics(pcnn_output_dynamic.time, pcnn_output_dynamic.output, x_title = "t", y_title = "y(t)", separate = separate_representation)
Пример #12
0
def template_dynamic(num_osc, own_weight = -3, neigh_weight = -1, initial_states = None, initial_outputs = None, steps = 1000, time = 10):
    network = hysteresis_network(num_osc, own_weight, neigh_weight);
    
    if (initial_states is not None):
        network.states = initial_states;
        
    if (initial_outputs is not None):
        network.outputs = initial_outputs;
    
    (t, x) = network.simulate(steps, time);
    draw_dynamics(t, x, x_title = "Time", y_title = "x(t)");
Пример #13
0
def template_dynamic_legion(num_osc, steps, time, conn_type, stimulus, params = None, separate_repr = True, ccore_flag = True):
    net = legion_network(num_osc, params, conn_type, ccore = ccore_flag);
    print("Created");
    
    dynamic = net.simulate(steps, time, stimulus, solution = solve_type.RK4);
    print("Simulated");
    
    draw_dynamics(dynamic.time, dynamic.output, x_title = "Time", y_title = "x(t)", separate = separate_repr);
    draw_dynamics(dynamic.time, dynamic.inhibitor, x_title = "Time", y_title = "z(t)");
    
    ensembles = dynamic.allocate_sync_ensembles(0.1);
    print(ensembles);
Пример #14
0
def template_segmentation_image(source, map_som_size = [5, 5], average_neighbors = 5, sync_order = 0.998, show_dyn = False, show_som_map = False):
    data = read_image(source);
    
    network = syncsom(data, map_som_size[0], map_som_size[1]);
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, average_neighbors, show_dyn, sync_order);
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\t\tWinners: ", network.som_layer.get_winner_number(), "\n");
    
    if (show_dyn is True):
        draw_dynamics(dyn_time, dyn_phase);
    
    clusters = network.get_clusters();
    draw_image_mask_segments(source, clusters);
def template_segmentation_image(source, map_som_size = [5, 5], radius = 128.0, sync_order = 0.998, show_dyn = False, show_som_map = False):
    data = read_image(source);
    
    network = syncsom(data, map_som_size[0], map_som_size[1], 1.0);
    (ticks, (dyn_time, dyn_phase)) = timedcall(network.process, show_dyn, sync_order);
    print("Sample: ", source, "\t\tExecution time: ", ticks, "\t\tWinners: ", network.som_layer.get_winner_number(), "\n");
    
    if (show_dyn is True):
        draw_dynamics(dyn_time, dyn_phase);
    
    clusters = network.get_clusters();
    draw_image_mask_segments(source, clusters);
Пример #16
0
 def show_output_dynamic(cnn_output_dynamic):
     """!
     @brief Shows output dynamic (output of each neuron) during simulation.
     
     @param[in] cnn_output_dynamic (cnn_dynamic): Output dynamic of the chaotic neural network.
     
     @see show_dynamic_matrix
     @see show_observation_matrix
     
     """
     
     draw_dynamics(cnn_output_dynamic.time, cnn_output_dynamic.output, x_title = "t", y_title = "x");
Пример #17
0
def template_graph_coloring(filename, alpha, eps, steps, time, title = None, tolerance = 0.1):
    if (title is None): title = filename;
    
    graph = read_graph(filename);
    network = hysteresisgcolor(graph.data, alpha, eps);
    
    (t, dyn) = network.simulate(steps, time);
    draw_dynamics(t, dyn, x_title = "Time", y_title = "State");
    
    clusters = network.get_clusters(tolerance);
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
    
    coloring_map = network.get_map_coloring(tolerance);
    draw_graph(graph, coloring_map);
Пример #18
0
def template_graph_coloring(filename, alpha, eps, steps, time, title = None, tolerance = 0.1, threshold_steps = 10):
    if (title is None): title = filename;
    
    graph = read_graph(filename);
    network = hysteresisgcolor(graph.data, alpha, eps);
    
    output_dynamic = network.simulate(steps, time);
    draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "State");
    
    clusters = output_dynamic.allocate_clusters(tolerance, threshold_steps);
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
    
    coloring_map = output_dynamic.allocate_map_coloring(tolerance, threshold_steps);
    draw_graph(graph, coloring_map);
Пример #19
0
def template_dynamic_hhn(num_osc,
                         steps,
                         time,
                         stimulus=None,
                         params=None,
                         separate_representation=False):
    net = hhn_network(num_osc, stimulus, params)

    (t, dyn) = net.simulate(steps, time)

    draw_dynamics(t,
                  dyn,
                  x_title="Time",
                  y_title="V",
                  separate=separate_representation)
Пример #20
0
def template_dynamic(num_osc,
                     own_weight=-3,
                     neigh_weight=-1,
                     initial_states=None,
                     initial_outputs=None,
                     steps=1000,
                     time=10):
    network = hysteresis_network(num_osc, own_weight, neigh_weight)

    if (initial_states is not None):
        network.states = initial_states

    if (initial_outputs is not None):
        network.outputs = initial_outputs

    (t, x) = network.simulate(steps, time)
    draw_dynamics(t, x, x_title="Time", y_title="x(t)")
Пример #21
0
def template_graph_coloring(filename,
                            alpha,
                            eps,
                            steps,
                            time,
                            title=None,
                            tolerance=0.1):
    if (title is None): title = filename

    graph = read_graph(filename)
    network = hysteresisgcolor(graph.data, alpha, eps)

    (t, dyn) = network.simulate(steps, time)
    draw_dynamics(t, dyn, x_title="Time", y_title="State")

    clusters = network.get_clusters(tolerance)
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index])

    coloring_map = network.get_map_coloring(tolerance)
    draw_graph(graph, coloring_map)
Пример #22
0
    def show_output_dynamic(sync_output_dynamic):
        """!
        @brief Shows output dynamic (output of each oscillator) during simulation.
        
        @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
        
        @see show_output_dynamics
        
        """

        figure, _ = draw_dynamics(sync_output_dynamic.time, sync_output_dynamic.output, x_title="t", y_title="phase", y_lim=[0, 2 * pi])
        plt.close(figure)
Пример #23
0
def template_dynamic_hhn(num_osc, steps, time, stimulus=None, params=None, separate_representation=False):
    net = hhn_network(num_osc, stimulus, params)

    (t, dyn) = net.simulate(steps, time)

    draw_dynamics(t, dyn, x_title="Time", y_title="V", separate=separate_representation)