Exemplo n.º 1
0
    def testListConnectionRepresentation(self):
        net = legion_network(3, [1, 0, 1], type_conn = conn_type.LIST_BIDIR, type_conn_represent = conn_represent.LIST);
        (t, x, z) = net.simulate(1000, 2000);
 
        assert extract_number_oscillations(x, 0) > 1;
        assert extract_number_oscillations(x, 1) == 1;   
        assert extract_number_oscillations(x, 2) > 1;  
Exemplo n.º 2
0
 def templateOutputDynamicInformation(stimulus, params, type_conn, sim_steps, sim_time, ccore_flag):
     legion_instance = legion_network(len(stimulus), params, type_conn, ccore = ccore_flag);
     dynamic = legion_instance.simulate(sim_steps, sim_time, stimulus);
      
     assert len(dynamic.output) > 0;
     assert len(dynamic.inhibitor) > 0;
     assert len(dynamic.time) > 0;
Exemplo n.º 3
0
 def testMixStimulatedThreeOscillators(self):
     net = legion_network(3, [1, 0, 1], type_conn = conn_type.LIST_BIDIR);
     (t, x, z) = net.simulate(1000, 2000);
      
     assert extract_number_oscillations(x, 0) > 1;
     assert extract_number_oscillations(x, 1) == 1;   
     assert extract_number_oscillations(x, 2) > 1;       
Exemplo n.º 4
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);
Exemplo n.º 5
0
 def testUstimulatedOscillatorWithoutLateralPotential(self):
     params = legion_parameters();
     params.teta = 0;    # because no neighbors at all
   
     net = legion_network(1, type_conn = conn_type.NONE, parameters = params, ccore = False);
     dynamic = net.simulate(1000, 200, [0]);
      
     assert extract_number_oscillations(dynamic.output, amplitude_threshold = 0.0) == 0;
Exemplo n.º 6
0
 def testStimulatedOscillatorWithoutLateralPotential(self):
     params = legion_parameters();
     params.teta = 0;    # because no neighbors at all
      
     net = legion_network(1, [1], type_conn = conn_type.NONE, parameters = params);
     (t, x, z) = net.simulate(1000, 200);
      
     assert extract_number_oscillations(x) > 1;      
Exemplo n.º 7
0
 def testStimulatedOscillatorWithoutLateralPotential(self):
     params = legion_parameters();
     params.teta = 0;    # because no neighbors at all
      
     net = legion_network(1, type_conn = conn_type.NONE, parameters = params, ccore = False);
     dynamic = net.simulate(2000, 400, [1]);
      
     assert extract_number_oscillations(dynamic.output) > 1;
Exemplo n.º 8
0
 def testUnstimulatedTwoOscillators(self):
     params = legion_parameters();
     params.teta_p = 2.5;
      
     net = legion_network(2, [0, 0], type_conn = conn_type.LIST_BIDIR, parameters = params);
     (t, x, z) = net.simulate(1000, 1000);
      
     assert extract_number_oscillations(x, 0) == 1;
     assert extract_number_oscillations(x, 1) == 1;
Exemplo n.º 9
0
def template_dynamic_legion(num_osc, steps, time, conn_type = conn_type.NONE, stimulus = None, params = None, separate_repr = True):
    net = legion_network(num_osc, stimulus, type_conn = conn_type, parameters = params);
    (t, x, z) = net.simulate(steps, time, solution = solve_type.RK4);
    
    draw_dynamics(t, x, x_title = "Time", y_title = "x(t)", separate = separate_repr);
    draw_dynamics(t, z, x_title = "Time", y_title = "z(t)");
    
    ensembles = net.allocate_sync_ensembles(0.1);
    print(ensembles);
