from NetworkBehaviour.Input.TREN.Lines import * from NetworkCore.Network import * from NetworkCore.Synapse_Group import * from NetworkBehaviour.Structure.Structure import * from Exploration.StorageManager.StorageManager import * so = True n_Neurons = 900 #source = FDTGrammarActivator_New(tag='grammar_act', random_blocks=True, input_density=0.015)#.plot_char_input_statistics()#output_size=par['N_e']#15 source = LongDelayGrammar(tag='grammar_act', random_blocks=True, mode=['simple'], input_density=0.015) #source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(30)), center_y=30 / 2, degree=90, line_length=60) #source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(30)), center_y=30 / 2, degree=90, line_length=60) SORN = Network() PC = NeuronGroup(net=SORN, tag='Pyramidal,prediction_source', size=get_squared_dim(int(n_Neurons)), behaviour={ 2: SORN_init_neuron_vars(nit_TH='0.1;+-100%'), 3: SORN_init_afferent_synapses(transmitter='GLU', density='50%', distribution='uniform(0.1,0.11)', normalize=True, partition_compensation=True), #lognormal(0,0.6) 4: SORN_init_afferent_synapses(transmitter='GABA_Dendrite', density='30%', distribution='uniform(0.1,0.11)', normalize=True), 5: SORN_init_afferent_synapses(transmitter='GABA_Soma', density='30%', distribution='uniform(0.1,0.11)', normalize=True), 6: SORN_init_afferent_synapses(transmitter='GABA_AIS', density='30%', distribution='uniform(0.1,0.11)', normalize=True), 12: SORN_slow_syn(transmitter='GLU', strength='0.1383', so=so), 13: SORN_slow_syn(transmitter='GABA_Dendrite', strength='-0.1', so=False), 14: SORN_slow_input_collect(), 17: SORN_fast_syn(transmitter='GABA_Soma', strength='-0.1', so=False), 17.1: SORN_fast_syn(transmitter='GABA_AIS', strength='-0.1', so=False), 19: SORN_input_collect(),
def run(tag='PV_SOM', ind=[], par={'N_e': 900, 'TS': [1]}): print(tag, par) sm = StorageManager(tag, random_nr=True, print_msg=display) sm.save_param_dict(par) #source = FDTGrammarActivator_New(tag='grammar_act', random_blocks=True, input_density=15/par['N_e'])#.plot_char_input_statistics()#output_size=par['N_e']#15 #print(len(source.alphabet)) source = LongDelayGrammar( tag='grammar_act', output_size=par['N_e'], random_blocks=True, mode=['simple'], input_density=0.015 ) #.print_test().plot_char_input_statistics()#10/par['N_e'] #source.plot_char_input_statistics() #print(len(source.alphabet)) #source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(30)), center_y=30 / 2, degree=90, line_length=60) #source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(30)), center_y=30 / 2, degree=90, line_length=60) #print(source.get_text_score('. parrot likes trees. wolf wolf wolf..')) SORN = Network() #[], [], initialize=False last_PC = None for timecale in par['TS']: PC = NeuronGroup( net=SORN, tag='Pyramidal Cell {},prediction_source'.format(timecale), size=get_squared_dim(int(par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-100%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='[50#0]%', distribution='uniform(0.1,0.11)', normalize=True, partition_compensation=True), #lognormal(0,0.6) 4: SORN_init_afferent_synapses(transmitter='GABA_Dendrite', density='[30#1]%', distribution='uniform(0.1,0.11)', normalize=True), 5: SORN_init_afferent_synapses(transmitter='GABA_Soma', density='[30#2]%', distribution='uniform(0.1,0.11)', normalize=True), 6: SORN_init_afferent_synapses(transmitter='GABA_AIS', density='[30#3]%', distribution='uniform(0.1,0.11)', normalize=True), 7: SORN_init_afferent_synapses(transmitter='GABA_NOX', density='full', distribution=None, normalize=True), 12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#4]', so=so), 13: SORN_slow_syn(transmitter='GABA_Dendrite', strength='-0.1', so=False), 14: SORN_slow_input_collect(), 17: SORN_fast_syn(transmitter='GABA_Soma', strength='-0.1', so=False), 17.1: SORN_fast_syn(transmitter='GABA_AIS', strength='-0.1', so=False), #17.2: SORN_fast_syn(transmitter='GABA_NOX', strength='-0.1', so=False), 19: SORN_input_collect(), 20: SORN_Refractory(factor='[0.5#5];+-50%'), 21: SORN_STDP_new(eta_stdp='[0.0015#6]', prune_stdp=False, excitation_punishment=0.0), #0.1#todo: test!!! 22: SORN_SN(syn_type='GLU', clip_max=None, init_norm_factor=1.0), 23: SORN_IP_TI(mp='n.output_new/2.0+n.output_new_temp/2.0', h_ip='lognormal_real_mean([0.04#7], [0.2944#8])', eta_ip='[0.0006#9];+-50%', integration_length='[15#10];+-50%', clip_min=None), #25: SORN_NOX(mp='self.partition_sum(n)', eta_nox='0.5;+-50%', h_dh=0.0),#0.9#0.3 26: SORN_SC_TI(h_sc='lognormal_real_mean([0.015#11], [0.2944#12])', eta_sc='[0.1#13];+-50%', integration_length='1'), #27: SORN_iSTDP(h_ip='same(SCTI, th)', eta_istdp='[0.0001#13]'), 30: SORN_finish() }) MT_SOM = NeuronGroup( net=SORN, tag='Martinotti Cell {},Somatostatin'.format(timecale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='0.6', so=so), # 1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) EXP_NOX_CELL = NeuronGroup( net=SORN, tag='NOX Cell {}'.format(timecale), size=get_squared_dim(int(16)), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.04', activation_function='identity'), 3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution=None, normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='9.0', so=so), #1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) BA_PV = NeuronGroup( net=SORN, tag='Basket Cell {},Parvalbumin'.format(timecale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='0.6', so=so), # 1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) CH_PV = NeuronGroup( net=SORN, tag='Chandelier Cell {},Parvalbumin'.format(timecale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), 14: SORN_fast_syn(transmitter='GLU', strength='0.4', so=so), #1.5353 #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #19: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) MT_SOM['structure', 0].stretch_to_equal_size(PC) BA_PV['structure', 0].stretch_to_equal_size(PC) CH_PV['structure', 0].stretch_to_equal_size(PC) EXP_NOX_CELL['structure', 0].stretch_to_equal_size(PC) #plt.scatter(PC.x, PC.y) #plt.scatter(MT_SOM.x, MT_SOM.y) #plt.scatter(BA_PV.x, BA_PV.y) #plt.scatter(CH_PV.x, CH_PV.y) #plt.scatter(EXP_NOX_CELL.x, EXP_NOX_CELL.y) #plt.show() #print(np.min(EXP_NOX_CELL.x), np.max(EXP_NOX_CELL.x)) #print(np.min(EXP_NOX_CELL.y), np.max(EXP_NOX_CELL.y)) #print(np.min(PC.x), np.max(PC.x)) #print(np.min(PC.y), np.max(PC.y)) SynapseGroup(net=SORN, src=PC, dst=PC, tag='GLU', connectivity='(s_id!=d_id)*in_box(10)', partition=True) SynapseGroup(net=SORN, src=PC, dst=MT_SOM, tag='GLU', connectivity='in_box(2)', partition=True) SynapseGroup(net=SORN, src=PC, dst=BA_PV, tag='GLU', connectivity='in_box(2)', partition=True) SynapseGroup(net=SORN, src=PC, dst=CH_PV, tag='GLU', connectivity='in_box(2)', partition=True) SynapseGroup(net=SORN, src=PC, dst=EXP_NOX_CELL, tag='GLU', connectivity='in_box(3.75)', partition=True) SynapseGroup(net=SORN, src=MT_SOM, dst=PC, tag='GABA_Dendrite', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=BA_PV, dst=PC, tag='GABA_Soma', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=CH_PV, dst=PC, tag='GABA_AIS', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=EXP_NOX_CELL, dst=PC, tag='GABA_NOX', connectivity='in_box(3.75)', partition=True) #SynapseGroup(net=SORN, src=SOM, dst=SOM, tag='GABA_D,SOM->SOM', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) #SynapseGroup(net=SORN, src=SOM, dst=PV, tag='GABA_D,SOM->PV', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) ##SynapseGroup(net=SORN, src=PV, dst=SOM, tag='GABA_P,PV->SOM')#not realistic? #SynapseGroup(net=SORN, src=PV, dst=PV, tag='GABA_P,PV->PV', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) if last_PC is None: PC.add_behaviour( 9, SORN_external_input(strength=1.0, pattern_groups=[source])) #MT_SOM.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #BA_PV.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #CH_PV.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #else: # #forward synapses # SynapseGroup(net=SORN, src=last_PC, dst=PC, tag='GLU,PC->PC(+1)', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([10, 10], [partition, partition]) # SynapseGroup(net=SORN, src=last_PC, dst=SOM, tag='GABA,PC->SOM(+1)', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([5, 5], [2, 2]) # #backward synapses # SynapseGroup(net=SORN, src=PC, dst=last_PC, tag='GLU,PC(+1)->PC', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([10, 10], [partition, partition]) # SynapseGroup(net=SORN, src=PC, dst=last_SOM, tag='GABA,PC(+1)->SOM', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([5, 5], [2, 2]) last_PC = PC #last_MT_SOM = MT_SOM #last_BA_PV = BA_PV #last_CH_PV = CH_PV #last_EXP_NOX_CELL = EXP_NOX_CELL PC.color = get_color(0, timecale) MT_SOM.color = get_color(1, timecale) BA_PV.color = get_color(2, timecale) CH_PV.color = get_color(3, timecale) EXP_NOX_CELL.color = get_color(4, timecale) #EXP_NOX_CELL.display_min_max_act = (0, 0.3) SORN.set_marked_variables(ind, info=(ind == []), storage_manager=sm) SORN.initialize(info=False) ################################################################################################################### score = 0 Network_UI(SORN, label='SORN UI PC PV SOM', storage_manager=sm, group_display_count=4).show( ) #'GLU', 'GABA_Dendrite', 'GABA_Soma', 'GABA_AIS' score += train_and_generate_text( SORN, 30000, 5000, 2000, display=True, stdp_off=True, same_timestep_without_feedback_loop=False, steps_recovery=0, storage_manager=sm) #, steps_recovery=15000 #score += get_oscillation_score_hierarchical(SORN, 0, 5000) return score
from NetworkBehaviour.Structure.Structure import * from NetworkBehaviour.Logic.Example_Simple_Network.Simple_Network_behaviour import * import Exploration.UI.Network_UI.Network_UI as NUI from Exploration.UI.Network_UI.Tabs.activity_tab import * from Exploration.UI.Network_UI.Tabs.sidebar_activity_module import * from Exploration.UI.Network_UI.Tabs.spiketrain_tab import * from Exploration.UI.Network_UI.Tabs.fourier_tab import * from Exploration.UI.Network_UI.Tabs.weight_tab import * from Exploration.UI.Network_UI.Tabs.sidebar_fast_forward_module import * from Exploration.UI.Network_UI.Tabs.sidebar_save_load_module import * from Exploration.UI.Network_UI.Tabs.stability_tab import * from Exploration.UI.Network_UI.Tabs.hist_tab import * number_of_neurons = 900 Easy_Network = Network() Easy_Neurons = NeuronGroup(net=Easy_Network, tag='neurons', size=get_squared_dim(number_of_neurons), behaviour={ 1: Easy_neuron_initialize(syn_density=0.05), 2: Easy_neuron_collect_input(noise_density=0.1, noise_strength=0.11), 3: Easy_neuron_generate_output(threshold=0.1), 4: Easy_neuron_Refractory(decay='0.8;0.99') })
def run(tag='hierarchical', ind=[], par={'N_e': 900, 'TS': [1]}): #print(tag, par) sm = StorageManager(tag, random_nr=True, print_msg=display) sm.save_param_dict(par) #source = FDTGrammarActivator_New(tag='grammar_act', random_blocks=True, input_density=15/par['N_e'])#.plot_char_input_statistics()#output_size=par['N_e']#15 #print(len(source.alphabet)) source = LongDelayGrammar( tag='grammar_act', output_size=par['N_e'], random_blocks=True, mode=['simple'], input_density=0.015 ) #.print_test()#.plot_char_input_statistics()#10/par['N_e'] #source.plot_char_input_statistics() #print(len(source.alphabet)) #source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(30)), center_y=30 / 2, degree=90, line_length=60) #print(source.get_text_score('. parrot likes trees. wolf wolf wolf..')) SORN = Network() last_e_ng = None for timecale in par['TS']: e_ng = NeuronGroup( net=SORN, tag='PC_{},prediction_source'.format(timecale), size=get_squared_dim(int(par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-100%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='13%', distribution='lognormal(0,[0.95#0])', normalize=True, partition_compensation=True), #0.89 uniform(0.1,0.11) 4: SORN_init_afferent_synapses( transmitter='GABA', density='45%', distribution='lognormal(0,[0.4#1])', normalize=True), #0.80222 uniform(0.1,0.11) 12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so), 13: SORN_slow_syn(transmitter='GABA', strength='-[0.1698#3]', so=False), 17: SORN_fast_syn(transmitter='GABA', strength='-[0.1#4]', so=False), #0.11045 18: SORN_input_collect(), 19: SORN_Refractory(factor='0.5;+-50%'), 21: SORN_STDP(eta_stdp='[0.00015#5]', prune_stdp=False), 22: SORN_SN(syn_type='GLU', clip_max=None, init_norm_factor=1.0), 23: SORN_IP_TI( h_ip='lognormal_real_mean([0.04#6], [0.2944#7])', eta_ip='[0.0006#8];+-50%', integration_length='[15#18];+-50%', clip_min=None ), #30 #, gap_percent=10 #30;+-50% #0.0003 #np.mean(n.output_new) 25: SORN_NOX(mp='self.partition_sum(n)', eta_nox='[0.5#9];+-50%'), 26: SORN_SC_TI(h_sc='lognormal_real_mean([0.015#10], [0.2944#11])', eta_sc='[0.1#12];+-50%', integration_length='1'), #60;+-50% #0.05 27: SORN_iSTDP(h_ip='same(SCTI, th)', eta_istdp='[0.0001#13]'), 30: SORN_finish(), }) i_ng = NeuronGroup( net=SORN, tag='Inter_{}'.format(timecale), size=get_squared_dim(int(0.2 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timecale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,[0.87038#14])', normalize=True), # 450 4: SORN_init_afferent_synapses( transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), 14: SORN_fast_syn(transmitter='GLU', strength='[1.5#16]', so=so), #1.5353 15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False), #0.08 18: SORN_input_collect(), 19: SORN_Refractory(factor='0.2;0.7'), #23: SORN_IP_TI(h_ip='lognormal_real_mean([0.08#6], [0.2944#7])', eta_ip='[0.0003#8];+-50%', integration_length='30;+-50%', clip_min=None), 30: SORN_finish() }) i_ng['structure', 0].stretch_to_equal_size(e_ng) SynapseGroup( net=SORN, src=e_ng, dst=e_ng, tag='GLU', connectivity='(s_id!=d_id)*in_box(10)', partition=True) #.partition([10, 10], [partition, partition]) SynapseGroup(net=SORN, src=e_ng, dst=i_ng, tag='GLU', connectivity='in_box(10)', partition=True) #.partition([5, 5], [2, 2]) SynapseGroup(net=SORN, src=i_ng, dst=e_ng, tag='GABA', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=i_ng, dst=i_ng, tag='GABA', connectivity='(s_id!=d_id)*in_box(10)', partition=True) #i_ng.add_behaviour(10, SORN_external_input(strength=1.0, pattern_groups=[source])) e_ng.add_behaviour( 9, SORN_external_input(strength=1.0, pattern_groups=[source])) if last_e_ng is not None: #forward synapses SynapseGroup( net=SORN, src=last_e_ng, dst=e_ng, tag='GLU', connectivity='in_box(10)', partition=True) #.partition([10, 10], [partition, partition]) SynapseGroup(net=SORN, src=last_e_ng, dst=i_ng, tag='GABA', connectivity='in_box(10)', partition=True) #.partition([5, 5], [2, 2]) #backward synapses SynapseGroup( net=SORN, src=e_ng, dst=last_e_ng, tag='GLU', connectivity='in_box(10)', partition=True) #.partition([10, 10], [partition, partition]) SynapseGroup(net=SORN, src=e_ng, dst=last_i_ng, tag='GABA', connectivity='in_box(10)', partition=True) #.partition([5, 5], [2, 2]) last_e_ng = e_ng last_i_ng = i_ng e_ng.color = get_color(0, timecale) i_ng.color = get_color(1, timecale) SORN.set_marked_variables(ind, info=(ind == []), storage_manager=sm) SORN.initialize(info=False) ################################################################################################################### score = 0 #Network_UI(SORN, label='SORN UI default setup', storage_manager=sm, group_display_count=2, reduced_layout=True).show() score += train_and_generate_text( SORN, 15000, 5000, 2000, display=True, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=2000, storage_manager=sm) #, steps_recovery=15000 #score += get_oscillation_score_hierarchical(SORN, 0, 5000) return score
def run(tag, ind=[], par={'N_e': [1800], 'TS': [1]}): name = 'DrumBeats_' + '_' + tag + str(par['N_e']) + 'N_e_' + str(par['TS']) sm = StorageManager(main_folder_name=tag, folder_name=name, random_nr=False, print_msg=display) sm.save_param_dict(par) source = DrumBeatActivator( tag='drum_act', which_tracks=[100], filter_silence=False, THR_similar_tracks=0.5, input_density=0.015, offtoken=True, ontoken=True, include_inverse_alphabet=False ) #, include_inverse_alphabet= True)#output_size=par['N_e'] inh_thr = ['0.1;+-0%', '0.1;+-0%', '0.1;+-0%'] exc_thr = ['0.1;+-100%', '0.1;+-100%', '0.1;+-100%'] SORN = Network() for i, lag in enumerate(par['TS']): # e_ng = NeuronGroup( net=SORN, tag='exc_cell_{},prediction_source,text_input_group'.format(lag), size=get_squared_dim(int(par['N_e'][i])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=lag, init_TH=exc_thr[i]), 3: SORN_init_afferent_synapses( transmitter='GLU', density='13%', distribution='lognormal(0,[0.89#0])', normalize=True, partition_compensation=True), 4: SORN_init_afferent_synapses( transmitter='GABA', density='50%', distribution='lognormal(0,[0.80222#1])', normalize=True), 12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so), 13: SORN_slow_syn(transmitter='GABA', strength='-[0.1698#3]', so=so), 17: SORN_fast_syn(transmitter='GABA', strength='-[0.11045#4]', so=so), 18: SORN_input_collect(), 19: SORN_Refractory(factor='0.5;+-50%'), 21: SORN_STDP(eta_stdp='[0.0001#5]', prune_stdp=False), 22: SORN_SN(syn_type='GLU', clip_max=None, init_norm_factor=1.0), 23: SORN_IP_TI(h_ip='lognormal_real_mean([0.04#6], [0.2944#7])', eta_ip='[0.0006#8];+-50%', integration_length='[30#18];+-50%', clip_min=None), #, gap_percent=10 #30;+-50% #0.0003 #24: SORN_NOX(mp='np.mean(n.output_new)', eta_nox='[0.3#9];+-50%', behaviour_enabled=False), #0.4 25: SORN_NOX(mp='self.partition_sum(n)', eta_nox='[0.3#9];+-50%'), # 0.4 26: SORN_SC_TI(h_sc='lognormal_real_mean([0.01#10], [0.2944#11])', eta_sc='[0.1#12];+-50%', integration_length='1'), #60;+-50% #0.05 27: SORN_iSTDP(h_ip='same(SCTI, th)', eta_istdp='[0.0001#13]'), 30: SORN_finish(), #99: SynapseRecorder(['[np.sum(s.slow_add)]'], tag='ex_glu_syn_rec'), #100: NeuronRecorder(['n.output'], tag='exc_out_rec') }) i_ng = NeuronGroup( net=SORN, tag='inh_cell_{}'.format(lag), size=get_squared_dim(int(0.2 * (par['N_e'][i]))), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=lag, init_TH=inh_thr[i]), 3: SORN_init_afferent_synapses( transmitter='GLU', density='45%', distribution='lognormal(0,[0.87038#14])', normalize=True), # 450 4: SORN_init_afferent_synapses( transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), 14: SORN_fast_syn(transmitter='GLU', strength='[1.5#16]', so=so), #1.5353 15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=so), #0.08 18: SORN_input_collect(), 19: SORN_Refractory(factor='0.1;0.4'), #23: SORN_IP_TI(h_ip='lognormal_real_mean([0.08#6], [0.2944#7])', eta_ip='[0.0003#8];+-50%', integration_length='30;+-50%', clip_min=None), 30: SORN_finish(), #100: NeuronRecorder(['n.output'], tag='inh_out_rec') }) i_ng['structure', 0].stretch_to_equal_size(e_ng) SynapseGroup(net=SORN, src=e_ng, dst=e_ng, tag='GLU,ee', connectivity='(s_id!=d_id)*in_box(10)', partition=True) #.partition([10, 10], [4, 4]) SynapseGroup(net=SORN, src=e_ng, dst=i_ng, tag='GLU,ie', connectivity='(s_id!=d_id)*in_box(10)', partition=True) #.partition([5, 5], [2, 2]) SynapseGroup(net=SORN, src=i_ng, dst=e_ng, tag='GABA,ei', connectivity='(s_id!=d_id)*in_box(10)', partition=True) SynapseGroup(net=SORN, src=i_ng, dst=i_ng, tag='GABA,ii', connectivity='(s_id!=d_id)*in_box(10)', partition=True) if lag == 1: i_ng.add_behaviour( 10, SORN_external_input(strength=1.0, pattern_groups=[source])) e_ng.add_behaviour( 10, SORN_external_input(strength=1.0, pattern_groups=[source])) #e_ng.add_behaviour(101, NeuronRecorder(['n.pattern_index'], tag='inp_rec')) else: #forward synapses SynapseGroup(net=SORN, src=last_e_ng, dst=e_ng, tag='GLU,eeff') #.partition([10, 10], [4, 4]) SynapseGroup(net=SORN, src=last_e_ng, dst=i_ng, tag='GABA,ieff') #.partition([5, 5], [2, 2]) #backward synapses SynapseGroup(net=SORN, src=e_ng, dst=last_e_ng, tag='GLU,eebw') #.partition([10, 10], [4, 4]) SynapseGroup(net=SORN, src=e_ng, dst=last_i_ng, tag='GABA,iebw') #.partition([5, 5], [2, 2]) last_e_ng = e_ng # excitatory neuron group last_i_ng = i_ng # inhibitory neuron group e_ng.color = (0, 0, 255, 255) i_ng.color = (255, 0, 255, 255) e_ng.pattern_index = 0 i_ng.pattern_index = 0 SORN.set_marked_variables(ind, info=(ind == [])) SORN.initialize(info=False) ############################################################################################################################################################ score_spont = score_predict_train = score_predict_test = 0 #import Exploration.UI.Network_UI.Network_UI as SUI #SUI.Network_UI(SORN, label='SORN UI default setup', storage_manager=sm, group_display_count=2, reduced_layout=False).show() SORN = run_plastic_phase(SORN, steps_plastic=1000000, display=True, storage_manager=sm) readout, X_train, Y_train, X_test, Y_test = train_readout( SORN, steps_train=100000, steps_test=100, source=SORN['drum_act', 0], display=True, stdp_off=True, storage_manager=sm) score_predict_train = get_score_predict_next_step(SORN, SORN['drum_act', 0], readout, X_train, Y_train, display=True, stdp_off=True, storage_manager=sm) score_predict_test = get_score_predict_next_step(SORN, SORN['drum_act', 0], readout, X_test, Y_test, display=True, stdp_off=True, storage_manager=sm) score_spont = get_score_spontaneous_music( SORN, SORN['drum_act', 0], readout, split_tracks=False, steps_spont=2000, display=True, stdp_off=True, same_timestep_without_feedback_loop=False, steps_recovery=0, create_MIDI=True, storage_manager=sm) #, steps_recovery=15000 sm.save_obj('score_train', score_predict_train) sm.save_obj('score_test', score_predict_test) sm.save_obj('score_spontaneous', score_spont) #plot_frequencies_poly(score_spont, path = sm.absolute_path+'frequencies', title='{} Ne, {} lag'.format(par['N_e'], par['TS'])) return score_predict_train, score_predict_test, score_spont
def run(tag, ind=[], par={'N_e': 1800, 'TS': [1]}): name = 'DrumBeats_' + '_' + tag + str(par['N_e']) + 'N_e_' + str(par['TS']) sm = StorageManager(main_folder_name=tag, folder_name=name, random_nr=False, print_msg=display) sm.save_param_dict(par) source = DrumBeatActivator( tag='drum_act', which_tracks=[100], filter_silence=False, THR_similar_tracks=0.5, input_density=0.015, offtoken=True, ontoken=True, include_inverse_alphabet=False ) #, include_inverse_alphabet= True)#output_size=par['N_e'] SORN = Network() last_PC = None for i, timescale in enumerate(par['TS']): # PC = NeuronGroup( net=SORN, tag='Pyramidal Cell {},prediction_source'.format(timescale), size=get_squared_dim(int(par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timescale, init_TH='0.1;+-100%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='[50#0]%', distribution='uniform(0.1,0.11)', normalize=True, partition_compensation=True), #lognormal(0,0.6) 4: SORN_init_afferent_synapses(transmitter='GABA_Dendrite', density='[30#1]%', distribution='uniform(0.1,0.11)', normalize=True), 5: SORN_init_afferent_synapses(transmitter='GABA_Soma', density='[30#2]%', distribution='uniform(0.1,0.11)', normalize=True), 6: SORN_init_afferent_synapses(transmitter='GABA_AIS', density='[30#3]%', distribution='uniform(0.1,0.11)', normalize=True), 7: SORN_init_afferent_synapses(transmitter='GABA_NOX', density='full', distribution=None, normalize=True), 12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#4]', so=so), 13: SORN_slow_syn(transmitter='GABA_Dendrite', strength='-0.1', so=False), 14: SORN_slow_input_collect(), 17: SORN_fast_syn(transmitter='GABA_Soma', strength='-0.1', so=False), 17.1: SORN_fast_syn(transmitter='GABA_AIS', strength='-0.1', so=False), #17.2: SORN_fast_syn(transmitter='GABA_NOX', strength='-0.1', so=False), 19: SORN_input_collect(), 20: SORN_Refractory(factor='[0.5#5];+-50%'), 21: SORN_STDP_new(eta_stdp='[0.0015#6]', prune_stdp=False, excitation_punishment=0.0), #0.1#todo: test!!! 22: SORN_SN(syn_type='GLU', clip_max=None, init_norm_factor=1.0), 23: SORN_IP_TI(mp='n.output_new/2.0+n.output_new_temp/2.0', h_ip='lognormal_real_mean([0.04#7], [0.2944#8])', eta_ip='[0.0006#9];+-50%', integration_length='[15#10];+-50%', clip_min=None), 25: SORN_NOX(mp='self.partition_sum(n)', eta_nox='0.5;+-50%', h_dh=0.0), #0.9#0.3 26: SORN_SC_TI(h_sc='lognormal_real_mean([0.015#11], [0.2944#12])', eta_sc='[0.1#13];+-50%', integration_length='1'), #27: SORN_iSTDP(h_ip='same(SCTI, th)', eta_istdp='[0.0001#13]'), 30: SORN_finish() }) MT_SOM = NeuronGroup( net=SORN, tag='Martinotti Cell {},Somatostatin'.format(timescale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timescale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='0.6', so=so), # 1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) ''' EXP_NOX_CELL = NeuronGroup(net=SORN, tag='NOX Cell {}'.format(timescale), size=get_squared_dim(int(16)), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timescale, init_TH='0.04', activation_function='identity'), 3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution=None, normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='9.0', so=so),#1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) ''' BA_PV = NeuronGroup( net=SORN, tag='Basket Cell {},Parvalbumin'.format(timescale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timescale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 10: SORN_slow_syn(transmitter='GLU', strength='0.6', so=so), # 1.5353 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #20: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) CH_PV = NeuronGroup( net=SORN, tag='Chandelier Cell {},Parvalbumin'.format(timescale), size=get_squared_dim(int(0.07 * par['N_e'])), behaviour={ 2: SORN_init_neuron_vars(iteration_lag=timescale, init_TH='0.1;+-0%'), 3: SORN_init_afferent_synapses( transmitter='GLU', density='50%', distribution='lognormal(0,0.87038)', normalize=True), #4: SORN_init_afferent_synapses(transmitter='GABA', density='20%', distribution='lognormal(0,[0.82099#15])', normalize=True), # 40 #11: SORN_slow_syn(transmitter='GABA', strength='-[0.1838#16]', so=so), 14: SORN_fast_syn(transmitter='GLU', strength='0.4', so=so), #1.5353 #15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#17]', so=False),#0.08 19: SORN_input_collect(), #19: SORN_Refractory(factor='0.2;0.7'), 30: SORN_finish() }) MT_SOM['structure', 0].stretch_to_equal_size(PC) BA_PV['structure', 0].stretch_to_equal_size(PC) CH_PV['structure', 0].stretch_to_equal_size(PC) #EXP_NOX_CELL['structure', 0].stretch_to_equal_size(PC) SynapseGroup(net=SORN, src=PC, dst=PC, tag='GLU', connectivity='(s_id!=d_id)*in_box(10)', partition=True) SynapseGroup(net=SORN, src=PC, dst=MT_SOM, tag='GLU', connectivity='in_box(2)', partition=True) SynapseGroup(net=SORN, src=PC, dst=BA_PV, tag='GLU', connectivity='in_box(2)', partition=True) SynapseGroup(net=SORN, src=PC, dst=CH_PV, tag='GLU', connectivity='in_box(2)', partition=True) #SynapseGroup(net=SORN, src=PC, dst=EXP_NOX_CELL, tag='GLU', connectivity='in_box(3.75)', partition=True) SynapseGroup(net=SORN, src=MT_SOM, dst=PC, tag='GABA_Dendrite', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=BA_PV, dst=PC, tag='GABA_Soma', connectivity='in_box(10)', partition=True) SynapseGroup(net=SORN, src=CH_PV, dst=PC, tag='GABA_AIS', connectivity='in_box(10)', partition=True) #SynapseGroup(net=SORN, src=EXP_NOX_CELL, dst=PC, tag='GABA_NOX', connectivity='in_box(3.75)', partition=True) #SynapseGroup(net=SORN, src=SOM, dst=SOM, tag='GABA_D,SOM->SOM', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) #SynapseGroup(net=SORN, src=SOM, dst=PV, tag='GABA_D,SOM->PV', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) ##SynapseGroup(net=SORN, src=PV, dst=SOM, tag='GABA_P,PV->SOM')#not realistic? #SynapseGroup(net=SORN, src=PV, dst=PV, tag='GABA_P,PV->PV', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True) if last_PC is None: PC.add_behaviour( 9, SORN_external_input(strength=1.0, pattern_groups=[source])) #MT_SOM.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #BA_PV.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #CH_PV.add_behaviour(9, SORN_external_input(strength=1.0, pattern_groups=[source])) #else: # #forward synapses # SynapseGroup(net=SORN, src=last_PC, dst=PC, tag='GLU,PC->PC(+1)', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([10, 10], [partition, partition]) # SynapseGroup(net=SORN, src=last_PC, dst=SOM, tag='GABA,PC->SOM(+1)', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([5, 5], [2, 2]) # #backward synapses # SynapseGroup(net=SORN, src=PC, dst=last_PC, tag='GLU,PC(+1)->PC', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([10, 10], [partition, partition]) # SynapseGroup(net=SORN, src=PC, dst=last_SOM, tag='GABA,PC(+1)->SOM', connectivity='(s_id!=d_id)*(np.abs(sx-dx)<=10)*(np.abs(sy-dy)<=10)', partition=True)#.partition([5, 5], [2, 2]) last_PC = PC #last_MT_SOM = MT_SOM #last_BA_PV = BA_PV #last_CH_PV = CH_PV #last_EXP_NOX_CELL = EXP_NOX_CELL PC.color = get_color(0, timescale) MT_SOM.color = get_color(1, timescale) BA_PV.color = get_color(2, timescale) CH_PV.color = get_color(3, timescale) EXP_NOX_CELL.color = get_color(4, timescale) #EXP_NOX_CELL.display_min_max_act = (0, 0.3) SORN.set_marked_variables(ind, info=(ind == []), storage_manager=sm) SORN.initialize(info=False) ############################################################################################################################################################ score_spont = score_predict_train = score_predict_test = 0 Network_UI(SORN, label='SORN UI PC PV SOM', storage_manager=sm, group_display_count=4, reduced_layout=False).show() SORN = run_plastic_phase(SORN, steps_plastic=1000000, display=True, storage_manager=sm) #print(set(np.nonzero(np.array(SORN['drum_act', 0].seen))[1])) readout, X_train, Y_train, X_test, Y_test = train_readout( SORN, steps_train=100000, steps_test=100, source=SORN['drum_act', 0], display=True, stdp_off=True, storage_manager=sm) score_predict_train = get_score_predict_next_step(SORN, SORN['drum_act', 0], readout, X_train, Y_train, display=True, stdp_off=True, storage_manager=sm) score_predict_test = get_score_predict_next_step(SORN, SORN['drum_act', 0], readout, X_test, Y_test, display=True, stdp_off=True, storage_manager=sm) score_spont = get_score_spontaneous_music( SORN, SORN['drum_act', 0], readout, split_tracks=False, steps_spont=2000, display=True, stdp_off=True, same_timestep_without_feedback_loop=False, steps_recovery=0, create_MIDI=True, storage_manager=sm) #, steps_recovery=15000 sm.save_obj('score_train', score_predict_train) sm.save_obj('score_test', score_predict_test) sm.save_obj('score_spontaneous', score_spont) plot_frequencies_poly(score_spont, path=sm.absolute_path + 'frequencies', title='{} Ne, {} lag'.format(par['N_e'], par['TS'])) return score_predict_train, score_predict_test, score_spont