Exemplo n.º 1
0
    my_modules[0] = UI_sidebar_activity_module(1,
                                               add_color_dict={
                                                   'output': (255, 255, 255),
                                                   'Input_Mask':
                                                   (-100, -100, -100)
                                               })
    my_modules[8] = single_group_plot_tab({
        'activity': (0, 0, 0),
        'excitation': (0, 0, 255),
        'inhibition': (255, 0, 0),
        'input_act': (255, 0, 255),
        'exhaustion_value': (0, 255, 0)
    })
    Network_UI(SORN,
               modules=my_modules,
               label='SORN K_WTA',
               storage_manager=sm,
               group_display_count=1,
               reduced_layout=False).show()

#learning
SORN.simulate_iterations(plastic_steps, 100, measure_block_time=True)

#deactivate STDP and Input
SORN.deactivate_mechanisms('STDP')
SORN.deactivate_mechanisms('Text_Activator')

#recovery phase
SORN.simulate_iterations(5000, 100, measure_block_time=True)

#text generation
SORN['Text_Reconstructor', 0].reconstruction_history = ''
Exemplo n.º 2
0
        #for synapse in neurons.afferent_synapses['GLU']:
        #    neurons.activity += synapse.W.dot(synapse.src.output)/synapse.src.size

        #neurons.voltage += neurons.get_neuron_vec('uniform',density=0.01)

#source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=30, grid_height=30, center_x=list(range(40)), center_y=30 / 2, degree=90, line_length=60)

source = TNAP_Image_Patches(tag='image_act', image_path='C:/Users/Nutzer/Programmieren/Python_Modular_Neural_Network_Toolbox/Images/pexels-photo-275484.jpeg', grid_width=30, grid_height=30, dimensions=['on_center_white', 'off_center_white'], patch_norm=True)#'red', 'green', 'blue', 'gray', '255-red', '255-green', '255-blue', '255-gray',, 'rgbw', '255-rgbw''off_center_white',


SORN = Network()

e_ng = NeuronGroup(net=SORN, tag='PC_{},prediction_source'.format(1), size= NeuronDimension(width=30, height=30, depth=2), behaviour={
    1: init(),
    2: Input_Behaviour(),
    9: SORN_external_input(write_to='activity', strength=1.0, pattern_groups=[source]),
})

SynapseGroup(net=SORN, src=e_ng, dst=e_ng, tag='GLU,syn')

SORN.initialize(info=False)

# print(e_ng['GLU'])
# print(SORN.SynapseGroups)

###################################################################################################################

my_modules = get_default_UI_modules(['output']) + get_my_default_UI_modules()

Network_UI(SORN, modules=my_modules, label='test', storage_manager=None, group_display_count=1, reduced_layout=False).show()
Exemplo n.º 3
0
my_syn = SynapseGroup(net=My_Network,
                      src=My_Neurons2,
                      dst=My_Neurons2,
                      tag='GLUTAMATE')

My_Network.initialize()

my_syn.enabeled = my_syn.W > 0

My_Network.simulate_iterations(1000)

import matplotlib.pyplot as plt
plt.plot(My_Network['n.voltage', 0])
plt.plot(My_Network['np.mean(n.voltage)', 0], color='black')
plt.show()

import matplotlib.pyplot as plt
plt.scatter(My_Neurons1.x, My_Neurons1.y)
plt.show()

from PymoNNto.Exploration.Network_UI import *
from Examples_Paper.Basic.Basic_Tab import *
from Examples_UI.OpenGLTab import *
#+ [OpenGLTab()]

my_UI_modules = [MyUITab()] + get_default_UI_modules(['voltage', 'exhaustion'],
                                                     ['W']) + [OpenGLTab()]
Network_UI(My_Network,
           modules=my_UI_modules,
           label='My_Network_UI',
           group_display_count=2).show()
