nengo.Network 
A network contains ensembles, nodes, connections, and other networks. 
nengo.Ensemble 
A group of neurons that collectively represent a vector. 
nengo.ensemble.Neurons 
An interface for making connections directly to an ensemble’s neurons. 
nengo.Node 
Provide nonneural inputs to Nengo objects and process outputs. 
nengo.Connection 
Connects two objects together. 
nengo.connection.LearningRule 
An interface for making connections to a learning rule. 
nengo.Probe 
A probe is an object that collects data from the simulation. 
nengo.
Network
(label=None, seed=None, add_to_container=None)[source]¶A network contains ensembles, nodes, connections, and other networks.
A network is primarily used for grouping together related objects and connections for visualization purposes. However, you can also use networks as a nice way to reuse network creation code.
To group together related objects that you do not need to reuse,
you can create a new Network
and add objects in a with
block.
For example:
network = nengo.Network()
with network:
with nengo.Network(label="Vision"):
v1 = nengo.Ensemble(nengo.LIF(100), dimensions=2)
with nengo.Network(label="Motor"):
sma = nengo.Ensemble(nengo.LIF(100), dimensions=2)
nengo.Connection(v1, sma)
To reuse a group of related objects, you can create a new subclass
of Network
, and add objects in the __init__
method.
For example:
class OcularDominance(nengo.Network):
def __init__(self):
self.column = nengo.Ensemble(nengo.LIF(100), dimensions=2)
network = nengo.Network()
with network:
left_eye = OcularDominance()
right_eye = OcularDominance()
nengo.Connection(left_eye.column, right_eye.column)
Parameters: 


Attributes: 

all_objects
¶(list) All objects in this network and its subnetworks.
all_ensembles
¶(list) All ensembles in this network and its subnetworks.
all_nodes
¶(list) All nodes in this network and its subnetworks.
all_networks
¶(list) All networks in this network and its subnetworks.
all_connections
¶(list) All connections in this network and its subnetworks.
all_probes
¶(list) All probes in this network and its subnetworks.
n_neurons
¶(int) Number of neurons in this network, including subnetworks.
nengo.
Ensemble
(n_neurons, dimensions, radius=Default, encoders=Default, intercepts=Default, max_rates=Default, eval_points=Default, n_eval_points=Default, neuron_type=Default, gain=Default, bias=Default, noise=Default, normalize_encoders=Default, label=Default, seed=Default)[source]¶A group of neurons that collectively represent a vector.
Parameters: 


Attributes: 

neurons
¶A direct interface to the neurons in the ensemble.
size_in
¶The dimensionality of the ensemble.
size_out
¶The dimensionality of the ensemble.
nengo.ensemble.
Neurons
(ensemble)[source]¶An interface for making connections directly to an ensemble’s neurons.
This should only ever be accessed through the neurons
attribute of an
ensemble, as a way to signal to Connection
that the connection
should be made directly to the neurons rather than to the ensemble’s
decoded value, e.g.:
nengo.Connection(a.neurons, b.neurons)
ensemble
¶(Ensemble) The ensemble these neurons are part of.
probeable
¶(tuple) Signals that can be probed in the neuron population.
size_in
¶(int) The number of neurons in the population.
size_out
¶(int) The number of neurons in the population.
nengo.
Node
(output=Default, size_in=Default, size_out=Default, label=Default, seed=Default)[source]¶Provide nonneural inputs to Nengo objects and process outputs.
Nodes can accept input, and perform arbitrary computations for the purpose of controlling a Nengo simulation. Nodes are typically not part of a brain model per se, but serve to summarize the assumptions being made about sensory data or other environment variables that cannot be generated by a brain model alone.
Nodes can also be used to test models by providing specific input signals
to parts of the model, and can simplify the input/output interface of a
Network
when used as a relay to/from its internal
ensembles (see EnsembleArray
for an example).
Parameters: 


Attributes: 

nengo.
Connection
(pre, post, synapse=Default, function=Default, transform=Default, solver=Default, learning_rule_type=Default, eval_points=Default, scale_eval_points=Default, label=Default, seed=Default, modulatory=Unconfigurable)[source]¶Connects two objects together.
The connection between the two object is unidirectional,
transmitting information from the first argument, pre
,
to the second argument, post
.
Almost any Nengo object can act as the pre or post side of a connection. Additionally, you can use Python slice syntax to access only some of the dimensions of the pre or post object.
For example, if node
has size_out=2
and ensemble
has
size_in=1
, we could not create the following connection:
nengo.Connection(node, ensemble)
But, we could create either of these two connections:
nengo.Connection(node[0], ensemble)
nengo.Connection(node[1], ensemble)
Parameters: 


