コード例 #1
0
 def frame_generation(index_iteration):
     print(index_iteration);
     
     figure.clf();
     
     figure.suptitle("Hodgkin-Huxley Network (iteration: " + str(index_iteration) +")", fontsize = 18, fontweight = 'bold');
     
     ax1 = figure.add_subplot(121);
     ax2 = figure.add_subplot(122);
     
     end_iteration = index_iteration;
     if (end_iteration > len(dyn_peripheral)):
         end_iteration = len(dyn_peripheral);
     
     dynamic_length = 100;
     begin_iteration = end_iteration - dynamic_length;
     if (begin_iteration < 0):
         begin_iteration = 0;
     
     # Display output dynamic
     xlim = [dyn_time[begin_iteration], dyn_time[begin_iteration + dynamic_length]];
     visualizer = dynamic_visualizer(1, x_title="Time", y_title="V", x_lim=xlim, y_lim=ylim);
     
     dyn_time_segment = [ dyn_time[i] for i in range(begin_iteration, end_iteration, 1) ];
     dyn_peripheral_segment = [ dyn_peripheral[i] for i in range(begin_iteration, end_iteration, 1) ];
     
     visualizer.append_dynamic(dyn_time_segment, dyn_peripheral_segment);
     visualizer.show(ax1, False);
     
     visualize_segmenetation(end_iteration, ax2, step);
     
     return [ figure.gca() ];
コード例 #2
0
 def frame_generation(index_iteration):
     print(index_iteration)
     
     figure.clf()
     
     figure.suptitle("Hodgkin-Huxley Network (iteration: " + str(index_iteration) +")", fontsize = 18, fontweight = 'bold')
     
     ax1 = figure.add_subplot(121)
     ax2 = figure.add_subplot(122)
     
     end_iteration = index_iteration
     if (end_iteration > len(dyn_peripheral)):
         end_iteration = len(dyn_peripheral)
     
     dynamic_length = 100
     begin_iteration = end_iteration - dynamic_length
     if begin_iteration < 0:
         begin_iteration = 0
     
     # Display output dynamic
     xlim = [dyn_time[begin_iteration], dyn_time[begin_iteration + dynamic_length]]
     visualizer = dynamic_visualizer(1, x_title="Time", y_title="V", x_lim=xlim, y_lim=ylim)
     
     dyn_time_segment = [ dyn_time[i] for i in range(begin_iteration, end_iteration, 1) ]
     dyn_peripheral_segment = [ dyn_peripheral[i] for i in range(begin_iteration, end_iteration, 1) ]
     
     visualizer.append_dynamic(dyn_time_segment, dyn_peripheral_segment)
     visualizer.show(ax1, False)
     
     visualize_segmenetation(end_iteration, ax2, step)
     
     return [ figure.gca() ]
コード例 #3
0
    def testVisualizeSeveralDynamicsOneCanvasNoCrash(self):
        t1 = [0, 1, 2, 3, 4, 5, 6, 7];
        y1 = [0, 0, 1, 2, 0, 1, 2, 0];

        t2 = [0, 1, 2, 3, 4, 5, 6, 7];
        y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t1, y1);
        visualizer.append_dynamics(t2, y2);
コード例 #4
0
    def testVisualizeSeveralDynamicsOneCanvasNoCrash(self):
        t1 = [0, 1, 2, 3, 4, 5, 6, 7];
        y1 = [0, 0, 1, 2, 0, 1, 2, 0];

        t2 = [0, 1, 2, 3, 4, 5, 6, 7];
        y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t1, y1);
        visualizer.append_dynamics(t2, y2);
コード例 #5
0
    def testVisualizeSeveralDynamicsSeveralCanvasesNoCrash(self):
        t1 = [0, 1, 2, 3, 4, 5, 6, 7];
        y1 = [0, 0, 1, 2, 0, 1, 2, 0];

        t2 = [0, 1, 2, 3, 4, 5, 6, 7];
        y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(3);
        visualizer.append_dynamic(t1, y1, canvas=0);
        visualizer.append_dynamics(t2, y2, canvas=1, separate=True);
コード例 #6
0
    def testVisualizeSeveralDynamicsSeveralCanvasesNoCrash(self):
        t1 = [0, 1, 2, 3, 4, 5, 6, 7];
        y1 = [0, 0, 1, 2, 0, 1, 2, 0];

        t2 = [0, 1, 2, 3, 4, 5, 6, 7];
        y2 = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(3);
        visualizer.append_dynamic(t1, y1, canvas=0);
        visualizer.append_dynamics(t2, y2, canvas=1, separate=True);