Exemplo n.º 4
0
def run(attrs={'name': 'KWTA', 'ind': [], 'N_e': 900, 'plastic': 15000}):
    so = True

    print_info = attrs.get('print', True)

    if print_info:
        print(attrs)

    sm = StorageManager(attrs['name'], random_nr=True, print_msg=print_info)
    sm.save_param_dict(attrs)

    #source = FewSentencesGrammar2(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015, frequency_adjustment=True)#21

    source = Line_Patterns(tag='image_act',
                           group_possibility=1.0,
                           grid_width=30,
                           grid_height=30,
                           center_x=list(range(40)),
                           center_y=30 / 2,
                           degree=90,
                           line_length=60)

    SORN = Network()

    e_ng = NeuronGroup(
        net=SORN,
        tag='PC_{},prediction_source'.format(1),
        size=get_squared_dim(attrs['N_e']),
        behaviour={
            2:
            SORN_init_neuron_vars(timescale=1),
            3:
            SORN_init_afferent_synapses(
                transmitter='GLU',
                density='40%',
                distribution='uniform(0.1,1.0)',
                normalize=True
            ),  #20%#lognormal(0,[0.95#1]) #[13#0]% #, partition_compensation=True , partition_compensation=True #lognormal(0,0.95)
            #4: SORN_init_afferent_synapses(transmitter='GABA', density='[30#1]%', distribution='uniform(0.0,1.0)', normalize=True),
            5:
            SORN_init_afferent_synapses(transmitter='GLU_cluster',
                                        density='40%',
                                        distribution='uniform(0.1,1.0)',
                                        normalize=True),

            #10.0: SORN_slow_syn
            10.0:
            SORN_slow_syn_simple(transmitter='GLU', strength='1.0',
                                 so=so),  #todo: SORN_slow_syn_simple??????
            10.1:
            SORN_IP_WTA_apply(),
            10.15:
            WTA_refrac_apply(strengthfactor='[0.1#0]'),  #0.1 #attrs['refrac']
            10.2:
            SORN_generate_output_K_WTA_partitioned(partition_size=7,
                                                   K='[0.02#1]'),
            10.3:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.4:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.5:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.6:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.7:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.8:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),

            # 12.1: SORN_WTA_iSTDP(eta_iSTDP='[0.00015#2]'),
            # 12.2: SORN_SN(syn_type='GABA'),
            #13.4: SORN_generate_output_K_WTA_partitioned(K='[0.12#4]'),
            #13.5: SORN_WTA_fast_syn(transmitter='GABA', strength='-[0.5#5]', so=so),#[0.1383#2]SORN_fast_syn
            #14: WTA_refrac(),
            #, filter_temporal_output=True
            15:
            SORN_buffer_variables(random_temporal_output_shift=False),
            18:
            WTA_refrac(decayfactor=0.5),
            20:
            SORN_IP_WTA(h_ip='lognormal_real_mean([0.02#1], [0.2944#2])',
                        eta_ip='[0.007#3]',
                        target_clip_min=None,
                        target_clip_max=None),  #-1.0 #1.0 #0.007
            21.1:
            SORN_STDP(transmitter='GLU',
                      eta_stdp='[0.00015#4]',
                      STDP_F={
                          -1: 0.2,
                          1: -1
                      }),  #, 0: 1 #[0.00015#7] #0.5, 0: 3.0
            21.2:
            SORN_STDP(transmitter='GLU_cluster',
                      eta_stdp='[0.00015#5]',
                      STDP_F={0: 2.0}),  #[0.00015#7]
            30:
            SORN_structural_plasticity(syn_type='syn', step_ct=1),
            #31: SORN_weight_noise(max_noise=0.0001),
            41:
            SORN_SN(syn_type='GLU', behaviour_norm_factor=1.0),
            42:
            SORN_SN(syn_type='GLU_cluster',
                    behaviour_norm_factor='[0.3#6]'),  # 0.1
        })

    # SynapseGroup(net=SORN, src=retina, dst=e_ng, tag='GLU,GLU_same', connectivity='(s_id!=d_id)*in_box(10)', partition=True)

    receptive_field = 18
    #receptive_field = int(18*math.sqrt(attrs['N_e']/1400))
    print(receptive_field)

    SynapseGroup(
        net=SORN, src=e_ng, dst=e_ng, tag='GLU,syn'
    )  #, connectivity='(s_id!=d_id)*in_box({})'.format(receptive_field))#, partition=True)#14
    SynapseGroup(
        net=SORN, src=e_ng, dst=e_ng, tag='GLU_cluster,syn'
    )  #, connectivity='(s_id!=d_id)*in_box({})'.format(receptive_field))#, partition=True)
    #SynapseGroup(net=SORN, src=e_ng, dst=e_ng, tag='GABA,GABA_same', connectivity='(s_id!=d_id)*in_box(10)', partition=True)

    e_ng.add_behaviour(
        9, SORN_external_input(strength=1.0, pattern_groups=[source]))

    if __name__ == '__main__' and attrs.get('UI', False):
        e_ng.color = get_color(0, 1)

    SORN.set_marked_variables(info=print_info, storage_manager=sm)
    SORN.initialize(info=False)

    #print(e_ng['GLU'])
    #print(SORN.SynapseGroups)

    ###################################################################################################################

    if __name__ == '__main__' and attrs.get('UI', False):
        my_modules = get_default_UI_modules([
            'output', 'exhaustion_value', 'weight_norm_factor'
        ]) + get_my_default_UI_modules()
        my_modules[0] = UI_sidebar_activity_module(1,
                                                   add_color_dict={
                                                       'output':
                                                       (255, 255, 255),
                                                       'Input_Mask':
                                                       (-100, -100, -100)
                                                   })
        #my_modules[1] = multi_group_plot_tab(['output', 'exhaustion_value', 'weight_norm_factor'])  # , 'nox', 'refractory_counter'
        my_modules[8] = single_group_plot_tab({
            'activity': (0, 0, 0),
            'excitation': (0, 0, 255),
            'inhibition': (255, 0, 0),
            'input_act': (255, 0, 255),
            'exhaustion_value': (0, 255, 0)
        })
        Network_UI(SORN,
                   modules=my_modules,
                   label='SORN UI K_WTA',
                   storage_manager=sm,
                   group_display_count=1,
                   reduced_layout=False).show()

    score = 0
    plastic_steps = attrs.get('plastic', 20000)

    #for i in range(1):
    #    #sm = StorageManager(attrs['name'] + '[{:03d}]'.format(i + 1), random_nr=True, print_msg=print_info)
    #    #sm.save_param_dict(attrs)
    #    sm=None
    #    score += train_and_generate_text(SORN, plastic_steps, 5000, 1000, display=print_info, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=1000, storage_manager=sm, return_key='right_sentences_square_score')

    score = 0

    #print(train_and_generate_text(SORN, plastic_steps, 5000, 1000, display=print_info, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=5000, storage_manager=sm, return_key='right_sentences_square_score'))
    #print('Output:')
    #print(predict_text_max_source_act(SORN, plastic_steps, 5000, 5000, display=True, stdp_off=True))#plastic_steps, 5000, 1000

    #print('score=', score)

    return get_max_text_score(SORN,
                              plastic_steps,
                              5000,
                              5000,
                              display=True,
                              stdp_off=True,
                              return_key='right_word_square_score')