Attributes: 

learning_rule
¶(LearningRule or iterable) Connectable learning rule object(s).
size_in
¶(int) The number of output dimensions of the pre object.
Also the input size of the function, if one is specified.
size_mid
¶(int) The number of output dimensions of the function, if specified.
If the function is not specified, then size_in == size_mid
.
size_out
¶(int) The number of input dimensions of the post object.
Also the number of output dimensions of the transform.
nengo.connection.
LearningRule
(connection, learning_rule_type)[source]¶An interface for making connections to a learning rule.
Connections to a learning rule are to allow elements of the network to affect the learning rule. For example, learning rules that use error information can obtain that information through a connection.
Learning rule objects should only ever be accessed through the
learning_rule
attribute of a connection.
connection
¶(Connection) The connection modified by the learning rule.
modifies
¶(str) The variable modified by the learning rule.
probeable
¶(tuple) Signals that can be probed in the learning rule.
size_out
¶(int) Cannot connect from learning rules, so always 0.
nengo.
Probe
(target, attr=None, sample_every=Default, synapse=Default, solver=Default, label=Default, seed=Default)[source]¶A probe is an object that collects data from the simulation.
This is to be used in any situation where you wish to gather simulation data (spike data, represented values, neuron voltages, etc.) for analysis.
Probes do not directly affect the simulation.
All Nengo objects can be probed (except Probes themselves).
Each object has different attributes that can be probed.
To see what is probeable for each object, print its
probeable
attribute.
>>> with nengo.Network():
... ens = nengo.Ensemble(10, 1)
>>> print(ens.probeable)
['decoded_output', 'input']
Parameters: 


Attributes: 

obj
¶(Nengo object) The underlying Nengo object target.
size_in
¶(int) Dimensionality of the probed signal.
size_out
¶(int) Cannot connect from probes, so always 0.
slice
¶(slice) The slice associated with the Nengo object target.
nengo.dists.Distribution 
A base class for probability distributions. 
nengo.dists.get_samples 
Convenience function to sample a distribution or return samples. 
nengo.dists.Uniform 
A uniform distribution. 
nengo.dists.Gaussian 
A Gaussian distribution. 
nengo.dists.Exponential 
An exponential distribution (optionally with high values clipped). 
nengo.dists.UniformHypersphere 
Uniform distribution on or in an ndimensional unit hypersphere. 
nengo.dists.Choice 
Discrete distribution across a set of possible values. 
nengo.dists.Samples 
A set of samples. 
nengo.dists.PDF 
An arbitrary distribution from a PDF. 
nengo.dists.SqrtBeta 
Distribution of the square root of a Beta distributed random variable. 
nengo.dists.SubvectorLength 
Distribution of the length of a subvectors of a unit vector. 
nengo.dists.CosineSimilarity 
Distribution of the cosine of the angle between two random vectors. 
nengo.dists.
Distribution
[source]¶A base class for probability distributions.
The only thing that a probabilities distribution need to define is a
sample
method. This base class ensures that all distributions
accept the same arguments for the sample function.
sample
(n, d=None, rng=np.random)[source]¶Samples the distribution.
Parameters: 


Returns: 

nengo.dists.
get_samples
(dist_or_samples, n, d=None, rng=np.random)[source]¶Convenience function to sample a distribution or return samples.
Use this function in situations where you accept an argument that could
be a distribution, or could be an array_like
of samples.
Parameters: 


Returns: 

Examples
>>> def mean(values, n=100):
... samples = get_samples(values, n=n)
... return np.mean(samples)
>>> mean([1, 2, 3, 4])
2.5
>>> mean(nengo.dists.Gaussian(0, 1))
0.057277898442269548
nengo.dists.
Uniform
(low, high, integer=False)[source]¶A uniform distribution.
It’s equally likely to get any scalar between low
and high
.
Note that the order of low
and high
doesn’t matter;
if low < high
this will still work, and low
will still
be a closed interval while high
is open.
Parameters: 


nengo.dists.
Gaussian
(mean, std)[source]¶A Gaussian distribution.
This represents a bellcurve centred at mean
and with
spread represented by the standard deviation, std
.
Parameters: 


Raises: 

nengo.dists.
Exponential
(scale, shift=0.0, high=inf)[source]¶An exponential distribution (optionally with high values clipped).
If high
is left to its default value of infinity, this is a standard
exponential distribution. If high
is set, then any sampled values at
or above high
will be clipped so they are slightly below high
.
This is useful for thresholding and, by extension,
networks.AssociativeMemory
.
The probability distribution function (PDF) is given by:
 0 if x < shift
