Exemplo n.º 1
0
def buildModel(ind):
    # model
    model = nef.Network('model')

    # input
    inputs = model.add(routing.twoDimsRouter('inputs')); # TODO: general IO dimensions 

    # output
    model.make('output', neurons=OUTdim, dimensions=OUTdim, mode='spike',
        max_rate= (mr,mr), intercept=(ii,ii),encoders=[[1],[1]],decoder_sign=+1);

    # spiking ANN
    model.make('ANN', neurons=N, dimensions=INdim, mode='spike',
        encoders = ([1,0], [0,1]), intercept= (ii, ii), max_rate = (mr,mr))

    # wire it:
    model.connect('ANN','ANN',weight_func=setReccurent);    # recurrent conencitons
    model.connect('ANN','output',weight_func=setOutW);      # ANN to output
    # for each input, make one neuron and connect it
    for d in range(INdim):
        # choose factory for input neurons:
        #inFactory.makeLinearNeuron(mr,d,model,'spike');
        #inFactory.makeBioLinearNeuron(mr,d,model,'spike');
        inFactory.makeSigmoidNeuron(mr, d, model,'spike');
        #inFactory.makeBioSigmoidNeuron(mr,d,model,'spike');
     
        # connect shared input to input neuron and neuron to ANN with weights
        actualIn=d;
        model.connect(inputs.getOrigin('out'), 'in_neuron_%d'%d, index_pre=d)
        model.connect('in_neuron_%d'%d, 'ANN',weight_func=setInW)

    return model;
Exemplo n.º 2
0
# input
model.make('input', neurons=INdim, dimensions=INdim, mode='direct',
    max_rate= (mr,mr), intercept=(ii,ii), encoders=[[1,0],[0,1]])

# spiking ANN
model.make('ANN', neurons=N, dimensions=INdim, mode='rate',
    encoders = ([1,0], [0,1]), intercept= (ii, ii), max_rate = (mr,mr))



# for each input, make one neuron and connect it
for d in range(INdim):
    
    #inFactory.makeLinearNeuron(100,d,model,'spike');
    #inFactory.makeBioLinearNeuron(100,d,model,'spike');
    inFactory.makeSigmoidNeuron(100, d, model,'spike');
    #inFactory.makeBioSigmoidNeuron(100,d,model,'spike');
    model.connect('input', 'in_neuron_%d'%d, index_pre=d)
    if d==1:
        model.connect('in_neuron_%d'%d, 'ANN',weight_func=ident) # todo better funcitons here
    else:
        model.connect('in_neuron_%d'%d, 'ANN',weight_func=ident)

net.add(model.network); 

# wiring
net.connect(generator,'model.input',weight=1)           # feed signal to both, plant and model
net.add_to_nengo();