def visualize(num_osc, steps, type_conn, repr_type, stimulus, height, width, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, None, None, ccore); dynamic = net.simulate(steps, stimulus); pcnn_visualizer.show_time_signal(dynamic); pcnn_visualizer.show_output_dynamic(dynamic); pcnn_visualizer.animate_spike_ensembles(dynamic, (height, width));
def templateGridRectangleDynamicLength(num_osc, steps, type_conn, repr_type, height, width, stimulus, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, height, width, ccore); dynamic = net.simulate(steps, stimulus); assert steps == len(dynamic); assert num_osc == len(dynamic.output[0]); assert steps == len(dynamic.allocate_time_signal());
def templateAllocationInRectangleStructure(self, num_osc, height, width, steps, type_conn, repr_type, stimulus, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, height, width, ccore); dynamic = net.simulate(steps, stimulus); assert steps == len(dynamic); assert num_osc == len(dynamic.output[0]); assert steps == len(dynamic.allocate_time_signal());
def templateDynamicLength(self, num_osc, steps, type_conn, repr_type, stimulus, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, None, None, ccore) dynamic = net.simulate(steps, stimulus) assert steps == len(dynamic) assert num_osc == len(dynamic.output[0]) assert steps == len(dynamic.allocate_time_signal())
def templateDynamicLength(self, num_osc, steps, type_conn, repr_type, stimulus, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, ccore) dynamic = net.simulate(steps, stimulus) assert steps == len(dynamic) assert num_osc == len(dynamic.output[0]) assert steps == len(dynamic.allocate_time_signal())
def template_dynamic_pcnn(num_osc, steps, stimulus = None, params = None, conn_type = conn_type.NONE, separate_representation = True, ccore_flag = True): net = pcnn_network(num_osc, params, conn_type, ccore = ccore_flag); dynamic = net.simulate(steps, stimulus); ensembles = dynamic.allocate_sync_ensembles(); print("Number of objects:", len(ensembles), "\nEnsembles:", ensembles); pcnn_visualizer.show_output_dynamic(dynamic); return ensembles;
def template_dynamic_pcnn(num_osc, steps, stimulus = None, params = None, conn_type = conn_type.NONE, separate_representation = True, ccore_flag = True): net = pcnn_network(num_osc, params, conn_type, ccore = ccore_flag); dynamic = net.simulate(steps, stimulus); ensembles = dynamic.allocate_sync_ensembles(); print("Number of objects:", len(ensembles), "\nEnsembles:", ensembles); draw_dynamics(dynamic.time, dynamic.output, x_title = "t", y_title = "y(t)", separate = separate_representation); return ensembles;
def templateAllocationInRectangleStructure(num_osc, height, width, steps, type_conn, repr_type, stimulus, ccore): net = pcnn_network(num_osc, None, type_conn, repr_type, height, width, ccore) dynamic = net.simulate(steps, stimulus) assert steps == len(dynamic) assert num_osc == len(dynamic.output[0]) assert steps == len(dynamic.allocate_time_signal())
def template_segmentation_image(image, parameters, simulation_time, brightness, scale_color = True, fastlinking = False, show_spikes = False, ccore_flag = True): image_source = Image.open(image); image_size = image_source.size; width = image_size[0]; height = image_size[1]; stimulus = read_image(image); stimulus = rgb2gray(stimulus); if (brightness != None): for pixel_index in range(len(stimulus)): if (stimulus[pixel_index] < brightness): stimulus[pixel_index] = 1; else: stimulus[pixel_index] = 0; else: maximum_stimulus = float(max(stimulus)); minimum_stimulus = float(min(stimulus)); delta = maximum_stimulus - minimum_stimulus; for pixel_index in range(len(stimulus)): if (scale_color is True): stimulus[pixel_index] = 1.0 - ((float(stimulus[pixel_index]) - minimum_stimulus) / delta); else: stimulus[pixel_index] = float(stimulus[pixel_index]) / 255; if (parameters is None): parameters = pcnn_parameters(); parameters.AF = 0.1; parameters.AL = 0.1; parameters.AT = 0.8; parameters.VF = 1.0; parameters.VL = 1.0; parameters.VT = 30.0; parameters.W = 1.0; parameters.M = 1.0; parameters.FAST_LINKING = fastlinking; net = pcnn_network(len(stimulus), parameters, conn_type.GRID_EIGHT, height = height, width = width, ccore = ccore_flag); output_dynamic = net.simulate(simulation_time, stimulus); pcnn_visualizer.show_output_dynamic(output_dynamic); ensembles = output_dynamic.allocate_sync_ensembles(); draw_image_mask_segments(image, ensembles); pcnn_visualizer.show_time_signal(output_dynamic); if (show_spikes is True): spikes = output_dynamic.allocate_spike_ensembles(); draw_image_mask_segments(image, spikes); pcnn_visualizer.animate_spike_ensembles(output_dynamic, image_size);
def templateDynamicLength(num_osc, steps, type_conn, repr_type, stimulus, ccore, **kwargs): params = kwargs.get('params', None); net = pcnn_network(num_osc, params, type_conn, repr_type, None, None, ccore); dynamic = net.simulate(steps, stimulus); assert steps == len(dynamic); assert num_osc == len(dynamic.output[0]); assert steps == len(dynamic.allocate_time_signal()); return net;
def templateSyncEnsemblesAllocation(num_osc, type_conn, steps, stimulus, ccore, ensembles): net = pcnn_network(num_osc, None, type_conn, conn_represent.MATRIX, None, None, ccore) dynamic = net.simulate(steps, stimulus) assert steps == len(dynamic) sync_ensembles = dynamic.allocate_sync_ensembles() if (ensembles is not None): assert len(ensembles) == len(sync_ensembles) for expected_ensemble in ensembles: ensemble_correct = False for index_ensemble in range(len(sync_ensembles)): sorted_expected_ensemble = expected_ensemble.sort() sorted_ensemble = sync_ensembles[index_ensemble].sort() if (sorted_expected_ensemble == sorted_ensemble): ensemble_correct = True break assert (True == ensemble_correct) unique_indexes = set() time_signal = dynamic.allocate_time_signal() spike_ensembles = dynamic.allocate_spike_ensembles() sync_ensembles = dynamic.allocate_sync_ensembles() for ensemble in spike_ensembles: assert len(ensemble) in time_signal for ensemble in sync_ensembles: spike_ensembles_exist = False for index in range(len(spike_ensembles)): if ensemble == spike_ensembles[index]: spike_ensembles_exist = True break assert (True == spike_ensembles_exist) for index_oscillator in ensemble: assert index_oscillator not in unique_indexes unique_indexes.add(index_oscillator)
def templateSyncEnsemblesAllocation(self, num_osc, type_conn, steps, stimulus, ccore, ensembles): net = pcnn_network(num_osc, None, type_conn, conn_represent.MATRIX, None, None, ccore) dynamic = net.simulate(steps, stimulus) assert steps == len(dynamic) sync_ensembles = dynamic.allocate_sync_ensembles() if ensembles is not None: assert len(ensembles) == len(sync_ensembles) for expected_ensemble in ensembles: ensemble_correct = False for index_ensemble in range(len(sync_ensembles)): sorted_expected_ensemble = expected_ensemble.sort() sorted_ensemble = sync_ensembles[index_ensemble].sort() if sorted_expected_ensemble == sorted_ensemble: ensemble_correct = True break assert True == ensemble_correct unique_indexes = set() time_signal = dynamic.allocate_time_signal() spike_ensembles = dynamic.allocate_spike_ensembles() sync_ensembles = dynamic.allocate_sync_ensembles() for ensemble in spike_ensembles: assert len(ensemble) in time_signal for ensemble in sync_ensembles: spike_ensembles_exist = False for index in range(len(spike_ensembles)): if ensemble == spike_ensembles[index]: spike_ensembles_exist = True break assert True == spike_ensembles_exist for index_oscillator in ensemble: assert index_oscillator not in unique_indexes unique_indexes.add(index_oscillator)
def templateSyncEnsemblesAllocation(num_osc, type_conn, steps, stimulus, ccore, ensembles): net = pcnn_network(num_osc, None, type_conn, conn_represent.MATRIX, None, None, ccore); dynamic = net.simulate(steps, stimulus); assert steps == len(dynamic); sync_ensembles = dynamic.allocate_sync_ensembles(); if (ensembles is not None): assert len(ensembles) == len(sync_ensembles); for expected_ensemble in ensembles: ensemble_correct = False; for index_ensemble in range(len(sync_ensembles)): sorted_expected_ensemble = expected_ensemble.sort(); sorted_ensemble = sync_ensembles[index_ensemble].sort(); if (sorted_expected_ensemble == sorted_ensemble): ensemble_correct = True; break; assert (True == ensemble_correct); unique_indexes = set(); time_signal = dynamic.allocate_time_signal(); spike_ensembles = dynamic.allocate_spike_ensembles(); sync_ensembles = dynamic.allocate_sync_ensembles(); for ensemble in spike_ensembles: assert len(ensemble) in time_signal; for ensemble in sync_ensembles: spike_ensembles_exist = False; for index in range(len(spike_ensembles)): if ensemble == spike_ensembles[index]: spike_ensembles_exist = True; break; assert (True == spike_ensembles_exist); for index_oscillator in ensemble: assert index_oscillator not in unique_indexes; unique_indexes.add(index_oscillator);
def template_dynamic_pcnn(num_osc, steps, stimulus=None, params=None, conn_type=conn_type.NONE, separate_representation=True, ccore_flag=True): net = pcnn_network(num_osc, params, conn_type, ccore=ccore_flag) dynamic = net.simulate(steps, stimulus) ensembles = dynamic.allocate_sync_ensembles() print("Number of objects:", len(ensembles), "\nEnsembles:", ensembles) draw_dynamics(dynamic.time, dynamic.output, x_title="t", y_title="y(t)", separate=separate_representation) return ensembles
def template_segmentation_image(image, parameters, simulation_time, brightness, scale_color=True, fastlinking=False, show_spikes=False, ccore_flag=True): image_source = Image.open(image) image_size = image_source.size width = image_size[0] height = image_size[1] stimulus = read_image(image) stimulus = rgb2gray(stimulus) if brightness is not None: for pixel_index in range(len(stimulus)): if stimulus[pixel_index] < brightness: stimulus[pixel_index] = 1 else: stimulus[pixel_index] = 0 else: maximum_stimulus = float(max(stimulus)) minimum_stimulus = float(min(stimulus)) delta = maximum_stimulus - minimum_stimulus for pixel_index in range(len(stimulus)): if scale_color is True: stimulus[pixel_index] = 1.0 - ( (float(stimulus[pixel_index]) - minimum_stimulus) / delta) else: stimulus[pixel_index] = float(stimulus[pixel_index]) / 255 if parameters is None: parameters = pcnn_parameters() parameters.AF = 0.1 parameters.AL = 0.1 parameters.AT = 0.8 parameters.VF = 1.0 parameters.VL = 1.0 parameters.VT = 30.0 parameters.W = 1.0 parameters.M = 1.0 parameters.FAST_LINKING = fastlinking net = pcnn_network(len(stimulus), parameters, conn_type.GRID_EIGHT, height=height, width=width, ccore=ccore_flag) output_dynamic = net.simulate(simulation_time, stimulus) pcnn_visualizer.show_output_dynamic(output_dynamic) ensembles = output_dynamic.allocate_sync_ensembles() draw_image_mask_segments(image, ensembles) pcnn_visualizer.show_time_signal(output_dynamic) if show_spikes is True: spikes = output_dynamic.allocate_spike_ensembles() draw_image_mask_segments(image, spikes) pcnn_visualizer.animate_spike_ensembles(output_dynamic, image_size)