p(x) =  1/scale * exp((x  shift)/scale) if x >= shift and x < high
 n if x == high  eps
 0 if x >= high
where n
is such that the PDF integrates to one, and eps
is an
infintesimally small number such that samples of x
are strictly less than
high
(in practice, eps
depends on the floating point precision).
Parameters: 


nengo.dists.
UniformHypersphere
(surface=False, min_magnitude=0)[source]¶Uniform distribution on or in an ndimensional unit hypersphere.
Sample points are uniformly distributed across the volume (default) or surface of an ndimensional unit hypersphere.
Parameters: 


nengo.dists.
Choice
(options, weights=None)[source]¶Discrete distribution across a set of possible values.
The same as numpy.random.choice
, except can take vector or matrix values
for the choices.
Parameters: 


nengo.dists.
Samples
(samples)[source]¶A set of samples.
This class is a subclass of Distribution
so that it can be used in any
situation that calls for a Distribution
. However, the call to sample
must match the dimensions of the samples or a ValidationError
will be raised.
Parameters: 


nengo.dists.
PDF
(x, p)[source]¶An arbitrary distribution from a PDF.
Parameters: 


nengo.dists.
SqrtBeta
(n, m=1)[source]¶Distribution of the square root of a Beta distributed random variable.
Given n + m
dimensional random unit vectors, the length of subvectors
with m
elements will be distributed according to this distribution.
Parameters: 


See also
cdf
(x)[source]¶Cumulative distribution function.
Note
Requires SciPy.
Parameters: 


Returns: 

nengo.dists.
SubvectorLength
(dimensions, subdimensions=1)[source]¶Distribution of the length of a subvectors of a unit vector.
Parameters: 


See also
nengo.dists.
CosineSimilarity
(dimensions)[source]¶Distribution of the cosine of the angle between two random vectors.
The “cosine similarity” is the cosine of the angle between two vectors, which is equal to the dot product of the vectors, divided by the L2norms of the individual vectors. When these vectors are unit length, this is then simply the distribution of their dot product.
This is also equivalent to the distribution of a single coefficient from a
unit vector (a single dimension of UniformHypersphere(surface=True)
).
Furthermore, CosineSimilarity(d+2)
is equivalent to the distribution of
a single coordinate from points uniformly sampled from the ddimensional
unit ball (a single dimension of
UniformHypersphere(surface=False).sample(n, d)
). These relationships
have been detailed in [Voelker2017].
This can be used to calculate an intercept c = ppf(1  p)
such that
dot(u, v) >= c
with probability p
, for random unit vectors u
and v
. In other words, a neuron with intercept ppf(1  p)
will
fire with probability p
for a random unit length input.
Parameters: 


See also
nengo.neurons.NeuronType 
Base class for Nengo neuron models. 
nengo.Direct 
Signifies that an ensemble should simulate in direct mode. 
nengo.RectifiedLinear 
A rectified linear neuron model. 
nengo.SpikingRectifiedLinear 
A rectified integrate and fire neuron model. 
nengo.Sigmoid 
A neuron model whose response curve is a sigmoid. 
nengo.LIF 
Spiking version of the leaky integrateandfire (LIF) neuron model. 
nengo.LIFRate 
Nonspiking version of the leaky integrateandfire (LIF) neuron model. 
nengo.AdaptiveLIF 
Adaptive spiking version of the LIF neuron model. 
nengo.AdaptiveLIFRate 
Adaptive nonspiking version of the LIF neuron model. 
nengo.Izhikevich 
Izhikevich neuron model. 
nengo.neurons.
NeuronType
[source]¶Base class for Nengo neuron models.
Attributes: 


current
(x, gain, bias)[source]¶Compute current injected in each neuron given input, gain and bias.
Parameters: 


gain_bias
(max_rates, intercepts)[source]¶Compute the gain and bias needed to satisfy max_rates, intercepts.
This takes the neurons, approximates their response function, and then uses that approximation to find the gain and bias value that will give the requested intercepts and max_rates.
Note that this default implementation is very slow! Whenever possible, subclasses should override this with a neuronspecific implementation.
Parameters: 


Returns: 

max_rates_intercepts
(gain, bias)[source]¶Compute the max_rates and intercepts given gain and bias.
Note that this default implementation is very slow! Whenever possible, subclasses should override this with a neuronspecific implementation.
Parameters: 


Returns: 

rates
(x, gain, bias)[source]¶Compute firing rates (in Hz) for given vector input, x
.
This default implementation takes the naive approach of running the step function for a second. This should suffice for most ratebased neuron types; for spiking neurons it will likely fail (those models should override this function).
Parameters: 


Returns: 