Exemplo n.º 5
0
def run(attrs={'name': 'KWTA', 'ind': [], 'N_e': 900, 'plastic': 15000}):
    so = True

    print_info = attrs.get('print', True)

    if print_info:
        print(attrs)

    sm = StorageManager(attrs['name'], random_nr=True, print_msg=print_info)
    sm.save_param_dict(attrs)

    #source = NewGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015, frequency_adjustment=True)
    #source = FewSentencesContextGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015, frequency_adjustment=True)#
    source = FewSentencesGrammar(tag='grammar_act',
                                 output_size=attrs['N_e'],
                                 random_blocks=True,
                                 input_density=0.015,
                                 frequency_adjustment=True)  #21
    #source = FewLongSentencesGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015, frequency_adjustment=True)

    #txt='guin eats fish. parrot eats mets. pex eits box ests bea esfish. perrod eats mets. penguin eat. fish. pareod eats mets. bex ests brrod eats mets. box eats brx ests bryod eats mets. pey uin eats fish. parrot eats metd. penguin eats fish. parrot eats mets. pey uin eats fish. pareot eats muts. penguin eats fish. perrot eats mets. pey uingeany fiseanf fnx . ts buin eat. fish. parrot eats mets. bey eats brxod eats bets. beyguin eatf fish. parrot eats bets. penguin eats fish. parrot eats metd. box e ts brx ests bea . fox ests brx edts bgxin eatbefish. perrot eats mets. peyguin eats fish. parrot eats muts. beyguin eats fish. parrotneats mets. feyguin eats fish. parrot eats muts. beyguin eats fish. parrot eats mets. bay uingeanf ftshf sh. per ot  ats mets. box eins boe e ts box eats brxddy fnseingoin eath. fah. d  buinueats fish. parrot eats mets. pay uin uats fish. parrot eats mets. perguinguat eais . pen uin eats fish. perrot eats mets. boyguinsuin eat. boe d  box euin eat  fish. panrod eats metd. beyguins bnx eats brx t d. soxead. fox eats brx ests bradd eats mets. poy uin eatg fish. parrot eats mets. pey uin eats fish. parrot eats mets. pey uin eaes fish. parrot eats mets. ponguin eats fish. perrodneats meas. box eats brx d.ts mguin eats fish. paneod eats meas. payguin aat  fish. pareot eats mets. peyguin eats fish. panguineuat bfish. parrod eats mets. pox eits brx eats brx eats brx eats brx eats box eats brx eats bead. ponguineeats fish. pareot eats mets. pexguin eats fish. parrot eats mets. pedguin eats fish. porrot eats mets. box eits box eats bex d forrot eats muts. bey uin uins atsh. fh. od eatn eath.ffeh. parrot eats mets. box uin uing atshf sh. pargod eats mets. pan uin eats fish. perrod eats mets. box eats boa eats fguin eats fish. parrot eats mets. poyguin eats fish. porrot eats mets. box eits bre eats brx eats breot eats bet . box ein uins atsh. fh. pdnguin eat  fish. parrot eats meas. box eats breot eats mets. fesh. par ot eats metd. box eiss besufish. parrot eats mets. payguin  ans fish. parrot eats mets. poyguin eats fish. parrot eats mets. box eats brx eats brx eats breod eats meat. box dats brx eatsnfiin eat. fo h. pod.uin eats fish. parrot eats mets. penguin eats fish. perrot eats mets. penguin eats fish. porrot eats bets. penguin eats fish. parrot eats mets. parguin eats fish. parrot eats metd. box eats bea eatsnbuing ats fish. parrot eats mead. bon eits bead. box ein eats fish. pareot eats mets. peyguin eats fish. parrot eats bets. bey eass brx eats breod eats mets. poyguin aats fish. porrot eats mets. penguin eats fish. parroineeats fish. par ot eafs mets. box eats brx eats bre eats bgxin eats fish. parrot eats buts. panguin eats fish. poneoi. eat. box eats bre e. box eans ats fish. forrot eats mets. box eits brx eats breot  ats metd. box eats braot eats mets. perguin eats fish. parrot eats mets. poy ein eats fish. parrot eats mets. penguin eats fish. parrot eats mett. ead. box eats breod eats meas. box eats brx eats bread eats eats fish. perrot eats mead. box eats braod eats mets. poyguin eats fish. parrot eats beat. fox . ts fuin eats fish. parrot eats mets. penguin eats fish. barrot eats meas. box eats bread. fongod eaas mfish. parrot eats mets. pex eins mea . sa. uin eats fish. borroineeats fish. parrot eats mets. pey eits mea f bhn uinruin eats fish. parrot eats muts. peyguin eats fish. barrot eats mead. box eats brx eats brx eats brx eats breaeats me. . nguin eats fish. parrot eats mets. pey efn  inuinneats fish. panguin eats fish. perrot eats mets. penguin eats fish. parrod. fox eats bre eats bre eats mets. penguin eats fish. perrot eats mea . box eats bre eats uin eats fish. parrot eats meas. feygu n eats fish. parrod eats mets. poy uins brx eats box eats bre eats  ead. forrod eats muts. penguin eats fish. penrod. fat. fox eats brx d. eat. box eats bradd. bad  eat. fash. ngnguin eats fish. parrot eats mets. poy uins aeatfibo. eats bets. perguin uinseatshfish. p rrot eats mets. penguin eats fish. parrot eats mets. penguin eats fish. barrot eats mets. penguin eats fish. parrot eats mets. penguin eats fish. box eanh ata f fo. pansod eats mets. poyguin umea fish. parrot eats mets. payguineaa.  on uinseats fish. por ea e me seape buineats braad. erxutn. pe meas. penguin eats fish. parrot eats mets. box eats bre eats breod eats mead. por eats bre eats bre eats nuti. pat.ufng . p eguinfeat. fish. porrot eats mets. poy eats bea eats brx d eats aets. panguin eats fish. parrot eats mets. poy eats bread. box eats brx eats beat.  fog. ats uin eats fish. parrot eats mets. poy uan eins atsh. fh. od eats mets. box eits breod eats mets. pey ean aats fish. parrot eats mets. poy uin eats fish. parrot eats mets. box eats brx eatsnfeat  fish. parrot eats mets. pey eanseats fish. parrot eats bets. box eats braod eats meat. foxh. borgoineeas  uts. pox eins mea . panguin eats fish. parrot eats bets. boy eins ang ats fiah. b reoi. eats fish. parrot eats mets. peyguin eats fish. parrot eats mets. poy ed eats m'
    #html = source.mark_with_grammar(txt)
    #show_html(html)

    #source = SingleWordGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015)
    #source = FewLongSentencesGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015)
    #source.plot_char_frequency_histogram(20)

    SORN = Network()

    e_ng = NeuronGroup(
        net=SORN,
        tag='PC_{},prediction_source'.format(1),
        size=get_squared_dim(attrs['N_e']),
        behaviour={
            2:
            SORN_init_neuron_vars(timescale=1),
            3:
            SORN_init_afferent_synapses(
                transmitter='GLU',
                density='90%',
                distribution='uniform(0.1,1.0)',
                normalize=True
            ),  #20%#lognormal(0,[0.95#1]) #[13#0]% #, partition_compensation=True , partition_compensation=True #lognormal(0,0.95)
            #4: SORN_init_afferent_synapses(transmitter='GABA', density='[30#1]%', distribution='uniform(0.0,1.0)', normalize=True),
            5:
            SORN_init_afferent_synapses(transmitter='GLU_cluster',
                                        density='90%',
                                        distribution='uniform(0.1,1.0)',
                                        normalize=True),

            #10.0: SORN_slow_syn
            10.0:
            SORN_slow_syn_simple(transmitter='GLU', strength='1.0',
                                 so=so),  #todo: SORN_slow_syn_simple??????
            10.1:
            SORN_IP_WTA_apply(),
            10.15:
            WTA_refrac_apply(strengthfactor='[0.1#0]'),  #0.1 #attrs['refrac']
            10.2:
            SORN_generate_output_K_WTA_partitioned(partition_size=7,
                                                   K='[0.02#1]'),
            10.3:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.4:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.5:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.6:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.7:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.8:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),

            # 12.1: SORN_WTA_iSTDP(eta_iSTDP='[0.00015#2]'),
            # 12.2: SORN_SN(syn_type='GABA'),
            #13.4: SORN_generate_output_K_WTA_partitioned(K='[0.12#4]'),
            #13.5: SORN_WTA_fast_syn(transmitter='GABA', strength='-[0.5#5]', so=so),#[0.1383#2]SORN_fast_syn
            #14: WTA_refrac(),
            #, filter_temporal_output=True
            15:
            SORN_buffer_variables(random_temporal_output_shift=False),
            18:
            WTA_refrac(decayfactor=0.5),
            20:
            SORN_IP_WTA(h_ip='lognormal_real_mean([0.02#1], [0.2944#2])',
                        eta_ip='[0.007#3]',
                        target_clip_min=None,
                        target_clip_max=None),  #-1.0 #1.0 #0.007
            21.1:
            SORN_STDP(transmitter='GLU',
                      eta_stdp='[0.00015#4]',
                      STDP_F={
                          -1: 0.2,
                          1: -1
                      }),  #, 0: 1 #[0.00015#7] #0.5, 0: 3.0
            21.2:
            SORN_STDP(transmitter='GLU_cluster',
                      eta_stdp='[0.00015#5]',
                      STDP_F={0: 2.0}),  #[0.00015#7]
            22:
            SORN_SN(syn_type='GLU', behaviour_norm_factor=1.0),
            23:
            SORN_SN(syn_type='GLU_cluster',
                    behaviour_norm_factor='[0.3#6]'),  #0.1
        })

    # SynapseGroup(net=SORN, src=retina, dst=e_ng, tag='GLU,GLU_same', connectivity='(s_id!=d_id)*in_box(10)', partition=True)

    receptive_field = 18
    #receptive_field = int(18*math.sqrt(attrs['N_e']/1400))
    print(receptive_field)

    SynapseGroup(net=SORN,
                 src=e_ng,
                 dst=e_ng,
                 tag='GLU,syn',
                 connectivity='(s_id!=d_id)*in_box({})'.format(
                     receptive_field))  #, partition=True)#14
    SynapseGroup(net=SORN,
                 src=e_ng,
                 dst=e_ng,
                 tag='GLU_cluster,syn',
                 connectivity='(s_id!=d_id)*in_box({})'.format(
                     receptive_field))  #, partition=True)
    #SynapseGroup(net=SORN, src=e_ng, dst=e_ng, tag='GABA,GABA_same', connectivity='(s_id!=d_id)*in_box(10)', partition=True)

    e_ng.add_behaviour(
        9, SORN_external_input(strength=1.0, pattern_groups=[source]))

    if __name__ == '__main__' and attrs.get('UI', False):
        e_ng.color = get_color(0, 1)

    SORN.set_marked_variables(attrs['ind'],
                              info=print_info,
                              storage_manager=sm)
    SORN.initialize(info=False)

    #print(e_ng['GLU'])
    #print(SORN.SynapseGroups)

    ###################################################################################################################

    if __name__ == '__main__' and attrs.get('UI', False):
        my_modules = get_default_UI_modules([
            'output', 'exhaustion_value', 'weight_norm_factor'
        ]) + get_my_default_UI_modules()
        my_modules[0] = UI_sidebar_activity_module(1,
                                                   add_color_dict={
                                                       'output':
                                                       (255, 255, 255),
                                                       'Input_Mask':
                                                       (-100, -100, -100)
                                                   })
        #my_modules[1] = multi_group_plot_tab(['output', 'exhaustion_value', 'weight_norm_factor'])  # , 'nox', 'refractory_counter'
        my_modules[8] = single_group_plot_tab({
            'activity': (0, 0, 0),
            'excitation': (0, 0, 255),
            'inhibition': (255, 0, 0),
            'input_act': (255, 0, 255),
            'exhaustion_value': (0, 255, 0)
        })
        Network_UI(SORN,
                   modules=my_modules,
                   label='SORN UI K_WTA',
                   storage_manager=sm,
                   group_display_count=1,
                   reduced_layout=False).show()

    score = 0
    plastic_steps = attrs.get('plastic', 20000)

    #for i in range(1):
    #    #sm = StorageManager(attrs['name'] + '[{:03d}]'.format(i + 1), random_nr=True, print_msg=print_info)
    #    #sm.save_param_dict(attrs)
    #    sm=None
    #    score += train_and_generate_text(SORN, plastic_steps, 5000, 1000, display=print_info, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=1000, storage_manager=sm, return_key='right_sentences_square_score')

    score = 0

    #print(train_and_generate_text(SORN, plastic_steps, 5000, 1000, display=print_info, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=5000, storage_manager=sm, return_key='right_sentences_square_score'))
    #print('Output:')
    #print(predict_text_max_source_act(SORN, plastic_steps, 5000, 5000, display=True, stdp_off=True))#plastic_steps, 5000, 1000

    #print('score=', score)

    return get_max_text_score(SORN,
                              plastic_steps,
                              5000,
                              5000,
                              display=True,
                              stdp_off=True,
                              return_key='right_word_square_score')
