How to use the nengo.Probe function in nengo

To help you get started, we’ve selected a few nengo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
nengo.Connection(autoGainControl,errorGain[-1],synapse=0.001)
                    # feedback the error multiplied by the calculated gain
                    errorFeedbackConn = nengo.Connection(\
                                        errorGain,ratorOut,synapse=errorFeedbackTau)
                if errorGainDecay and spikingNeurons: # decaying gain, works only if error is computed from spiking neurons
                    errorFeedbackConn.learning_rule_type = \
                        {'wtDecayRule':nengo.PES(decay_rate_x_dt=errorGainDecayRate*dt)}
                                                            # PES with error unconnected, so only decay
        
            ###
            ### error and weight probes ###
            ###
            errorOn_p = nengo.Probe(error, synapse=None, label='errorOn')
            error_p = nengo.Probe(errorWt, synapse=None, label='error')
            if saveWeightsEvolution:
                learnedWeightsProbe = nengo.Probe(\
                            plasticConnEE,'weights',sample_every=weightdt,label='EEweights')
                # feedforward weights probe
                learnedInWeightsProbe = nengo.Probe(\
                            InEtoE,'weights',sample_every=weightdt,label='InEEweights')

    if initLearned:
        if not plastDecoders:
            # Easier to just use EtoEfake with initLearned.
            # Else even if I set the ensemble properties perfectly (manually, or setting seed of the Ensemble),
            #  I will still need to conect the Learning Rule to the new connection, etc.
            if OCL: sim = nengo_ocl.Simulator(mainModel,dt)
            else: sim = nengo.Simulator(mainModel,dt)
            
            Eencoders = sim.data[ratorOut].encoders
            Eintercepts = sim.data[ratorOut].intercepts
            Emax_rates = sim.data[ratorOut].max_rates
github studywolf / blog / Nengo scripting / Nengo 2 / discrete_filter / point_attractor.py View on Github external
time = 5  # number of seconds to run simulation
    alphas = [10.0, 100.0, 1000.0]
    for ii, alpha in enumerate(alphas):
        probe_results = []
        model = nengo.Network()
        beta = alpha / 4.0
        for option in [True, False]:
            with model:
                def goal_func(t):
                    return float(int(t)) / time * 2 - 1
                goal = nengo.Node(output=goal_func)
                pa = generate(n_neurons=1000, analog=option,
                              alpha=alpha, beta=beta, dt=dt)
                nengo.Connection(goal, pa.input, synapse=None)

                probe_ans = nengo.Probe(goal)
                probe = nengo.Probe(pa.output, synapse=.01)

            sim = nengo.Simulator(model, dt=dt)
            sim.run(time)
            probe_results.append(np.copy(sim.data[probe]))

        plt.subplot(len(alphas), 1, ii+1)
        lines_c = plt.plot(sim.trange(), probe_results[0], 'b')
        lines_d = plt.plot(sim.trange(), probe_results[1], 'g')
        line_ans = plt.plot(sim.trange(), sim.data[probe_ans][:, 0], 'r--')
        plt.legend([lines_c[0], lines_d[0], line_ans],
                   ['continuous', 'discrete', 'desired'])
        plt.title('alpha=%.2f, beta=%.2f' % (alpha, beta))

    plt.tight_layout()
    plt.show()