step_math
(dt, J, output)[source]¶Implements the differential equation for this neuron type.
At a minimum, NeuronType subclasses must implement this method.
That implementation should modify the output
parameter rather
than returning anything, for efficiency reasons.
Parameters: 


nengo.
Direct
[source]¶Signifies that an ensemble should simulate in direct mode.
In direct mode, the ensemble represents and transforms signals perfectly, rather than through a neural approximation. Note that direct mode ensembles with recurrent connections can easily diverge; most other neuron types will instead saturate at a certain high firing rate.
nengo.
RectifiedLinear
(amplitude=1)[source]¶A rectified linear neuron model.
Each neuron is modeled as a rectified line. That is, the neuron’s activity scales linearly with current, unless it passes below zero, at which point the neural activity will stay at zero.
Parameters: 


nengo.
SpikingRectifiedLinear
(amplitude=1)[source]¶A rectified integrate and fire neuron model.
Each neuron is modeled as a rectified line. That is, the neuron’s activity scales linearly with current, unless the current is less than zero, at which point the neural activity will stay at zero. This is a spiking version of the RectifiedLinear neuron model.
Parameters: 


nengo.
Sigmoid
(tau_ref=0.0025)[source]¶A neuron model whose response curve is a sigmoid.
Since the tuning curves are strictly positive, the intercepts
correspond to the inflection point of each sigmoid. That is,
f(intercept) = 0.5
where f
is the pure sigmoid function.
nengo.
LIF
(tau_rc=0.02, tau_ref=0.002, min_voltage=0, amplitude=1)[source]¶Spiking version of the leaky integrateandfire (LIF) neuron model.
Parameters: 


nengo.
LIFRate
(tau_rc=0.02, tau_ref=0.002, amplitude=1)[source]¶Nonspiking version of the leaky integrateandfire (LIF) neuron model.
Parameters: 


nengo.
AdaptiveLIF
(tau_n=1, inc_n=0.01, **lif_args)[source]¶Adaptive spiking version of the LIF neuron model.
Works as the LIF model, except with adapation state n
, which is
subtracted from the input current. Its dynamics are:
tau_n dn/dt = n
where n
is incremented by inc_n
when the neuron spikes.
Parameters: 


References
[1]  Koch, Christof. Biophysics of Computation: Information Processing in Single Neurons. Oxford University Press, 1999. p. 339 
nengo.
AdaptiveLIFRate
(tau_n=1, inc_n=0.01, **lif_args)[source]¶Adaptive nonspiking version of the LIF neuron model.
Works as the LIF model, except with adapation state n
, which is
subtracted from the input current. Its dynamics are:
tau_n dn/dt = n
where n
is incremented by inc_n
when the neuron spikes.
Parameters: 


References
[1]  Koch, Christof. Biophysics of Computation: Information Processing in Single Neurons. Oxford University Press, 1999. p. 339 
nengo.
Izhikevich
(tau_recovery=0.02, coupling=0.2, reset_voltage=65.0, reset_recovery=8.0)[source]¶Izhikevich neuron model.
This implementation is based on the original paper [1]; however, we rename some variables for clarity. What was originally ‘v’ we term ‘voltage’, which represents the membrane potential of each neuron. What was originally ‘u’ we term ‘recovery’, which represents membrane recovery, “which accounts for the activation of K+ ionic currents and inactivation of Na+ ionic currents.” The ‘a’, ‘b’, ‘c’, and ‘d’ parameters are also renamed (see the parameters below).
We use default values that correspond to regular spiking (‘RS’) neurons. For other classes of neurons, set the parameters as follows.
reset_voltage=55, reset_recovery=4
reset_voltage=50, reset_recovery=2
tau_recovery=0.1
coupling=0.25
tau_recovery=0.1, coupling=0.26
Parameters: 


