How to use the nengo.Node 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 / arm_control / nengo_arm.py View on Github external
y3 = y2 - len1 * np.cos(angle_offset-angles[0] - angles[1])

        arm_func._nengo_html_ = '''
        <svg viewBox="0 0 100 100" height="100%" width="100%">
            <line style="stroke:black" y2="{y2}" x2="{x2}" y1="{y1}" x1="{x1}"></line>
            <line style="stroke:black" y2="{y3}" x2="{x3}" y1="{y2}" x1="{x2}"></line>
            <circle fill="black" stroke-width="1" stroke="black" r="1.5" cy="{y3}" cx="{x3}"></circle>
        </svg>
        '''.format(**locals())
        # end of visualization code ---------------------------------------------

        return data
    arm_node = nengo.Node(output=arm_func, size_in=2)

    # specify torque input to arm
    input_node = nengo.Node(output=[1, .1])

    # to send a target to an ensemble which then connections to the arm
    ens = nengo.Ensemble(n_neurons=500, dimensions=2, radius=np.sqrt(20))
    nengo.Connection(input_node, ens[:2]) # to send target info to ensemble

    # connect ens to arm
    nengo.Connection(ens, arm_node)#, function=some_function) 
    # --------------------------------------------------------

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()
github arnav-gudibande / nengopacman / pacman_world.py View on Github external
# The score is kept track of using an html rendering
            def score(t):
                for ghost in self.enemies:
                    self.update_ghost(ghost)
                total_score = sum([pacman.score for pacman in self.pacmen])

                if total_score == total:
                    self.reset(0, True)

                scores = ':'.join(['%d' % pacman.score for pacman in self.pacmen])

                html = '<h1>%s / %d</h1>' % (scores, total)
                html += '%1.3f seconds' % (t*10)
                html = '<center>%s</center>' % html
                score._nengo_html_ = html
            self.score = nengo.Node(score)
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
amp = 1. / max_rate
assert np.allclose(neuron_type.gain_bias(max_rate, intercept), (1, 1), atol=1e-2)