Exemplo n.º 10
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);
Exemplo n.º 11
0
 def templateSyncEnsembleAllocation(self, stimulus, params, type_conn, sim_steps, sim_time, expected_clusters, ccore_flag = False):
     result_testing = False;
     
     for _ in range(0, 3, 1):
         net = legion_network(len(stimulus), params, type_conn, ccore = ccore_flag);
         dynamic = net.simulate(sim_steps, sim_time, stimulus);
         
         ensembles = dynamic.allocate_sync_ensembles(0.1);
         if (ensembles != expected_clusters):
             continue;
         
         result_testing = True;
         break;
     
     assert result_testing;
Exemplo n.º 12
0
    def templateSyncEnsembleAllocation(self, stimulus, params, type_conn,
                                       sim_steps, sim_time, expected_clusters):
        result_testing = False

        for attempt in range(0, 3, 1):
            net = legion_network(len(stimulus), params, type_conn)
            dynamic = net.simulate(sim_steps, sim_time, stimulus)

            ensembles = dynamic.allocate_sync_ensembles(0.1)
            if (ensembles != expected_clusters):
                continue

            result_testing = True
            break

        assert result_testing
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def testStimulatedOscillatorWithLateralPotential(self):
     net = legion_network(1, type_conn = conn_type.NONE, ccore = False);
     dynamic = net.simulate(2000, 400, [1]);
      
     assert extract_number_oscillations(dynamic.output, amplitude_threshold = 0.0) >= 1;
Exemplo n.º 15
0
    def testStimulatedTwoOscillators(self):
        net = legion_network(2, [1, 1], type_conn=conn_type.LIST_BIDIR)
        (t, x, z) = net.simulate(1000, 2000)

        assert extract_number_oscillations(x, 0) > 1
        assert extract_number_oscillations(x, 1) > 1
Exemplo n.º 16
0
 def testStimulatedOscillatorWithLateralPotential(self):
     net = legion_network(1, [1], type_conn = conn_type.NONE);
     (t, x, z) = net.simulate(1000, 200);
      
     assert extract_number_oscillations(x) == 1;
Exemplo n.º 17
0
 def templateOscillationsWithStructures(type_conn, ccore_flag):
     net = legion_network(4, type_conn = conn_type.LIST_BIDIR, ccore = ccore_flag);
     dynamic = net.simulate(500, 1000, [1, 1, 1, 1]);
       
     for i in range(len(net)):
         assert extract_number_oscillations(dynamic.output, i) > 1;
Exemplo n.º 18
0
    def testStimulatedOscillatorWithLateralPotential(self):
        net = legion_network(1, type_conn=conn_type.NONE)
        dynamic = net.simulate(1000, 200, [1])

        assert extract_number_oscillations(dynamic.output) == 1
Exemplo n.º 19
0
    def testStimulatedOscillatorWithLateralPotential(self):
        net = legion_network(1, [1], type_conn=conn_type.NONE)
        (t, x, z) = net.simulate(1000, 200)

        assert extract_number_oscillations(x) == 1
Exemplo n.º 20
0
    def testMixStimulatedThreeOscillatorsByCore(self):
        net = legion_network(3, type_conn=conn_type.LIST_BIDIR, ccore=True)
        dynamic = net.simulate(1000, 2000, [1, 0, 1])

        assert extract_number_oscillations(dynamic.output, 0) > 1
        assert extract_number_oscillations(dynamic.output, 2) > 1
Exemplo n.º 21
0
   def testListConnectionRepresentation(self):
       net = legion_network(3, type_conn = conn_type.LIST_BIDIR, type_conn_represent = conn_represent.LIST, ccore = False);
       dynamic = net.simulate(1000, 2000, [1, 0, 1]);
 
       assert extract_number_oscillations(dynamic.output, 0) > 1;  
       assert extract_number_oscillations(dynamic.output, 2) > 1;  
