How to use the nengo.Simulator 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 studywolf / blog / Nengo scripting / Nengo 2 / arm_control / nengo_arm.py View on Github external
if run_in_GUI:
    # to run in GUI, comment out next 4 lines for running without GUI
    import nengo_gui
    nengo_gui.GUI(model=model, filename=__file__, locals=locals(), 
                  interactive=False, allow_file_change=False).start()
    import sys
    sys.exit()
else:  
    # to run in command line
    with model:    
        probe_input = nengo.Probe(input_node)
        probe_arm = nengo.Probe(arm_node[arm.DOF*2])
        
    print 'building model...'
    sim = nengo.Simulator(model, dt=.001)
    print 'build complete.'

    sim.run(10)

    t = sim.trange()
    x = sim.data[probe_arm]
    y = sim.data[probe_arm]

    # plot collected data
    import matplotlib.pyplot as plt

    plt.subplot(311)
    plt.plot(t, x)
    plt.xlabel('time')
    plt.ylabel('probe_arm0')
github studywolf / blog / Nengo scripting / arm_control / nengo_arm.py View on Github external
if run_in_GUI:
    # to run in GUI, comment out next 4 lines for running without GUI
    import nengo_gui
    nengo_gui.GUI(model=model, filename=__file__, locals=locals(), 
                  interactive=False, allow_file_change=False).start()
    import sys
    sys.exit()
else:  
    # to run in command line
    with model:    
        probe_input = nengo.Probe(input_node)
        probe_arm = nengo.Probe(arm_node[arm.DOF*2])
        
    print 'building model...'
    sim = nengo.Simulator(model, dt=.001)
    print 'build complete.'

    sim.run(10)

    t = sim.trange()
    x = sim.data[probe_arm]
    y = sim.data[probe_arm]

    # plot collected data
    import matplotlib.pyplot as plt

    plt.subplot(311)
    plt.plot(t, x)
    plt.xlabel('time')
    plt.ylabel('probe_arm0')
github simondlevy / MulticopterSim / Source / MulticopterSim / hackflight / python / nengo_pidcontrol.py View on Github external
def start(self):

        self.sim = nengo.Simulator(self.model, progress_bar=False)
github studywolf / blog / Nengo scripting / Nengo 2 / discrete_filter / point_attractor.py View on Github external
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 simondlevy / MulticopterSim / Extras / nengo / takeoff.py View on Github external
from time import sleep
from sys import stdout
from altitude_hold import buildpid, runpid, startcopter

# Simulator params
SIM_TIME = 0.001

if __name__ == '__main__':

    # initial conditions
    z = 0
    u = 0

    model, pid = buildpid()

    sim = nengo.Simulator(model, progress_bar=False)  

    copter = startcopter()

    with model:

        stdout.write('Hit Play in simulator ... ')
        stdout.flush()

        # Loop until user hits the stop button
        while  True:

            # Run the PID controller
            runpid(copter, pid)

            # Update the simulator
            sim.run(SIM_TIME)
github adityagilra / FOLLOW / input_rec_transform_nengo_plot.py View on Github external
##  as they could be ambiguous from name of the file
    import nengo
    Nexc, N, reprRadius, nrngain = 3000, 2, 5, 2
    seedR0, seedR2 = 2, 4
    gain_bias_set = True
    #biaslow, biashigh = 1 - nrngain, 1 + nrngain
    biaslow, biashigh = -nrngain, nrngain
    print('building model')
    mainModel = nengo.Network(label="Single layer network", seed=seedR0)
    with mainModel:
        ratorOut = nengo.Ensemble( Nexc, dimensions=N, radius=reprRadius,
                            neuron_type=nengo.neurons.LIF(),
                            bias=nengo.dists.Uniform(biaslow,biashigh), gain=np.ones(Nexc)*nrngain, 
                            #max_rates=nengo.dists.Uniform(200, 400),
                            noise=None, seed=seedR2, label='ratorOut' )
    sim = nengo.Simulator(mainModel,dt)
    biases = sim.data[ratorOut].bias
    zerofiringbiases = biases[zeroidxs]
    gains = sim.data[ratorOut].gain
    zerofiringgains = gains[zeroidxs]
    
    if gain_bias_set: histrange, biasrange = 5, 5
    else: histrange, biasrange = 500, 100
    fig = plt.figure(facecolor='w')
    ax1 = plt.subplot(231)
    vals,_,_ = ax1.hist(gains,bins=50,range=(0,histrange),color='k',histtype='step')
    ax1.set_xlabel('all gains')
    ax2 = plt.subplot(232)
    vals,_,_ = ax2.hist(biases,bins=50,range=(-histrange,biasrange),color='k',histtype='step')
    ax2.set_xlabel('all biases')
    ax3 = plt.subplot(234)
    vals,_,_ = ax3.hist(zerofiringgains,bins=50,range=(0,histrange),color='k',histtype='step')
github adityagilra / FOLLOW / input_ff_rec_robot_nengo_directu_ocl.py View on Github external
## if not initLearned, we don't care about matching weights to ideal
            ## this reduces a large set of connections, esp if Nexc is large
            #model.connections.remove(EtoEfake)
        else:
            EtoE.function = Wdesired
            EtoE.transform = np.array(1.0)
        

    #################################
    ### Build Nengo network
    #################################

    if OCL:
        sim = nengo_ocl.Simulator(mainModel,dt)
    else:
        sim = nengo.Simulator(mainModel,dt)
    Eencoders = sim.data[ratorOut].encoders
    
    #################################
    ### load previously learned weights, if requested and file exists
    #################################
    if errorLearning and (continueLearning or testLearned) and isfile(weightsLoadFileName):
        print('loading previously learned weights from',weightsLoadFileName)
        with contextlib.closing(
                shelve.open(weightsLoadFileName, 'r', protocol=-1)
                ) as weights_dict:
            #sim.data[plasticConnEE].weights = weights_dict['learnedWeights']       # can't be set, only read
            sim.signals[ sim.model.sig[plasticConnEE]['weights'] ] \
                                = weights_dict['learnedWeights']                    # can be set if weights/decoders are plastic
            sim.signals[ sim.model.sig[InEtoE]['weights'] ] \
                                = weights_dict['learnedInWeights']                  # can be set if weights/decoders are plastic
    else:
github BINDS-LAB-UMASS / bindsnet_experiments / experiments / benchmark / benchmark.py View on Github external
def Nengo(n_neurons, time):
    t0 = t()
    t1 = t()

    model = nengo.Network()
    with model:
        X = nengo.Ensemble(n_neurons, dimensions=1, neuron_type=nengo.LIF())
        Y = nengo.Ensemble(n_neurons, dimensions=2, neuron_type=nengo.LIF())
        nengo.Connection(X, Y, transform=np.random.rand(n_neurons, n_neurons))

    with nengo.Simulator(model) as sim:
        sim.run(time / 1000) 

    return t() - t0, t() - t1
github SpiNNakerManchester / SpiNNakerGraphFrontEnd / spinnaker_graph_front_end / examples / nengo / overridden_mapping_algorithms / nengo_create_host_simulator.py View on Github external
def __call__(self, host_network, machine_time_step_in_seconds):

        # Build the host simulator
        host_sim = nengo.Simulator(
            host_network, dt=machine_time_step_in_seconds)
        return host_sim
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
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):
        plt.plot([x, x], ylim, 'k--')

inds = slice(0, int(t[-1]/presentation_time) + 1)
images = test_images[inds]