Exemplo n.º 6
0
def run(
    attrs={
        'name': 'maze',
        'ind': [],
        'N_e': 900,
        'TS': [1],
        'ff': True,
        'fb': True,
        'plastic': 15000
    }):
    so = True

    print_info = attrs.get('print', True)

    if print_info:
        print(attrs)

    sm = StorageManager(attrs, random_nr=True, print_msg=print_info)
    sm.save_param_dict(attrs)

    #source = LongDelayGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, mode=['simple'], input_density=0.01)
    maze = Maze(level='default')

    SORN = Network()  #behaviour={maze.get_network_behaviour()}

    SORN.maze = maze

    for layer, timescale in enumerate(attrs['TS']):

        e_location = NeuronGroup(
            net=SORN,
            tag='E_location_{}'.format(timescale),
            size=maze.get_location_neuron_dimension(),
            behaviour={
                2:
                SORN_init_neuron_vars(timescale=timescale),
                3:
                SORN_init_afferent_synapses(
                    transmitter='GLU',
                    density='full',
                    distribution='uniform(0.1,0.11)',
                    normalize=True,
                    partition_compensation=True
                ),  # 0.89 uniform(0.1,0.11)uniform(0,[0.95#0])
                4:
                SORN_init_afferent_synapses(
                    transmitter='GABA',
                    density='full',
                    distribution='uniform(0.1,0.11)',
                    normalize=True
                ),  # 0.80222 uniform(0.1,0.11) lognormal(0,[0.4#1])
                9:
                maze.get_location_neuron_behaviour(),  ###############
                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_generate_output(init_TH='0.1;+-100%'),
                19:
                SORN_buffer_variables(),
                20:
                SORN_Refractory_Analog(factor='0.5;+-50%'),
                21:
                SORN_STDP(eta_stdp='[0.0015#5]',
                          weight_attr='W_temp',
                          STDP_F={
                              -5: 0.2,
                              -4: 0.4,
                              -3: 0.6,
                              -2: 0.8,
                              -1: 1
                          }),
                22:
                SORN_temporal_synapses(syn_type='GLU',
                                       behaviour_norm_factor=1.0),
                #22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=1.0),
                23:
                SORN_IP_TI(h_ip='lognormal_real_mean([0.004#6], [0.2944#7])',
                           eta_ip='[0.0006#8];+-50%',
                           integration_length='[15#18];+-50%',
                           clip_min=None),
                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]'),

                #29: SORN_dopamine(),
            })

        i_location = NeuronGroup(
            net=SORN,
            tag='I_location{}'.format(timescale),
            size=maze.get_inhibitory_location_neuron_dimension(),
            behaviour={
                2:
                SORN_init_neuron_vars(timescale=timescale),
                3:
                SORN_init_afferent_synapses(
                    transmitter='GLU',
                    density='50%',
                    distribution='uniform(0.1,0.11)',
                    normalize=True),  #lognormal(0,[0.87038#14])
                4:
                SORN_init_afferent_synapses(
                    transmitter='GABA',
                    density='20%',
                    distribution='uniform(0.1,0.11)',
                    normalize=True),  #lognormal(0,[0.82099#15])
                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_generate_output(init_TH='0.1;+-0%'),
                19:
                SORN_buffer_variables(),
                20:
                SORN_Refractory_Analog(factor='0.2;0.7'),
            })
        '''
        e_vision = NeuronGroup(net=SORN, tag='E_vision_{}'.format(timescale), size=maze.get_vision_neuron_dimension(), behaviour={
                2: SORN_init_neuron_vars(timescale=timescale),
                3: SORN_init_afferent_synapses(transmitter='GLU', density='full', 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)

                9: maze.get_vision_neuron_behaviour(),

                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_generate_output(init_TH='0.01'),
                19: SORN_buffer_variables(),

                #20: SORN_Refractory(factor='0.5;+-50%'),
                #21: SORN_STDP(eta_stdp='[0.00015#5]'),
                #22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=5.0),

                #23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
                #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]')

            })
        '''

        e_action = NeuronGroup(
            net=SORN,
            tag='E_action_{}'.format(timescale),
            size=maze.get_action_neuron_dimension(),
            behaviour={
                2:
                SORN_init_neuron_vars(timescale=timescale),
                3:
                SORN_init_afferent_synapses(
                    transmitter='GLU',
                    density='full',
                    distribution='uniform(0.1,0.11)',
                    normalize=True,
                    partition_compensation=True),  # 0.89 lognormal(0,[0.5#0])
                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_generate_output(init_TH='0.01'),
                19:
                SORN_buffer_variables(),
                20:
                SORN_Refractory_Analog(factor='0.7;+-50%'),
                21:
                SORN_STDP(eta_stdp='[0.0015#5]',
                          STDP_F={
                              -1: 1,
                              1: 0
                          },
                          weight_attr='W_temp'),  #bigger #todo!!!!
                #22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=5.0),
                22:
                SORN_temporal_synapses(syn_type='GLU',
                                       behaviour_norm_factor=5.0),
                23:
                SORN_IP_TI(h_ip='0.04',
                           eta_ip='0.001',
                           integration_length='[15#18];+-50%',
                           clip_min=None),
                #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]')
                29:
                SORN_dopamine(),
                30:
                maze.get_action_neuron_behaviour()
            })
        '''
        e_reward = NeuronGroup(net=SORN, tag='E_reward_{}'.format(timescale), size=maze.get_reward_neuron_dimension(), behaviour={
                2: SORN_init_neuron_vars(timescale=timescale),
                3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution='lognormal(0,[0.95#0])', normalize=True, partition_compensation=True),

                9: maze.get_reward_neuron_behaviour(),

                12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so),
                18: SORN_generate_output(init_TH='0.01'),
                19: SORN_buffer_variables(),

                #20: SORN_Refractory(factor='0.5;+-50%'),
                21: SORN_STDP(eta_stdp='[0.00015#5]'),
                22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=0.1),

                #23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
                #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]')
            })
        '''

        e_punishment = NeuronGroup(
            net=SORN,
            tag='E_punishment_{}'.format(timescale),
            size=maze.get_punishment_neuron_dimension(),
            behaviour={
                2:
                SORN_init_neuron_vars(timescale=timescale),
                3:
                SORN_init_afferent_synapses(
                    transmitter='GLU',
                    density='full',
                    distribution='lognormal(0,[0.95#0])',
                    normalize=True,
                    partition_compensation=True),
                9:
                maze.get_punishment_neuron_behaviour(),
                12:
                SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so),
                18:
                SORN_generate_output(init_TH='0.01'),
                19:
                SORN_buffer_variables(),

                #20: SORN_Refractory(factor='0.5;+-50%'),
                21:
                SORN_STDP(eta_stdp='[0.00015#5]'),  #todo!!!!
                22:
                SORN_SN(syn_type='GLU',
                        clip_max=None,
                        behaviour_norm_factor=0.1),

                #23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
                #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]')
            })

        i_location['structure', 0].stretch_to_equal_size(e_location)

        SynapseGroup(net=SORN,
                     src=e_location,
                     dst=e_location,
                     tag='GLU,GLU_same',
                     connectivity='(s_id!=d_id)*in_box(10)',
                     partition=True)
        SynapseGroup(net=SORN,
                     src=e_location,
                     dst=i_location,
                     tag='GLU',
                     connectivity='in_box(10)',
                     partition=True)
        SynapseGroup(net=SORN,
                     src=i_location,
                     dst=e_location,
                     tag='GABA',
                     connectivity='in_box(10)',
                     partition=True)
        SynapseGroup(net=SORN,
                     src=i_location,
                     dst=i_location,
                     tag='GABA',
                     connectivity='(s_id!=d_id)*in_box(10)',
                     partition=True)

        #SynapseGroup(net=SORN, src=e_vision, dst=e_location, tag='GLU', partition=True)
        SynapseGroup(net=SORN,
                     src=e_location,
                     dst=e_action,
                     tag='GLU',
                     partition=True)

        #SynapseGroup(net=SORN, src=e_location, dst=e_reward, tag='GLU', partition=True)
        #SynapseGroup(net=SORN, src=e_reward, dst=e_location, tag='DOP+', partition=True)
        #SynapseGroup(net=SORN, src=e_reward, dst=e_action, tag='DOP+', partition=True)

        SynapseGroup(net=SORN,
                     src=e_location,
                     dst=e_punishment,
                     tag='GLU',
                     partition=True)
        SynapseGroup(net=SORN,
                     src=e_punishment,
                     dst=e_location,
                     tag='DOP-',
                     partition=True)
        SynapseGroup(net=SORN,
                     src=e_punishment,
                     dst=e_action,
                     tag='DOP-',
                     partition=True)

        if __name__ == '__main__' and attrs.get('UI', False):
            e_location.color = (0, 0, 255, 255)
            i_location.color = (255, 0, 0, 255)
            e_action.color = (255, 255, 0, 255)
            #e_vision.color = (0, 255, 255, 255)
            #e_reward.color = (100, 255, 100, 255)
            e_punishment.color = (255, 100, 100, 255)

    SORN.set_marked_variables(attrs['ind'],
                              info=print_info,
                              storage_manager=sm)
    SORN.initialize(info=False)

    ###################################################################################################################

    if __name__ == '__main__' and attrs.get('UI', False):
        #default_modules.insert(0, maze_tab())
        #Network_UI(SORN, label='SORN UI default setup', storage_manager=sm, group_display_count=4, reduced_layout=True).show()
        Network_UI(SORN,
                   modules=get_default_UI_modules() + [maze_tab()],
                   label='SORN UI K_WTA',
                   storage_manager=sm,
                   group_display_count=1,
                   reduced_layout=False).show()

    return 0