Exemplo n.º 22
0
 def templateOscillationsWithStructures(self, type_conn, ccore_flag = False):
     net = legion_network(4, type_conn = conn_type.LIST_BIDIR, ccore = ccore_flag);
     dynamic = net.simulate(500, 1000, [1, 1, 1, 1]);
      
     for i in range(len(net)):
         assert extract_number_oscillations(dynamic.output, i) > 1;
Exemplo n.º 23
0
 def templateOscillationsWithStructures(self, type_conn):
     net = legion_network(4, [1, 1, 1, 1], type_conn = conn_type.LIST_BIDIR);
     (t, x, z) = net.simulate(500, 1000);
      
     for i in range(net.num_osc):
         assert extract_number_oscillations(x, i) > 1;
Exemplo n.º 24
0
 def testMixStimulatedThreeOscillators(self):
     net = legion_network(3, type_conn = conn_type.LIST_BIDIR, ccore = False);
     dynamic = net.simulate(1000, 2000, [1, 0, 1]);
       
     assert extract_number_oscillations(dynamic.output, 0) > 1; 
     assert extract_number_oscillations(dynamic.output, 2) > 1;
Exemplo n.º 25
0
   def testListConnectionRepresentation(self):
       net = legion_network(3, type_conn = conn_type.LIST_BIDIR, type_conn_represent = conn_represent.LIST, ccore = False);
       dynamic = net.simulate(1000, 2000, [1, 0, 1]);
 
       assert extract_number_oscillations(dynamic.output, 0) > 1;  
       assert extract_number_oscillations(dynamic.output, 2) > 1;  
Exemplo n.º 26
0
 def testStimulatedTwoOscillators(self):
     net = legion_network(2, type_conn = conn_type.LIST_BIDIR);
     dynamic = net.simulate(1000, 2000, [1, 1]);
      
     assert extract_number_oscillations(dynamic.output, 0) > 1;
     assert extract_number_oscillations(dynamic.output, 1) > 1;
Exemplo n.º 27
0
    def testStimulatedTwoOscillators(self):
        net = legion_network(2, type_conn=conn_type.LIST_BIDIR)
        dynamic = net.simulate(1000, 2000, [1, 1])

        assert extract_number_oscillations(dynamic.output, 0) > 1
        assert extract_number_oscillations(dynamic.output, 1) > 1
Exemplo n.º 28
0
 def templateOscillationsWithStructures(self, type_conn):
     net = legion_network(4, type_conn = conn_type.LIST_BIDIR);
     dynamic = net.simulate(500, 1000, [1, 1, 1, 1]);
      
     for i in range(net.num_osc):
         assert extract_number_oscillations(dynamic.output, i) > 1;
Exemplo n.º 29
0
 def templateSyncEnsembleAllocation(self, stimulus, params, type_conn, sim_steps, sim_time, expected_clusters):
     net = legion_network(len(stimulus), params, type_conn);
     dynamic = net.simulate(sim_steps, sim_time, stimulus);
     
     ensembles = dynamic.allocate_sync_ensembles(0.1);
     assert ensembles == expected_clusters;
Exemplo n.º 30
0
    def testStimulatedOscillatorWithLateralPotential(self):
        net = legion_network(1, type_conn=conn_type.NONE, ccore=False)
        dynamic = net.simulate(2000, 400, [1])

        assert extract_number_oscillations(dynamic.output,
                                           amplitude_threshold=0.0) >= 1
Exemplo n.º 31
0
 def testStimulatedOscillatorWithLateralPotential(self):
     net = legion_network(1, type_conn = conn_type.NONE);
     dynamic = net.simulate(1000, 200, [1]);
      
     assert extract_number_oscillations(dynamic.output) == 1;
Exemplo n.º 32
0
    def templateOscillationsWithStructures(self, type_conn):
        net = legion_network(4, [1, 1, 1, 1], type_conn=conn_type.LIST_BIDIR)
        (t, x, z) = net.simulate(500, 1000)

        for i in range(net.num_osc):
            assert extract_number_oscillations(x, i) > 1