github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
EtoEexpect = nengo.Connection(expectOut.neurons, expectOut.neurons,
                                                            transform=Wdyn2, synapse=tau) # synapse is tau_syn for filtering
                else:
                    ## the system didn't learn in this case
                    ##  possibly the problem is ensemble to ensemble here but neurons to neurons for InEtoE & EtoE?
                    InEtoEexpect = nengo.Connection(ratorIn, expectOut, synapse=tau)
                                                                    # ACHTUNG! the ff transform if not unity must be set here...
                    EtoEexpect = nengo.Connection(expectOut, expectOut,
                                                    function=Wdesired, synapse=tau) # synapse is tau_syn for filtering
                if trialClamp:
                    nengo.Connection(endTrialClamp,expectOut.neurons,synapse=1e-3)
                                                                        # clamp expectOut like ratorIn and ratorOut above
                                                                        # fast synapse for fast-reacting clamp
                expectOut_probe = nengo.Probe(expectOut, synapse=tau)
                if testLearned and saveSpikes:
                    expectOut_spikesOut = nengo.Probe(expectOut.neurons, 'output')
            ###
            ### error ensemble, could be with error averaging, gets post connection ###
            ###
            if spikingNeurons:
                error = nengo.Ensemble(Nerror, dimensions=N, radius=reprRadiusErr, label='error')
            else:
                error = nengo.Node( size_in=N, output = lambda timeval,err: err)
                if trialClamp:
                    errorOff = nengo.Node( size_in=N, output = lambda timeval,err: \
                                                err if (Tperiod
github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
output = lambda timeval,x: x[:N]*x[-1])
                    nengo.Connection(errorOff,errorGain[:N],synapse=0.001)
                    nengo.Connection(autoGainControl,errorGain[-1],synapse=0.001)
                    # feedback the error multiplied by the calculated gain
                    errorFeedbackConn = nengo.Connection(\
                                        errorGain,ratorOut,synapse=errorFeedbackTau)
                if errorGainDecay and spikingNeurons: # decaying gain, works only if error is computed from spiking neurons
                    errorFeedbackConn.learning_rule_type = \
                        {'wtDecayRule':nengo.PES(decay_rate_x_dt=errorGainDecayRate*dt)}
                                                            # PES with error unconnected, so only decay
        
            ###
            ### error and weight probes ###
            ###
            errorOn_p = nengo.Probe(error, synapse=None, label='errorOn')
            error_p = nengo.Probe(errorWt, synapse=None, label='error')
            if saveWeightsEvolution:
                learnedWeightsProbe = nengo.Probe(\
                            plasticConnEE,'weights',sample_every=weightdt,label='EEweights')
                # feedforward weights probe
                learnedInWeightsProbe = nengo.Probe(\
                            InEtoE,'weights',sample_every=weightdt,label='InEEweights')

    if initLearned:
        if not plastDecoders:
            # Easier to just use EtoEfake with initLearned.
            # Else even if I set the ensemble properties perfectly (manually, or setting seed of the Ensemble),
            #  I will still need to conect the Learning Rule to the new connection, etc.
            if OCL: sim = nengo_ocl.Simulator(mainModel,dt)
            else: sim = nengo.Simulator(mainModel,dt)
            
            Eencoders = sim.data[ratorOut].encoders
github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
errorGain = nengo.Node(size_in=N+1,size_out=N,
                                        output = lambda timeval,x: x[:N]*x[-1])
                    nengo.Connection(errorOff,errorGain[:N],synapse=0.001)
                    nengo.Connection(autoGainControl,errorGain[-1],synapse=0.001)
                    # feedback the error multiplied by the calculated gain
                    errorFeedbackConn = nengo.Connection(\
                                        errorGain,ratorOut,synapse=errorFeedbackTau)
                if errorGainDecay and spikingNeurons: # decaying gain, works only if error is computed from spiking neurons
                    errorFeedbackConn.learning_rule_type = \
                        {'wtDecayRule':nengo.PES(decay_rate_x_dt=errorGainDecayRate*dt)}
                                                            # PES with error unconnected, so only decay
        
            ###
            ### error and weight probes ###
            ###
            errorOn_p = nengo.Probe(error, synapse=None, label='errorOn')
            error_p = nengo.Probe(errorWt, synapse=None, label='error')
            if saveWeightsEvolution:
                learnedWeightsProbe = nengo.Probe(\
                            plasticConnEE,'weights',sample_every=weightdt,label='EEweights')
                # feedforward weights probe
                learnedInWeightsProbe = nengo.Probe(\
                            InEtoE,'weights',sample_every=weightdt,label='InEEweights')

    if initLearned:
        if not plastDecoders:
            # Easier to just use EtoEfake with initLearned.
            # Else even if I set the ensemble properties perfectly (manually, or setting seed of the Ensemble),
            #  I will still need to conect the Learning Rule to the new connection, etc.
            if OCL: sim = nengo_ocl.Simulator(mainModel,dt)
            else: sim = nengo.Simulator(mainModel,dt)
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
# --- make dot classifier node
    def dot_test_fn(t, x):
        i = int(t / presentation_time)
        # d = np.dot(code_means, x)
        d = np.dot(code_means - code_mean, x - code_mean)
        return test_labels[i] == labels[np.argmax(d)]

    dot_test = nengo.Node(dot_test_fn, size_in=layers[-1].n_neurons)
    nengo.Connection(layers[-1].neurons, dot_test,
                     transform=amp / dt, synapse=pstc)

    # --- make probes
    probe_layers = [nengo.Probe(layer, 'spikes') for layer in layers]
    probe_class = nengo.Probe(class_layer.output, synapse=0.03)
    probe_test = nengo.Probe(test, synapse=0.01)
    probe_centroid = nengo.Probe(centroid_test, synapse=0.01)
    probe_dot = nengo.Probe(dot_test, synapse=0.01)


# --- simulation
sim = nengo.Simulator(model, dt=dt)
sim.run(100., progress=True)
# sim.run(5.)
# sim.run(1., progress=True)

t = sim.trange()

# --- plots
from nengo.utils.matplotlib import rasterplot

def plot_bars():
    ylim = plt.ylim()
github hunse / nef-rbm / sigmoid-rbm / run_dbn.py View on Github external
nengo.Connection(code_bias, code_layer.input, synapse=0)
    nengo.Connection(output, code_layer.input, transform=W.T, synapse=pstc)

    # --- make classifier layer
    class_layer = nengo.networks.EnsembleArray(10, 10, label='class', radius=20)
    class_bias = nengo.Node(output=bc)
    nengo.Connection(class_bias, class_layer.input, synapse=0)
    nengo.Connection(code_layer.output, class_layer.input,
                     transform=Wc.T, synapse=pstc)

    test = nengo.Node(output=test_dots, size_in=n_labels)
    nengo.Connection(class_layer.output, test)

    probe_code = nengo.Probe(code_layer.output, synapse=0.03)
    probe_class = nengo.Probe(class_layer.output, synapse=0.03)
    probe_test = nengo.Probe(test, synapse=0.01)


# --- simulation
# rundata_file = 'rundata.npz'
# if not os.path.exists(rundata_file):
if 1:
    sim = nengo.Simulator(model)
    # sim.run(1.)
    # sim.run(5.)
    sim.run(10.)

    t = sim.trange()
    x = sim.data[probe_code]
    y = sim.data[probe_class]
    z = sim.data[probe_test]
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
def dot_test_fn(t, x):
        i = int(t / presentation_time)
        # d = np.dot(code_means, x)
        d = np.dot(code_means - code_mean, x - code_mean)
        return test_labels[i] == labels[np.argmax(d)]

    dot_test = nengo.Node(dot_test_fn, size_in=layers[-1].n_neurons)
    nengo.Connection(layers[-1].neurons, dot_test,
                     transform=amp / dt, synapse=pstc)

    # --- make probes
    probe_layers = [nengo.Probe(layer, 'spikes') for layer in layers]
    probe_class = nengo.Probe(class_layer.output, synapse=0.03)
    probe_test = nengo.Probe(test, synapse=0.01)
    probe_centroid = nengo.Probe(centroid_test, synapse=0.01)
    probe_dot = nengo.Probe(dot_test, synapse=0.01)


# --- simulation
sim = nengo.Simulator(model, dt=dt)
sim.run(100., progress=True)
# sim.run(5.)
# sim.run(1., progress=True)

t = sim.trange()

# --- plots
from nengo.utils.matplotlib import rasterplot

def plot_bars():
    ylim = plt.ylim()
    for x in np.arange(0, t[-1], presentation_time):
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
nengo.Connection(layers[-1].neurons, centroid_test,
                     transform=amp / dt, synapse=pstc)

    # --- make dot classifier node
    def dot_test_fn(t, x):
        i = int(t / presentation_time)
        # d = np.dot(code_means, x)
        d = np.dot(code_means - code_mean, x - code_mean)
        return test_labels[i] == labels[np.argmax(d)]

    dot_test = nengo.Node(dot_test_fn, size_in=layers[-1].n_neurons)
    nengo.Connection(layers[-1].neurons, dot_test,
                     transform=amp / dt, synapse=pstc)

    # --- make probes
    probe_layers = [nengo.Probe(layer, 'spikes') for layer in layers]
    probe_class = nengo.Probe(class_layer.output, synapse=0.03)
    probe_test = nengo.Probe(test, synapse=0.01)
    probe_centroid = nengo.Probe(centroid_test, synapse=0.01)
    probe_dot = nengo.Probe(dot_test, synapse=0.01)


# --- simulation
sim = nengo.Simulator(model, dt=dt)
sim.run(100., progress=True)
# sim.run(5.)
# sim.run(1., progress=True)

t = sim.trange()

# --- plots
from nengo.utils.matplotlib import rasterplot
github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
InEtoEexpect = nengo.Connection(ratorIn.neurons, expectOut.neurons,
                                                            transform=Wdyn2, synapse=tau)
                    EtoEexpect = nengo.Connection(expectOut.neurons, expectOut.neurons,
                                                            transform=Wdyn2, synapse=tau) # synapse is tau_syn for filtering
                else:
                    ## the system didn't learn in this case
                    ##  possibly the problem is ensemble to ensemble here but neurons to neurons for InEtoE & EtoE?
                    InEtoEexpect = nengo.Connection(ratorIn, expectOut, synapse=tau)
                                                                    # ACHTUNG! the ff transform if not unity must be set here...
                    EtoEexpect = nengo.Connection(expectOut, expectOut,
                                                    function=Wdesired, synapse=tau) # synapse is tau_syn for filtering
                if trialClamp:
                    nengo.Connection(endTrialClamp,expectOut.neurons,synapse=1e-3)
                                                                        # clamp expectOut like ratorIn and ratorOut above
                                                                        # fast synapse for fast-reacting clamp
                expectOut_probe = nengo.Probe(expectOut, synapse=tau)
                if testLearned and saveSpikes:
                    expectOut_spikesOut = nengo.Probe(expectOut.neurons, 'output')
            ###
            ### error ensemble, could be with error averaging, gets post connection ###
            ###
            if spikingNeurons:
                error = nengo.Ensemble(Nerror, dimensions=N, radius=reprRadiusErr, label='error')
            else:
                error = nengo.Node( size_in=N, output = lambda timeval,err: err)
                if trialClamp:
                    errorOff = nengo.Node( size_in=N, output = lambda timeval,err: \
                                                err if (Tperiod