References
[1]  (1, 2) E. M. Izhikevich, “Simple model of spiking neurons.” IEEE Transactions on Neural Networks, vol. 14, no. 6, pp. 15691572. (http://www.izhikevich.org/publications/spikes.pdf) 
nengo.learning_rules.LearningRuleType 
Base class for all learning rule objects. 
nengo.PES 
Prescribed Error Sensitivity learning rule. 
nengo.BCM 
BienenstockCooperMunroe learning rule. 
nengo.Oja 
Oja learning rule. 
nengo.Voja 
Vector Oja learning rule. 
nengo.learning_rules.
LearningRuleType
(learning_rate=Default, size_in=0)[source]¶Base class for all learning rule objects.
To use a learning rule, pass it as a learning_rule_type
keyword
argument to the Connection
on which you want to do learning.
Each learning rule exposes two important pieces of metadata that the builder uses to determine what information should be stored.
The size_in
is the dimensionality of the incoming error signal. It
can either take an integer or one of the following string values:
'pre'
: vector error signal in preobject space'post'
: vector error signal in postobject space'mid'
: vector error signal in the conn.size_mid
space'pre_state'
: vector error signal in presynaptic ensemble space'post_state'
: vector error signal in presynaptic ensemble spaceThe difference between 'post_state'
and 'post'
is that with the
former, if a Neurons
object is passed, it will use the dimensionality
of the corresponding Ensemble
, whereas the latter simply uses the
post
object size_in
. Similarly with 'pre_state'
and 'pre'
.
The modifies
attribute denotes the signal targeted by the rule.
Options are:
'encoders'
'decoders'
'weights'
Parameters: 


Attributes: 

nengo.
PES
(learning_rate=Default, pre_synapse=Default, pre_tau=Unconfigurable)[source]¶Prescribed Error Sensitivity learning rule.
Modifies a connection’s decoders to minimize an error signal provided through a connection to the connection’s learning rule.
Parameters: 


Attributes: 

nengo.
BCM
(learning_rate=Default, pre_synapse=Default, post_synapse=Default, theta_synapse=Default, pre_tau=Unconfigurable, post_tau=Unconfigurable, theta_tau=Unconfigurable)[source]¶BienenstockCooperMunroe learning rule.
Modifies connection weights as a function of the presynaptic activity and the difference between the postsynaptic activity and the average postsynaptic activity.
Parameters: 


Notes
The BCM rule is dependent on pre and post neural activities,
not decoded values, and so is not affected by changes in the
size of pre and post ensembles. However, if you are decoding from
the post ensemble, the BCM rule will have an increased effect on
larger post ensembles because more connection weights are changing.
In these cases, it may be advantageous to scale the learning rate
on the BCM rule by 1 / post.n_neurons
.
Attributes: 


nengo.
Oja
(learning_rate=Default, pre_synapse=Default, post_synapse=Default, beta=Default, pre_tau=Unconfigurable, post_tau=Unconfigurable)[source]¶Oja learning rule.
Modifies connection weights according to the Hebbian Oja rule, which augments typically Hebbian coactivity with a “forgetting” term that is proportional to the weight of the connection and the square of the postsynaptic activity.
Parameters: 


Notes
The Oja rule is dependent on pre and post neural activities,
not decoded values, and so is not affected by changes in the
size of pre and post ensembles. However, if you are decoding from
the post ensemble, the Oja rule will have an increased effect on
larger post ensembles because more connection weights are changing.
In these cases, it may be advantageous to scale the learning rate
on the Oja rule by 1 / post.n_neurons
.
Attributes: 


nengo.
Voja
(learning_rate=Default, post_synapse=Default, post_tau=Unconfigurable)[source]¶Vector Oja learning rule.
Modifies an ensemble’s encoders to be selective to its inputs.
A connection to the learning rule will provide a scalar weight for the learning rate, minus 1. For instance, 0 is normal learning, 1 is no learning, and less than 1 causes antilearning or “forgetting”.
Parameters: 


Attributes: 

nengo.Process 
A general system with input, output, and state. 
nengo.processes.PresentInput 
Present a series of inputs, each for the same fixed length of time. 
nengo.processes.FilteredNoise 
Filtered white noise process. 
nengo.processes.BrownNoise 
Brown noise process (aka Brownian noise, red noise, Wiener process). 
nengo.processes.WhiteNoise 
Fullspectrum white noise process. 
nengo.processes.WhiteSignal 
An ideal lowpass filtered white noise process. 
nengo.processes.Piecewise 
A piecewise function with different options for interpolation. 
nengo.
Process
(default_size_in=0, default_size_out=1, default_dt=0.001, seed=None)[source]¶A general system with input, output, and state.
For more details on how to use processes and make custom process subclasses, see Processes and how to use them.
Parameters: 


Attributes: 

apply
(x, d=None, dt=None, rng=<module 'numpy.random' from '/home/travis/miniconda/envs/test/lib/python3.6/sitepackages/numpy/random/__init__.py'>, copy=True, **kwargs)[source]¶Run process on a given input.
Keyword arguments that do not appear in the parameter list below
will be passed to the make_step
function of this process.
Parameters: 


get_rng
(rng)[source]¶Get a properly seeded independent RNG for the process step.
Parameters: 


make_step
(shape_in, shape_out, dt, rng)[source]¶Create function that advances the process forward one time step.
This must be implemented by all custom processes.
Parameters: 


run
(t, d=None, dt=None, rng=<module 'numpy.random' from '/home/travis/miniconda/envs/test/lib/python3.6/sitepackages/numpy/random/__init__.py'>, **kwargs)[source]¶Run process without input for given length of time.
Keyword arguments that do not appear in the parameter list below
will be passed to the make_step
function of this process.
Parameters: 


run_steps
(n_steps, d=None, dt=None, rng=<module 'numpy.random' from '/home/travis/miniconda/envs/test/lib/python3.6/sitepackages/numpy/random/__init__.py'>, **kwargs)[source]¶Run process without input for given number of steps.
Keyword arguments that do not appear in the parameter list below
will be passed to the make_step
function of this process.
Parameters: 


nengo.processes.
PresentInput
(inputs, presentation_time, **kwargs)[source]¶Present a series of inputs, each for the same fixed length of time.
Parameters: 


nengo.processes.
FilteredNoise
(synapse=Lowpass(0.005), dist=Gaussian(mean=0, std=1), scale=True, synapse_kwargs=None, **kwargs)[source]¶Filtered white noise process.
This process takes white noise and filters it using the provided synapse.
Parameters: 


nengo.processes.
BrownNoise
(dist=Gaussian(mean=0, std=1), **kwargs)[source]¶Brown noise process (aka Brownian noise, red noise, Wiener process).
This process is the integral of white noise.
Parameters: 


nengo.processes.
WhiteNoise
(dist=Gaussian(mean=0, std=1), scale=True, **kwargs)[source]¶Fullspectrum white noise process.
Parameters: 


References
[1]  (1, 2) Gillespie, D.T. (1996) Exact numerical simulation of the Ornstein Uhlenbeck process and its integral. Phys. Rev. E 54, pp. 208491. 
nengo.processes.
WhiteSignal
(period, high, rms=0.5, y0=None, **kwargs)[source]¶An ideal lowpass filtered white noise process.
This signal is created in the frequency domain, and designed to have exactly equal power at all frequencies below the cutoff frequency, and no power above the cutoff.
The signal is naturally periodic, so it can be used beyond its period while still being continuous with continuous derivatives.
Parameters: 


nengo.processes.
Piecewise
(data, interpolation='zero', **kwargs)[source]¶A piecewise function with different options for interpolation.
Given an input dictionary of {0: 0, 0.5: 1, 0.75: 0.5, 1: 0}
,
this process will emit the numerical values (0, 1, 0.5, 0)
starting at the corresponding time points (0, 0.5, 0.75, 1).
The keys in the input dictionary must be times (float or int). The values in the dictionary can be floats, lists of floats, or numpy arrays. All lists or numpy arrays must be of the same length, as the output shape of the process will be determined by the shape of the values.
Interpolation on the data points using scipy.interpolate
is also
supported. The default interpolation is ‘zero’, which creates a
piecewise function whose values change at the specified time points.
So the above example would be shortcut for:
def function(t):
if t < 0.5:
return 0
elif t < 0.75
return 1
elif t < 1:
return 0.5
else:
return 0
For times before the first specified time, an array of zeros (of the correct length) will be emitted. This means that the above can be simplified to:
Piecewise({0.5: 1, 0.75: 0.5, 1: 0})
Parameters: 


Examples
>>> from nengo.processes import Piecewise
>>> process = Piecewise({0.5: 1, 0.75: 1, 1: 0})
>>> with nengo.Network() as model:
... u = nengo.Node(process, size_out=process.default_size_out)
... up = nengo.Probe(u)
>>> with nengo.Simulator(model) as sim:
... sim.run(1.5)
>>> f = sim.data[up]
>>> t = sim.trange()
>>> f[t == 0.2]
array([[ 0.]])
>>> f[t == 0.58]
array([[ 1.]])
Attributes: 


nengo.synapses.Synapse 
Abstract base class for synapse models. 
nengo.synapses.filt 
Filter signal with synapse . 
nengo.synapses.filtfilt 
Zerophase filtering of signal using the synapse filter. 
nengo.LinearFilter 
General linear timeinvariant (LTI) system synapse. 
nengo.Lowpass 
Standard firstorder lowpass filter synapse. 
nengo.Alpha 
Alphafunction filter synapse. 
nengo.synapses.Triangle 
Triangular finite impulse response (FIR) synapse. 
nengo.synapses.
Synapse
(default_size_in=1, default_size_out=None, default_dt=0.001, seed=None)[source]¶Abstract base class for synapse models.
Conceptually, a synapse model emulates a biological synapse, taking in input in the form of released neurotransmitter and opening ion channels to allow more or less current to flow into the neuron.
In Nengo, the implementation of a synapse is as a specific case of a
Process
in which the input and output shapes are the same.
The input is the current across the synapse, and the output is the current
that will be induced in the postsynaptic neuron.
Synapses also contain the Synapse.filt
and Synapse.filtfilt
methods,
which make it easy to use Nengo’s synapse models outside of Nengo
simulations.
Parameters: 


Attributes: 

filt
(x, dt=None, axis=0, y0=None, copy=True, filtfilt=False)[source]¶Filter x
with this synapse model.
Parameters: 


filtfilt
(x, **kwargs)[source]¶Zerophase filtering of x
using this filter.
Equivalent to filt(x, filtfilt=True, **kwargs)
.
make_step
(shape_in, shape_out, dt, rng, y0=None, dtype=<class 'numpy.float64'>)[source]¶Create function that advances the synapse forward one time step.
At a minimum, Synapse subclasses must implement this method. That implementation should return a callable that will perform the synaptic filtering operation.
Parameters: 


nengo.synapses.
filt
(signal, synapse, dt, axis=0, x0=None, copy=True)[source]¶Filter signal
with synapse
.
Note
Deprecated in Nengo 2.1.0.
Use Synapse.filt
method instead.
nengo.synapses.
filtfilt
(signal, synapse, dt, axis=0, x0=None, copy=True)[source]¶Zerophase filtering of signal
using the synapse
filter.
Note
Deprecated in Nengo 2.1.0.
Use Synapse.filtfilt
method instead.
nengo.
LinearFilter
(num, den, analog=True, **kwargs)[source]¶General linear timeinvariant (LTI) system synapse.
This class can be used to implement any linear filter, given the filter’s transfer function. [1]
Parameters: 


References
[1]  (1, 2) https://en.wikipedia.org/wiki/Filter_%28signal_processing%29 
Attributes: 


evaluate
(frequencies)[source]¶Evaluate the transfer function at the given frequencies.
Examples
Using the evaluate
function to make a Bode plot:
synapse = nengo.synapses.LinearFilter([1], [0.02, 1])
f = numpy.logspace(1, 3, 100)
y = synapse.evaluate(f)
plt.subplot(211); plt.semilogx(f, 20*np.log10(np.abs(y)))
plt.xlabel('frequency [Hz]'); plt.ylabel('magnitude [dB]')
plt.subplot(212); plt.semilogx(f, np.angle(y))
plt.xlabel('frequency [Hz]'); plt.ylabel('phase [radians]')
make_step
(shape_in, shape_out, dt, rng, y0=None, dtype=<class 'numpy.float64'>, method='zoh')[source]¶Returns a Step
instance that implements the linear filter.
NoDen
(num, den, output)[source]¶An LTI step function for transfer functions with no denominator.
This step function should be much faster than the equivalent general step function.
Simple
(num, den, output, y0=None)[source]¶An LTI step function for transfer functions with one num and den.
This step function should be much faster than the equivalent general step function.
General
(num, den, output, y0=None)[source]¶An LTI step function for any given transfer function.
Implements a discretetime LTI system using the difference equation [1] for the given transfer function (num, den).
References
[1]  (1, 2) https://en.wikipedia.org/wiki/Digital_filter#Difference_equation 
nengo.
Lowpass
(tau, **kwargs)[source]¶Standard firstorder lowpass filter synapse.
The impulseresponse function is given by:
f(t) = (1 / tau) * exp(t / tau)
Parameters: 


Attributes: 

make_step
(shape_in, shape_out, dt, rng, y0=None, dtype=<class 'numpy.float64'>, **kwargs)[source]¶Returns an optimized LinearFilter.Step
subclass.
nengo.
Alpha
(tau, **kwargs)[source]¶Alphafunction filter synapse.
The impulseresponse function is given by:
alpha(t) = (t / tau**2) * exp(t / tau)
and was found by [1] to be a good basic model for synapses.
Parameters: 


References
[1]  (1, 2) Mainen, Z.F. and Sejnowski, T.J. (1995). Reliability of spike timing in neocortical neurons. Science (New York, NY), 268(5216):15036. 
Attributes: 


make_step
(shape_in, shape_out, dt, rng, y0=None, dtype=<class 'numpy.float64'>, **kwargs)[source]¶Returns an optimized LinearFilter.Step
subclass.
nengo.synapses.
Triangle
(t, **kwargs)[source]¶Triangular finite impulse response (FIR) synapse.
This synapse has a triangular and finite impulse response. The length of
the triangle is t
seconds; thus the digital filter will have
t / dt + 1
taps.
Parameters: 


Attributes: 

nengo.solvers.Solver 
Decoder or weight solver. 
nengo.solvers.Lstsq 
Unregularized leastsquares solver. 
nengo.solvers.LstsqNoise 
Leastsquares solver with additive Gaussian white noise. 
nengo.solvers.LstsqMultNoise 
Leastsquares solver with multiplicative white noise. 
nengo.solvers.LstsqL2 
Leastsquares solver with L2 regularization. 
nengo.solvers.LstsqL2nz 
Leastsquares solver with L2 regularization on nonzero components. 
nengo.solvers.LstsqL1 
Leastsquares solver with L1 and L2 regularization (elastic net). 
nengo.solvers.LstsqDrop 
Find sparser decoders/weights by dropping small values. 
nengo.solvers.Nnls 
Nonnegative leastsquares solver without regularization. 
nengo.solvers.NnlsL2 
Nonnegative leastsquares solver with L2 regularization. 
nengo.solvers.NnlsL2nz 
Nonnegative leastsquares with L2 regularization on nonzero components. 
nengo.solvers.NoSolver 
Manually pass in weights, bypassing the decoder solver. 
nengo.solvers.
Solver
(weights=False)[source]¶Decoder or weight solver.
__call__
(A, Y, rng=<module 'numpy.random' from '/home/travis/miniconda/envs/test/lib/python3.6/sitepackages/numpy/random/__init__.py'>, E=None)[source]¶Call the solver.
Parameters: 


Returns: 

mul_encoders
(Y, E, copy=False)[source]¶Helper function that projects signal Y
onto encoders E
.
Parameters: 


nengo.solvers.
Lstsq
(weights=False, rcond=0.01)[source]¶Unregularized leastsquares solver.
Parameters: 


Attributes: 

nengo.solvers.
LstsqNoise
(weights=False, noise=0.1, solver=Cholesky(transpose=None))[source]¶Leastsquares solver with additive Gaussian white noise.
Parameters: 


Attributes: 

nengo.solvers.
LstsqMultNoise
(weights=False, noise=0.1, solver=Cholesky(transpose=None))[source]¶Leastsquares solver with multiplicative white noise.
Parameters: 


Attributes: 

nengo.solvers.
LstsqL2
(weights=False, reg=0.1, solver=Cholesky(transpose=None))[source]¶Leastsquares solver with L2 regularization.
Parameters: 


Attributes: 

nengo.solvers.
LstsqL2nz
(weights=False, reg=0.1, solver=Cholesky(transpose=None))[source]¶Leastsquares solver with L2 regularization on nonzero components.
Parameters: 


Attributes: 

nengo.solvers.
LstsqL1
(weights=False, l1=0.0001, l2=1e06, max_iter=1000)[source]¶Leastsquares solver with L1 and L2 regularization (elastic net).
This method is well suited for creating sparse decoders or weight matrices.
Note
Requires scikitlearn.
Parameters: 


Attributes: 

nengo.solvers.
LstsqDrop
(weights=False, drop=0.25, solver1=LstsqL2(reg=0.001, solver=Cholesky(transpose=None), weights=False), solver2=LstsqL2(reg=0.1, solver=Cholesky(transpose=None), weights=False))[source]¶Find sparser decoders/weights by dropping small values.
This solver first solves for coefficients (decoders/weights) with L2 regularization, drops those nearest to zero, and retrains remaining.
Parameters: 


Attributes: 

nengo.solvers.
Nnls
(weights=False)[source]¶Nonnegative leastsquares solver without regularization.
Similar to Lstsq
, except the output values are nonnegative.
If solving for nonnegative weights, it is important that the intercepts of the postpopulation are also nonnegative, since neurons with negative intercepts will never be silent, affecting output accuracy.
Note
Requires SciPy.
Parameters: 


Attributes: 

nengo.solvers.
NnlsL2
(weights=False, reg=0.1)[source]¶Nonnegative leastsquares solver with L2 regularization.
Similar to LstsqL2
, except the output values are nonnegative.
If solving for nonnegative weights, it is important that the intercepts of the postpopulation are also nonnegative, since neurons with negative intercepts will never be silent, affecting output accuracy.
Note
Requires SciPy.
Parameters: 


Attributes: 

nengo.solvers.
NnlsL2nz
(weights=False, reg=0.1)[source]¶Nonnegative leastsquares with L2 regularization on nonzero components.
Similar to LstsqL2nz
, except the output values are nonnegative.
If solving for nonnegative weights, it is important that the intercepts of the postpopulation are also nonnegative, since neurons with negative intercepts will never be silent, affecting output accuracy.
Note
Requires SciPy.
Parameters: 


Attributes: 

nengo.solvers.
NoSolver
(values=None, weights=False)[source]¶Manually pass in weights, bypassing the decoder solver.
Parameters: 


Attributes: 