コード例 #7
0
ファイル: hhn_examples.py プロジェクト: annoviko/pyclustering
def template_dynamic_hhn(num_osc, steps, time, stimulus = None, params = None, separate = False, ccore_flag = False):
    net = hhn_network(num_osc, stimulus, params, ccore = ccore_flag);

    (t, dyn_peripheral, dyn_central) = net.simulate(steps, time);

    amount_canvases = 1;
    if (isinstance(separate, list)):
        amount_canvases = len(separate) + 2;
    elif (separate is True):
        amount_canvases = len(dyn_peripheral[0]) + 2;
    
    visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False);
    visualizer.append_dynamics(t, dyn_peripheral, 0, separate);
    visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True);
    visualizer.show();
コード例 #8
0
def template_dynamic_hhn(num_osc, steps, time, stimulus = None, params = None, separate = False, ccore_flag = False):
    net = hhn_network(num_osc, stimulus, params, ccore = ccore_flag);

    (t, dyn_peripheral, dyn_central) = net.simulate(steps, time);

    amount_canvases = 1;
    if (isinstance(separate, list)):
        amount_canvases = len(separate) + 2;
    elif (separate is True):
        amount_canvases = len(dyn_peripheral[0]) + 2;
    
    visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False);
    visualizer.append_dynamics(t, dyn_peripheral, 0, separate);
    visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True);
    visualizer.show();
コード例 #9
0
    def testVisualizeSeparateListNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(2);
        visualizer.append_dynamics(t, y, canvas=0, separate=[ [0], [1] ]);
コード例 #10
0
    def testVisualizeMultipleDynamicNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamics(t, y);
コード例 #11
0
    def testVisualizeSignleDynamicNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t, y);
コード例 #12
0
    def testVisualizeUnusedCanvasesNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(3);
        visualizer.append_dynamic(t, y, canvas=0, color='red');
コード例 #13
0
    def testVisualizeSeparateSequenceNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7]
        y = [[0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2]]

        visualizer = dynamic_visualizer(2)
        visualizer.append_dynamics(t, y, canvas=0, separate=True)
コード例 #14
0
    def testVisualizeSeparateListNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(2);
        visualizer.append_dynamics(t, y, canvas=0, separate=[ [0], [1] ]);
コード例 #15
0
    def testVisualizeMultipleDynamicNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [ [0, 0], [0, 0], [1, 0], [2, 1], [0, 2], [1, 0], [2, 1], [0, 2] ];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamics(t, y);
コード例 #16
0
    def testVisualizeSignleDynamicNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t, y);
コード例 #17
0
    def testVisualizeUnusedCanvasesNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(3);
        visualizer.append_dynamic(t, y, canvas=0, color='red');
コード例 #18
0
    def testVisualizeDynamicWithColorNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t, y, canvas=0, color='red');
コード例 #19
0
    def testVisualizeDynamicWithColorNoCrash(self):
        t = [0, 1, 2, 3, 4, 5, 6, 7];
        y = [0, 0, 1, 2, 0, 1, 2, 0];

        visualizer = dynamic_visualizer(1);
        visualizer.append_dynamic(t, y, canvas=0, color='red');