Exemplo n.º 7
0
def run(attrs={'name':'hierarchical', 'ind':[], 'N_e':900, 'TS':[1], 'ff':True, 'fb':True, 'plastic':15000}):

    so = True

    print_info = attrs.get('print', True)

    if print_info:
        print(attrs)

    #sm = None
    sm = StorageManager(attrs['name'], random_nr=True, print_msg=print_info)
    sm.save_param_dict(attrs)

    #grammar mode: what level17_short simple

    #source = FDTGrammarActivator_New(tag='grammar_act', random_blocks=True, input_density=0.015)#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=attrs['N_e'], random_blocks=True, mode=['level17_short'], input_density=0.015)#.print_test()#.plot_char_input_statistics()#10/par['N_e']

    #source = SingleWordGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015)

    source = FewSentencesGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, input_density=0.015)

    #print(source.print_test())

    #print([t for t in source.get_all_grammar_transitions() if len(t)==2])

    #source.plot_char_input_statistics()
    #print(len(source.alphabet))
    #img_source = Line_Patterns(tag='image_act', group_possibility=1.0, grid_width=20, grid_height=20, center_x=list(range(20)), center_y=20 / 2, degree=90, line_length=60, select_mode='random')
    #print(source.get_text_score('. parrot likes trees. wolf wolf wolf..'))

    SORN = Network()




    #retina = NeuronGroup(net=SORN, tag='retina', size=get_squared_dim(20*20), behaviour={
    #        2: SORN_init_neuron_vars(timescale=1),

            #9: SORN_external_input(strength=1.0, pattern_groups=[img_source]),

            #18: SORN_generate_output(init_TH='0.1;+-100%'),
            #19: SORN_buffer_variables(random_temporal_output_shift=False),

            #20: SORN_Refractory_Analog(factor='0.5;+-50%'),
        #})


    for layer, timescale in enumerate(attrs['TS']):

        e_ng = NeuronGroup(net=SORN, tag='PC_{},prediction_source'.format(timescale), size=get_squared_dim(int(attrs['N_e']/timescale)), behaviour={
            2: SORN_init_neuron_vars(timescale=timescale),
            3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution='lognormal(0,[0.95#0])', normalize=True, partition_compensation=True),#0.89 uniform(0.1,0.11)#13%
            4: SORN_init_afferent_synapses(transmitter='GABA', density='full', distribution='lognormal(0,[0.4#1])', normalize=True),#0.80222 uniform(0.1,0.11)#45%

            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_generate_output(init_TH='0.1;+-100%'),
            19: SORN_buffer_variables(random_temporal_output_shift=False),

            #20: SORN_Refractory_Digital(factor='0.5;+-50%', threshold=0.1),
            20: SORN_Refractory_Analog(factor='0.5;+-50%'),
            21: SORN_STDP(eta_stdp='[0.00015#5]'),#, STDP_F={-4:-0.01,-3:0.01,-2:0.1,-1:0.5,0:0.2,1:-0.3,2:-0.1,3:-0.05}, plot=True),#{-2:0.1,-1:0.5,0:0.2,1:-0.3,2:-0.1}
            22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=1.0),
            #22.1: SORN_SN(syn_type='GLU_same', clip_max=None, behaviour_norm_factor=0.6),
            #22.2: SORN_SN(syn_type='GLU_ff', clip_max=None, behaviour_norm_factor=0.25),
            #22.3: SORN_SN(syn_type='GLU_fb', clip_max=None, behaviour_norm_factor=0.25),7z

            23: SORN_IP_TI(h_ip='lognormal_real_mean([0.04#6], [0.2944#7])', eta_ip='[0.0006#8];+-50%', integration_length='[15#19];+-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]')
        })

        i_ng = NeuronGroup(net=SORN, tag='Inter_{}'.format(timescale), size=get_squared_dim(int(0.2 * attrs['N_e']/timescale)), behaviour={
            2: SORN_init_neuron_vars(timescale=timescale),
            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#17]', so=so),#1.5353
            15: SORN_fast_syn(transmitter='GABA', strength='-[0.08#18]', so=False),#0.08
            18: SORN_generate_output(init_TH='0.1;+-0%'),
            19: SORN_buffer_variables(),

            #20: SORN_Refractory_Digital(factor='0.2;0.7', threshold=0.1),
            20: SORN_Refractory_Analog(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),
        })

        i_ng['structure', 0].stretch_to_equal_size(e_ng)

        #SynapseGroup(net=SORN, src=retina, dst=e_ng, tag='GLU,GLU_same', connectivity='(s_id!=d_id)*in_box(10)', partition=True)

        SynapseGroup(net=SORN, src=e_ng, dst=e_ng, tag='GLU,GLU_same', 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)



        if layer > 0:
            if attrs.get('ff', True):#forward synapses
                SynapseGroup(net=SORN, src=last_e_ng, dst=e_ng, tag='GLU,GLU_ff', 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])
            if attrs.get('fb', False):#backward synapses
                SynapseGroup(net=SORN, src=e_ng, dst=last_e_ng, tag='GLU,GLU_fb', 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])
        #else:
            # 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]))

        last_e_ng = e_ng
        last_i_ng = i_ng

        if __name__ == '__main__' and attrs.get('UI', False):
            e_ng.color = get_color(0, timescale)
            i_ng.color = get_color(1, timescale)

    SORN.set_marked_variables(attrs['ind'], info=print_info, storage_manager=sm)
    SORN.initialize(info=False)

    ###################################################################################################################

    if __name__ == '__main__' and attrs.get('UI', False):
        my_modules = get_default_UI_modules() + get_my_default_UI_modules()
        Network_UI(SORN, modules=my_modules, label='SORN UI default setup', storage_manager=sm, group_display_count=2, reduced_layout=False).show()


    score = 0
    plastic_steps = attrs.get('plastic', 20000)

    for i in range(1):
        sm = StorageManager(attrs['name']+'[{:03d}]'.format(i+1), random_nr=True, print_msg=print_info)
        sm.save_param_dict(attrs)
        score += train_and_generate_text(SORN, plastic_steps, 5000, 1000, display=print_info, stdp_off=True, same_timestep_without_feedback_loop=True, steps_recovery=1000, storage_manager=sm)#5000, 3000 stdp_off=True

    #score += get_oscillation_score_hierarchical(SORN, 0, 5000)
    #print(predict_text_max_source_act(SORN, plastic_steps, 1000, 2000))
    #t = max_source_act_text(SORN, 2000)
    #print(t)
    return score
