diff --git a/Exploration/Behaviour_UI.py b/Exploration/Behavior_UI.py similarity index 100% rename from Exploration/Behaviour_UI.py rename to Exploration/Behavior_UI.py diff --git a/Exploration/HelperFunctions/Synapses_And_Weights.py b/Exploration/HelperFunctions/Synapses_And_Weights.py index b116938..1575477 100644 --- a/Exploration/HelperFunctions/Synapses_And_Weights.py +++ b/Exploration/HelperFunctions/Synapses_And_Weights.py @@ -118,7 +118,8 @@ def get_combined_syn_mats(synapses, neuron_id=None, attr='W'): shapes[key] = (base_src.height, base_src.width) try: syn_mat = eval('s.' + attr) - if type(syn_mat) is not bool: + + if type(syn_mat)!=bool: w = s.ignore_transpose_mode(syn_mat) else: w = syn_mat diff --git a/Exploration/Network_UI/Basic_Tabs/sidebar_fast_forward_module.py b/Exploration/Network_UI/Basic_Tabs/sidebar_fast_forward_module.py index 84a6faa..c5ae8b5 100644 --- a/Exploration/Network_UI/Basic_Tabs/sidebar_fast_forward_module.py +++ b/Exploration/Network_UI/Basic_Tabs/sidebar_fast_forward_module.py @@ -32,7 +32,11 @@ def fast_forward(self, steps, Network_UI): def initialize(self, Network_UI): self.iteration_display_label=Network_UI.sidebar.add_widget(QLabel()) - self.iteration_display_label.setMaximumHeight(10) + #self.iteration_display_label.setMaximumHeight(20) + + font_metrics = QFontMetrics(self.iteration_display_label.font()) + text_height = font_metrics.height() + self.iteration_display_label.setFixedHeight(text_height) def start_pause_click(event): Network_UI.pause = not Network_UI.pause diff --git a/Exploration/Network_UI/Sequence_Activation_Tabs/reconstruction_tab.py b/Exploration/Network_UI/Sequence_Activation_Tabs/reconstruction_tab.py index 0beea6a..281c23a 100644 --- a/Exploration/Network_UI/Sequence_Activation_Tabs/reconstruction_tab.py +++ b/Exploration/Network_UI/Sequence_Activation_Tabs/reconstruction_tab.py @@ -11,7 +11,7 @@ def add_recorder_variables(self, neuron_group, Network_UI): return def initialize(self, Network_UI): - if Network_UI.network['TextActivator', 0] and Network_UI.network['TextGenerator', 0] is not None: + if Network_UI.network['TextActivator', 0] is not None and Network_UI.network['TextGenerator', 0] is not None: self.reconstruction_tab = Network_UI.add_tab(title=self.title) #Network_UI.Next_Tab(self.title) self.grid = QGridLayout() @@ -70,7 +70,7 @@ def initialize(self, Network_UI): def update(self, Network_UI): - if Network_UI.network['TextActivator', 0] is not None and self.reconstruction_tab.isVisible(): + if Network_UI.network['TextActivator', 0] is not None and Network_UI.network['TextGenerator', 0] is not None and self.reconstruction_tab.isVisible(): group=Network_UI.selected_neuron_group() ''' diff --git a/Exploration/Network_UI/Sequence_Activation_Tabs/sidebar_grammar_module.py b/Exploration/Network_UI/Sequence_Activation_Tabs/sidebar_grammar_module.py index f1b6616..cea64a0 100644 --- a/Exploration/Network_UI/Sequence_Activation_Tabs/sidebar_grammar_module.py +++ b/Exploration/Network_UI/Sequence_Activation_Tabs/sidebar_grammar_module.py @@ -66,14 +66,16 @@ def initialize(self, Network_UI): def update(self, Network_UI): if Network_UI.network['TextGenerator', 0] is not None and Network_UI.network['TextActivator', 0] is not None: - if Network_UI.network['TextActivator', 0].behavior_enabled: - inp_text = Network_UI.network['TextGenerator', 0].history[-self.text_length:] + if Network_UI.network['TextGenerator', 0].behavior_enabled and Network_UI.network['TextActivator', 0].behavior_enabled: + inp_text = Network_UI.network['TextGenerator', 0].get_str_history()[-self.text_length:] else: inp_text = 'deactivated' + inp_text=inp_text.replace('\n', '') self.inp_text_label.setText(inp_text) if Network_UI.network['TextReconstructor', 0] is not None: recon_text = Network_UI.network['TextReconstructor', 0].reconstruction_history[-self.text_length:] + recon_text=recon_text.replace('\n', '') self.recon_text_label.setText(recon_text) ''' diff --git a/Exploration/Network_UI/Sequence_Activation_Tabs/sun_gravity_plot_tab.py b/Exploration/Network_UI/Sequence_Activation_Tabs/sun_gravity_plot_tab.py index 6b05bde..2b71513 100644 --- a/Exploration/Network_UI/Sequence_Activation_Tabs/sun_gravity_plot_tab.py +++ b/Exploration/Network_UI/Sequence_Activation_Tabs/sun_gravity_plot_tab.py @@ -156,10 +156,10 @@ def draw_neurons(self, painter, group, neuron_size=1, selected_neurons=None): painter.setPen(0) - inactive = group.output <= 0 + inactive = group.spike <= 0 active = np.invert(inactive) - for c in unique(color, axis=0): + for c in np.unique(color, axis=0): mask = np.all(color == c[None,:], axis=1) * inactive #(color == c) np.all(a == b, axis=1) painter.setBrush(pg.mkBrush(color=c)) for x, y in zip(group.buffer_posx[mask], group.buffer_posy[mask]): diff --git a/NetworkBehavior/Structure/Partition.py b/NetworkBehavior/Structure/Partition.py index 8bc4f56..00f2d81 100644 --- a/NetworkBehavior/Structure/Partition.py +++ b/NetworkBehavior/Structure/Partition.py @@ -32,7 +32,7 @@ def partition(self, synapses, dst_group_masks): # todo:auto receptive field ext syn_sub_groups.append(synapses.get_sub_synapse_group(src_mask, dst_mask)) - print('partitioned into', len(syn_sub_groups), 'SynapseGroups') + print('partitioned into', len(syn_sub_groups), 'SynapseGroups', str(int(rf_x)), 'x', str(int(rf_y)), 'x', str(int(rf_z))) # add sub Groups for sg in syn_sub_groups: diff --git a/NetworkCore/Base_Attachable_Modules.py b/NetworkCore/Base_Attachable_Modules.py index b6a8d3a..8ef240b 100644 --- a/NetworkCore/Base_Attachable_Modules.py +++ b/NetworkCore/Base_Attachable_Modules.py @@ -3,6 +3,9 @@ from numpy.random import * from numpy import * from functools import wraps +import builtins + +bool = builtins.bool def lognormal_real_mean(mean=1.0, sigma=1.0, size=1): mu = -np.power(sigma, 2) + np.log(mean) @@ -40,7 +43,7 @@ def __init__(self, tag, network, behavior): self.behavior = {}#behavior if type(behavior) == list: - self.behavior = dict(zip(range(len(self.behavior)), self.behavior)) + behavior = dict(zip(range(len(behavior)), behavior)) for k,b in behavior.items(): self.add_behavior(k, b, initialize=False) @@ -266,4 +269,6 @@ def deactivate_behaviours(self, tag): @deprecated_warning("activate_behaviours function will be removed in coming versions. Please use activate_behaviors instead.") def activate_behaviours(self,tag): - return self.activate_behaviors(tag) \ No newline at end of file + return self.activate_behaviors(tag) + +__all__ = ['lognormal_real_mean', 'lognormal_rm', 'uniform_gap', 'is_number', 'deprecated_warning', 'NetworkObjectBase'] # numpy functions are only accessible inside this file diff --git a/NetworkCore/Neuron_Group.py b/NetworkCore/Neuron_Group.py index 31d207c..92eb5b1 100644 --- a/NetworkCore/Neuron_Group.py +++ b/NetworkCore/Neuron_Group.py @@ -32,28 +32,24 @@ def __init__(self, net, size, behavior, tag=None, color=None): size = -1#will be overwritten by size-behavior self.size = size + self.BaseNeuronGroup = self#used for subgroup reconstruction + self.afferent_synapses = {} #set by SynapseGroup + self.efferent_synapses = {} + self.mask = True#np.array([True for _ in range(size)]).astype(bool)#True#used for subgroup reconstruction + self.id = np.arange(self.size) + + if color is not None: + self.color = color super().__init__(tag, net, behavior) self.add_tag('ng') - self.BaseNeuronGroup = self#used for subgroup reconstruction - if net is not None: net.NeuronGroups.append(self) for tag in self.tags: if not hasattr(net, tag): setattr(net, tag, self) - self.afferent_synapses = {} #set by SynapseGroup - self.efferent_synapses = {} - - self.mask = True#np.array([True for _ in range(size)]).astype(bool)#True#used for subgroup reconstruction - - self.id = np.arange(self.size) - - if color is not None: - self.color = color - def synapses(self, mode, tag='All'):#afferent=0, efferent=1 if mode==afferent: return self.afferent_synapses[tag] diff --git a/NetworkCore/Synapse_Group.py b/NetworkCore/Synapse_Group.py index bc6861c..64fe13b 100644 --- a/NetworkCore/Synapse_Group.py +++ b/NetworkCore/Synapse_Group.py @@ -194,3 +194,5 @@ def ignore_transpose_mode(self, W):# always returns DxS matrix else: return W + + diff --git a/test_pymoNNto.py b/test_pymoNNto.py index 25dc420..b5a0097 100644 --- a/test_pymoNNto.py +++ b/test_pymoNNto.py @@ -48,6 +48,17 @@ def get_sample_network(): return My_Network, My_Neurons, My_Synapses, sm +def get_sample_network_list(): + My_Network = Network() + My_Neurons = NeuronGroup(net=My_Network, tag='my_neurons', size=100, behavior=[ + Counter(inc='[2#I]'), + Recorder('count') + ]) + My_Synapses = SynapseGroup(net=My_Network, src=My_Neurons, dst=My_Neurons, tag='GLUTAMATE') + sm = StorageManager('test', random_nr=False, print_msg=False) + My_Network.initialize(storage_manager=sm) + + return My_Network, My_Neurons, My_Synapses, sm def test_basics(): net = Network() @@ -113,40 +124,40 @@ def test_behavior_and_tagging(): # basic network set_genome({'I': 1}) - My_Network, My_Neurons, My_Synapses, sm = get_sample_network() + for My_Network, My_Neurons, My_Synapses, sm in [get_sample_network(), get_sample_network_list()]: - My_Network.simulate_iterations(1000) + My_Network.simulate_iterations(1000) - My_Network.deactivate_behaviors('Counter') - My_Network.simulate_iterations(10) + My_Network.deactivate_behaviors('Counter') + My_Network.simulate_iterations(10) - My_Network.activate_behaviors('Counter') - My_Network.simulate_iterations(20) + My_Network.activate_behaviors('Counter') + My_Network.simulate_iterations(20) - My_Network.recording_off() - My_Network.simulate_iterations(30) + My_Network.recording_off() + My_Network.simulate_iterations(30) - assert My_Network.iteration == 1000+10+20+30 - assert np.mean(My_Neurons.count) == 1000+20+30 + assert My_Network.iteration == 1000+10+20+30 + assert np.mean(My_Neurons.count) == 1000+20+30 - assert My_Synapses.src == My_Neurons - assert My_Synapses.dst == My_Neurons + assert My_Synapses.src == My_Neurons + assert My_Synapses.dst == My_Neurons - assert My_Neurons.synapses(afferent, 'GLUTAMATE') == [My_Synapses] + assert My_Neurons.synapses(afferent, 'GLUTAMATE') == [My_Synapses] - assert len(My_Network.all_objects()) == 3 + assert len(My_Network.all_objects()) == 3 - #tagging system - assert My_Network['my_neurons'] == [My_Neurons] - assert len(My_Network['count', 0]) == My_Network.iteration-30 + #tagging system + assert My_Network['my_neurons'] == [My_Neurons] + assert len(My_Network['count', 0]) == My_Network.iteration-30 - My_Network.clear_recorder() - assert len(My_Neurons['count', 0]) == 0 + My_Network.clear_recorder() + assert len(My_Neurons['count', 0]) == 0 - assert My_Network.tag_shortcuts['my_neurons'] == My_Network['my_neurons'] + assert My_Network.tag_shortcuts['my_neurons'] == My_Network['my_neurons'] - if os.path.isdir(folder+'test/'): - shutil.rmtree(folder+'test/') + if os.path.isdir(folder+'test/'): + shutil.rmtree(folder+'test/')