dt = 1e-3
model = nengo.Network(seed=97)
with model:
    input_images = nengo.Node(output=get_image, label='images')

    # --- make nonlinear layers
    layers = []
    for i, [W, b] in enumerate(zip(weights, biases)):
        n = b.size
        layer = nengo.Ensemble(n, 1, label='layer %d' % i, neuron_type=neuron_type,
                               max_rates=max_rate*np.ones(n),
                               intercepts=intercept*np.ones(n))
        bias = nengo.Node(output=b)
        nengo.Connection(bias, layer.neurons, transform=np.eye(n), synapse=0)

        if i == 0:
            nengo.Connection(input_images, layer.neurons,
                             transform=W.T, synapse=pstc)
        else:
            nengo.Connection(layers[-1].neurons, layer.neurons,
                             transform=W.T * amp / dt, synapse=pstc)

        layers.append(layer)

    # --- make cleanup
    class_layer = nengo.networks.EnsembleArray(Nclass, 10, label='class', radius=5)
    class_bias = nengo.Node(output=bc)
    nengo.Connection(class_bias, class_layer.input, synapse=0)
    nengo.Connection(layers[-1].neurons, class_layer.input,
github arnav-gudibande / nengopacman / netPlayer.py View on Github external
def __init__(self, **kwargs):

        super(self, NetPlayer).__init__(N, **kwargs)

        self.player_move = []

        self.move = nengo.Node(move, size_in = 2, size_out = 2)
        self.food = nengo.Node(food, size_in = 2, size_out = 2)
        self.obstacles = nengo.Node(obstacles, size_in = 2, size_out = 2)

        for i in xrange(N):
            self.player_move.append()
github SpiNNakerManchester / SpiNNakerGraphFrontEnd / spinnaker_graph_front_end / examples / nengo / nengo_implicit_interfaces / nengo_output_node.py View on Github external
import nengo
from spinn_utilities.overrides import overrides
from spinnaker_graph_front_end.examples.nengo.nengo_implicit_interfaces.\
    nengo_live_output_interface import \
    NengoLiveOutputInterface


class NengoOutputNode(nengo.Node, NengoLiveOutputInterface):

    def __init__(self, spinnaker_vertex):
        NengoLiveOutputInterface.__init__(self)
        self._spinnaker_vertex = spinnaker_vertex

    @property
    def size_in(self):
        return self._spinnaker_vertex.size_in

    @overrides(NengoLiveOutputInterface.output)
    def output(self, t, x):
        """ enforced by the nengo duck typing

        :param t: 
        :param x:
        :return: 
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
nengo.Connection(input_images, layer.neurons,
                             transform=W.T, synapse=pstc)
        else:
            nengo.Connection(layers[-1].neurons, layer.neurons,
                             transform=W.T * amp / dt, synapse=pstc)

        layers.append(layer)

    # --- make cleanup
    class_layer = nengo.networks.EnsembleArray(Nclass, 10, label='class', radius=5)
    class_bias = nengo.Node(output=bc)
    nengo.Connection(class_bias, class_layer.input, synapse=0)
    nengo.Connection(layers[-1].neurons, class_layer.input,
                     transform=Wc.T * amp / dt, synapse=pstc)

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

    # --- make centroid classifier node
    def centroid_test_fn(t, x):
        i = int(t / presentation_time)
        d = ((x - code_means)**2).sum(1)
        return test_labels[i] == labels[np.argmin(d)]

    centroid_test = nengo.Node(centroid_test_fn, size_in=layers[-1].n_neurons)
    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)
github adityagilra / FOLLOW / input_ff_rec_transform_nengo_ocl.py View on Github external
default_size_out=N, default_dt = dt,
                                            dist=nengo.dists.Gaussian(0 if (errNoiseMean is None) else errNoiseMean, errNoise),
                                            seed=seedR1) )
                nengo.Connection(errNoiseNode,error)

            ###
            ### Add the relevant pre signal to the error ensemble ###
            ###
            if recurrentLearning:                           # L2 rec learning
                if copycatLayer:
                    # Error = post - desired_output
                    rateEvolve2error = nengo.Connection(expectOut,error,synapse=tau,transform=-np.eye(N))
                                                                # - desired output here (post above)
                                                                # tau-filtered expectOut must be compared to tau-filtered ratorOut (post above)
                else:
                    rateEvolve = nengo.Node(rateEvolveFn)
                    # Error = post - desired_output
                    rateEvolve2error = nengo.Connection(rateEvolve,error,synapse=tau,transform=-np.eye(N))
                    #rateEvolve2error = nengo.Connection(rateEvolve,error,synapse=None,transform=-np.eye(N))
                                                                # - desired output here (post above)
                                                                # unfiltered non-spiking reference is compared to tau-filtered spiking ratorOut (post above)
                plasticConnEE = EtoE
                rateEvolve_probe = nengo.Probe(rateEvolve2error, 'output')
                                                                # save the filtered/unfiltered reference as this is the 'actual' reference

            ###
            ### Add the exc learning rules to the connection, and the error ensemble to the learning rule ###
            ###
            EtoERulesDict = { 'PES' : nengo.PES(learning_rate=PES_learning_rate_rec,
                                            pre_tau=tau) }
            plasticConnEE.learning_rule_type = EtoERulesDict
            #plasticConnEE.learning_rule['PES'].learning_rate=0
github adityagilra / FOLLOW / input_ff_rec_robot_nengo_directu_ocl.py View on Github external
#np.random.seed(1)
                if not errorGainProportion: # default error feedback
                    errorFeedbackConn = nengo.Connection(errorOff,ratorOut,\
                            synapse=errorFeedbackTau,\
                            transform=-errorFeedbackGain)#*(np.random.uniform(-0.1,0.1,size=(N,N))+np.eye(N)))
                else:
                    # obsolete
                    ## calculate the gain from the filtered mean(abs(error))
                    #autoGainControl = nengo.Node(size_in=1,size_out=1,\
                    #                           output = lambda timeval,abserr_filt: \
                    #                                   -errorFeedbackGain*abserr_filt\
                    #                                   /errorGainProportionTau/reprRadiusErr)
                    #nengo.Connection(error,autoGainControl,synapse=errorGainProportionTau,\
                    #                           function = lambda err: np.mean(np.abs(err)))
                    # instead of the above gain[err(t)], I just have gain(t) 
                    autoGainControl = nengo.Node(size_in=1,size_out=1,\
                                                    output = lambda timeval,x: \
                                                        -errorFeedbackGain*(2.*Tmax-timeval)/2./Tmax)
                    # multiply error with this calculated gain
                    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
        
            ###
github hunse / nef-rbm / auto / run_lif_nocode.py View on Github external
i = int(t / presentation_time)
        d = ((x - code_means)**2).sum(1)
        return test_labels[i] == labels[np.argmin(d)]

    centroid_test = nengo.Node(centroid_test_fn, size_in=layers[-1].n_neurons)
    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)