Exemplo n.º 8
0
def run(
    attrs={
        'name': 'maze',
        'ind': [],
        'N_e': 900,
        'TS': [1],
        'ff': True,
        'fb': True,
        'plastic': 15000
    }):
    so = True

    print_info = attrs.get('print', True)

    if print_info:
        print(attrs)

    sm = StorageManager(attrs, random_nr=True, print_msg=print_info)
    sm.save_param_dict(attrs)

    #source = LongDelayGrammar(tag='grammar_act', output_size=attrs['N_e'], random_blocks=True, mode=['simple'], input_density=0.01)
    maze = Maze(level='default', same_color=False)

    SORN = Network()  #behaviour={maze.get_network_behaviour()}

    SORN.maze = maze

    e_location = NeuronGroup(
        net=SORN,
        tag='PC_{},prediction_source'.format(1),
        size=maze.get_location_neuron_dimension(),
        behaviour={
            2:
            SORN_init_neuron_vars(timescale=1),
            3:
            SORN_init_afferent_synapses(
                transmitter='GLU',
                density='90%',
                distribution='uniform(0.1,1.0)',
                normalize=True
            ),  #20%#lognormal(0,[0.95#1]) #[13#0]% #, partition_compensation=True , partition_compensation=True #lognormal(0,0.95)
            #4: SORN_init_afferent_synapses(transmitter='GABA', density='[30#1]%', distribution='uniform(0.0,1.0)', normalize=True),
            5:
            SORN_init_afferent_synapses(transmitter='GLU_cluster',
                                        density='90%',
                                        distribution='uniform(0.1,1.0)',
                                        normalize=True),
            8:
            maze.get_vision_neuron_behaviour(),
            9:
            maze.get_location_neuron_behaviour(),

            #10.0: SORN_slow_syn
            10.0:
            SORN_slow_syn_simple(transmitter='GLU', strength='1.0',
                                 so=so),  #todo: SORN_slow_syn_simple??????
            10.1:
            SORN_IP_WTA_apply(),
            #10.15: WTA_refrac_apply(strengthfactor='[0.1#0]'),#0.1 #attrs['refrac']
            10.2:
            SORN_generate_output_K_WTA_partitioned(partition_size=7,
                                                   K='[0.02#1]'),
            10.3:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.4:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.5:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.6:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),
            10.7:
            SORN_slow_syn_simple(transmitter='GLU_cluster', strength='1.0'),
            10.8:
            SORN_generate_output_K_WTA_partitioned(
                partition_size=7, K='[0.02#1]', filter_temporal_output=False),

            # 12.1: SORN_WTA_iSTDP(eta_iSTDP='[0.00015#2]'),
            # 12.2: SORN_SN(syn_type='GABA'),
            #13.4: SORN_generate_output_K_WTA_partitioned(K='[0.12#4]'),
            #13.5: SORN_WTA_fast_syn(transmitter='GABA', strength='-[0.5#5]', so=so),#[0.1383#2]SORN_fast_syn
            #14: WTA_refrac(),
            #, filter_temporal_output=True
            15:
            SORN_buffer_variables(random_temporal_output_shift=False),
            18:
            WTA_refrac(decayfactor=0.5),
            20:
            SORN_IP_WTA(h_ip='lognormal_real_mean([0.02#1], [0.2944#2])',
                        eta_ip='[0.007#3]',
                        target_clip_min=None,
                        target_clip_max=None),  #-1.0 #1.0 #0.007
            21.1:
            SORN_STDP(transmitter='GLU',
                      eta_stdp='[0.00015#4]',
                      STDP_F={
                          -1: 0.2,
                          1: -1
                      }),  #, 0: 1 #[0.00015#7] #0.5, 0: 3.0
            21.2:
            SORN_STDP(transmitter='GLU_cluster',
                      eta_stdp='[0.00015#5]',
                      STDP_F={0: 2.0}),  #[0.00015#7]
            22:
            SORN_SN(syn_type='GLU', behaviour_norm_factor=1.0),
            23:
            SORN_SN(syn_type='GLU_cluster',
                    behaviour_norm_factor='[0.3#6]'),  #0.1
        })
    '''
        e_action = NeuronGroup(net=SORN, tag='E_action_{}'.format(timescale), size=maze.get_action_neuron_dimension(), behaviour={
                2: SORN_init_neuron_vars(timescale=timescale),
                3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution='uniform(0.1,0.11)', normalize=True, partition_compensation=True),  # 0.89 lognormal(0,[0.5#0])

                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_generate_output(init_TH='0.01'),
                19: SORN_buffer_variables(),

                20: SORN_Refractory_Analog(factor='0.7;+-50%'),
                21: SORN_STDP(eta_stdp='[0.0015#5]', STDP_F={-1: 1, 1:0}, weight_attr='W_temp'),#bigger #todo!!!!
                #22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=5.0),
                22: SORN_temporal_synapses(syn_type='GLU', behaviour_norm_factor=5.0),

                23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
                #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]')

                29: SORN_dopamine(),

                30: maze.get_action_neuron_behaviour()
            })


29: SORN_dopamine(),

30: maze.get_action_neuron_behaviour()
    '''
    '''
        e_reward = NeuronGroup(net=SORN, tag='E_reward_{}'.format(timescale), size=maze.get_reward_neuron_dimension(), behaviour={
                2: SORN_init_neuron_vars(timescale=timescale),
                3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution='lognormal(0,[0.95#0])', normalize=True, partition_compensation=True),

                9: maze.get_reward_neuron_behaviour(),

                12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so),
                18: SORN_generate_output(init_TH='0.01'),
                19: SORN_buffer_variables(),

                #20: SORN_Refractory(factor='0.5;+-50%'),
                21: SORN_STDP(eta_stdp='[0.00015#5]'),
                22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=0.1),

                #23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
                #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]')
            })
    '''
    '''
    e_punishment = NeuronGroup(net=SORN, tag='E_punishment_{}'.format(timescale), size=maze.get_punishment_neuron_dimension(), behaviour={
            2: SORN_init_neuron_vars(timescale=timescale),
            3: SORN_init_afferent_synapses(transmitter='GLU', density='full', distribution='lognormal(0,[0.95#0])', normalize=True, partition_compensation=True),

            9: maze.get_punishment_neuron_behaviour(),

            12: SORN_slow_syn(transmitter='GLU', strength='[0.1383#2]', so=so),
            18: SORN_generate_output(init_TH='0.01'),
            19: SORN_buffer_variables(),

            #20: SORN_Refractory(factor='0.5;+-50%'),
            21: SORN_STDP(eta_stdp='[0.00015#5]'), #todo!!!!
            22: SORN_SN(syn_type='GLU', clip_max=None, behaviour_norm_factor=0.1),

            #23: SORN_IP_TI(h_ip='0.04', eta_ip='0.001', integration_length='[15#18];+-50%', clip_min=None),
            #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]')
        })
    '''

    SynapseGroup(net=SORN, src=e_location, dst=e_location, tag='GLU,GLU_same')
    SynapseGroup(net=SORN,
                 src=e_location,
                 dst=e_location,
                 tag='GLU_cluster,syn')

    #SynapseGroup(net=SORN, src=e_vision, dst=e_location, tag='GLU', partition=True)
    #SynapseGroup(net=SORN, src=e_location, dst=e_action, tag='GLU', partition=True)

    #SynapseGroup(net=SORN, src=e_location, dst=e_reward, tag='GLU', partition=True)
    #SynapseGroup(net=SORN, src=e_reward, dst=e_location, tag='DOP+', partition=True)
    #SynapseGroup(net=SORN, src=e_reward, dst=e_action, tag='DOP+', partition=True)

    #SynapseGroup(net=SORN, src=e_location, dst=e_punishment, tag='GLU', partition=True)
    #SynapseGroup(net=SORN, src=e_punishment, dst=e_location, tag='DOP-', partition=True)
    #SynapseGroup(net=SORN, src=e_punishment, dst=e_action, tag='DOP-', partition=True)

    if __name__ == '__main__' and attrs.get('UI', False):
        e_location.color = (0, 0, 255, 255)
        #e_action.color = (255, 255, 0, 255)
        #e_vision.color = (0, 255, 255, 255)
        #e_reward.color = (100, 255, 100, 255)
        #e_punishment.color = (255, 100, 100, 255)

    SORN.set_marked_variables(attrs['ind'],
                              info=print_info,
                              storage_manager=sm)
    SORN.initialize(info=False)

    ###################################################################################################################

    if __name__ == '__main__' and attrs.get('UI', False):
        #default_modules.insert(0, maze_tab())
        #Network_UI(SORN, label='SORN UI default setup', storage_manager=sm, group_display_count=4, reduced_layout=True).show()
        Network_UI(
            SORN,
            modules=get_default_UI_modules(neuron_parameters=['activity']) +
            [maze_tab()],
            label='SORN UI K_WTA',
            storage_manager=sm,
            group_display_count=1,
            reduced_layout=False).show()

    return 0