コード例 #20
0
def template_image_segmentation(image_file, steps, time, dynamic_file_prefix):
    image = read_image(image_file)
    stimulus = rgb2gray(image)

    params = hhn_parameters()
    params.deltah = 650
    params.w1 = 0.1
    params.w2 = 9.0
    params.w3 = 5.0
    params.threshold = -10

    stimulus = [255.0 - pixel for pixel in stimulus]
    divider = max(stimulus) / 50.0
    stimulus = [int(pixel / divider) for pixel in stimulus]

    t, dyn_peripheral, dyn_central = None, None, None

    if (not os.path.exists(dynamic_file_prefix + 'dynamic_time.txt') or
            not os.path.exists(dynamic_file_prefix + 'dynamic_peripheral.txt')
            or not os.path.exists(dynamic_file_prefix +
                                  'dynamic_dyn_central.txt')):

        print(
            "File with output dynamic is not found - simulation will be performed - it may take some time, be patient."
        )

        net = hhn_network(len(stimulus), stimulus, params, ccore=True)

        (t, dyn_peripheral, dyn_central) = net.simulate(steps, time)

        print("Store dynamic to save time for simulation next time.")

        with open(dynamic_file_prefix + 'dynamic_time.txt',
                  'wb') as file_descriptor:
            pickle.dump(t, file_descriptor)

        with open(dynamic_file_prefix + 'dynamic_peripheral.txt',
                  'wb') as file_descriptor:
            pickle.dump(dyn_peripheral, file_descriptor)

        with open(dynamic_file_prefix + 'dynamic_dyn_central.txt',
                  'wb') as file_descriptor:
            pickle.dump(dyn_central, file_descriptor)
    else:
        print("Load output dynamic from file.")

        with open(dynamic_file_prefix + 'dynamic_time.txt',
                  'rb') as file_descriptor:
            t = pickle.load(file_descriptor)

        with open(dynamic_file_prefix + 'dynamic_peripheral.txt',
                  'rb') as file_descriptor:
            dyn_peripheral = pickle.load(file_descriptor)

        with open(dynamic_file_prefix + 'dynamic_dyn_central.txt',
                  'rb') as file_descriptor:
            dyn_central = pickle.load(file_descriptor)

    animate_segmentation(t, dyn_peripheral, image_file, 200)

    # just for checking correctness of results - let's use classical algorithm
    if (False):
        dbscan_instance = dbscan(image, 3, 4, True)
        dbscan_instance.process()
        trustable_clusters = dbscan_instance.get_clusters()

        amount_canvases = len(trustable_clusters) + 2
        visualizer = dynamic_visualizer(amount_canvases,
                                        x_title="Time",
                                        y_title="V",
                                        y_labels=False)
        visualizer.append_dynamics(t, dyn_peripheral, 0, trustable_clusters)
        visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True)
        visualizer.show()
コード例 #21
0
def template_image_segmentation(image_file, steps, time, dynamic_file_prefix):
    image = read_image(image_file);
    stimulus = rgb2gray(image);

    params = hhn_parameters();
    params.deltah = 650;
    params.w1 = 0.1;
    params.w2 = 9.0;
    params.w3 = 5.0;
    params.threshold = -10;

    stimulus = [255.0 - pixel for pixel in stimulus];
    divider = max(stimulus) / 50.0;
    stimulus = [int(pixel / divider) for pixel in stimulus];

    t, dyn_peripheral, dyn_central = None, None, None;

    if ( not os.path.exists(dynamic_file_prefix + 'dynamic_time.txt') or
         not os.path.exists(dynamic_file_prefix + 'dynamic_peripheral.txt') or
         not os.path.exists(dynamic_file_prefix + 'dynamic_dyn_central.txt') ):
        
        print("File with output dynamic is not found - simulation will be performed - it may take some time, be patient.");

        net = hhn_network(len(stimulus), stimulus, params, ccore=True);

        (t, dyn_peripheral, dyn_central) = net.simulate(steps, time);

        print("Store dynamic to save time for simulation next time.");

        with open(dynamic_file_prefix + 'dynamic_time.txt', 'wb') as file_descriptor:
            pickle.dump(t, file_descriptor);

        with open(dynamic_file_prefix + 'dynamic_peripheral.txt', 'wb') as file_descriptor:
            pickle.dump(dyn_peripheral, file_descriptor);

        with open(dynamic_file_prefix + 'dynamic_dyn_central.txt', 'wb') as file_descriptor:
            pickle.dump(dyn_central, file_descriptor);
    else:
        print("Load output dynamic from file.");
        
        with open (dynamic_file_prefix + 'dynamic_time.txt', 'rb') as file_descriptor:
            t = pickle.load(file_descriptor);

        with open (dynamic_file_prefix + 'dynamic_peripheral.txt', 'rb') as file_descriptor:
            dyn_peripheral = pickle.load(file_descriptor);

        with open (dynamic_file_prefix + 'dynamic_dyn_central.txt', 'rb') as file_descriptor:
            dyn_central = pickle.load(file_descriptor);

    animate_segmentation(t, dyn_peripheral, image_file, 200);

    # just for checking correctness of results - let's use classical algorithm
    if (False):
        dbscan_instance = dbscan(image, 3, 4, True);
        dbscan_instance.process();
        trustable_clusters = dbscan_instance.get_clusters();
    
        amount_canvases = len(trustable_clusters) + 2;
        visualizer = dynamic_visualizer(amount_canvases, x_title = "Time", y_title = "V", y_labels = False);
        visualizer.append_dynamics(t, dyn_peripheral, 0, trustable_clusters);
        visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True);
        visualizer.show();