-
Notifications
You must be signed in to change notification settings - Fork 1
/
nengo.tex
1678 lines (1553 loc) · 56.6 KB
/
nengo.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass{frontiersSCNS}
%%%%% Some customizations
\usepackage{listings}
\usepackage{inconsolata}
\graphicspath{{figures/}}
%%%%% Frontiers boilerplate
\usepackage{url,lineno}
\linenumbers
\copyrightyear{2013}
\pubyear{2013}
\def\journal{Neuroinformatics}
\def\DOI{}
\def\articleType{Methods Article}
\def\keyFont{\fontsize{8}{11}\helveticabold }
\def\firstAuthorLast{Bekolay {et~al.}}
\def\Authors{Trevor Bekolay\,$^{1,*}$, James Bergstra\,$^{1}$,
Eric Hunsberger\,$^{1}$, Travis DeWolf\,$^{1}$, Terrence C. Stewart\,$^{1}$,
Daniel Rasmussen\,$^{1}$, Xuan Choo\,$^{1}$, Aaron Voelker\,$^{1}$,
and Chris Eliasmith\,$^{1}$}
\def\Address{$^{1}$Center for Theoretical Neuroscience,
University of Waterloo, Waterloo, ON, Canada}
\def\corrAuthor{Trevor Bekolay}
\def\corrAddress{David R. Cheriton School of Computer Science,
University of Waterloo, 200 University Avenue West,
Waterloo, ON, N2L 3G1, Canada}
\def\corrEmail{tbekolay@uwaterloo.ca}
%%%%% Document begins
\begin{document}
\onecolumn
\firstpage{1}
\title[Nengo in Python]{Nengo: A Python tool for
building large-scale functional brain models}
\author[\firstAuthorLast ]{\Authors}
\address{}
\correspondance{}
\extraAuth{}
\topic{Python in Neuroscience II}
\maketitle
\begin{abstract}
Neuroscience currently lacks
a comprehensive theory of
how cognitive processes can be
implemented in a biological substrate.
The Neural Engineering Framework (NEF)
proposes one such theory,
but has not yet gathered
significant empirical support,
partly due to the technical
challenge of building and simulating
large-scale models with the NEF.
Nengo is a software tool
that can be used to build and simulate
large-scale models based on the NEF;
currently, it is the primary resource
for both teaching how the NEF
is used,
and for doing research
that generates specific
NEF models
to explain experimental data.
Nengo 1.4, which was implemented in Java,
was used to create Spaun,
the world's largest functional
brain model \citep{eliasmith2012}.
Simulating Spaun
highlighted limitations
in Nengo 1.4's ability to
support model construction with simple syntax,
to simulate large models quickly,
and to collect large amounts of data
for subsequent analysis.
This paper describes Nengo 2.0,
which is implemented in Python
and overcomes these limitations.
It uses simple and extendable syntax,
simulates a benchmark model on the scale of Spaun
50 times faster than Nengo 1.4,
and has a flexible mechanism
for collecting simulation results.
\tiny \keyFont{\section{Keywords:} Neural Engineering
Framework, Nengo, Python, neuroscience, theoretical neuroscience,
control theory, simulation}
\end{abstract}
\section{Introduction}
Modeling the human brain
is one of the greatest
scientific challenges of our time.
Computational neuroscience
has made significant advancements
from simulating low-level biological parts in great detail,
to solving high-level problems that humans find difficult;
however, we still lack a mathematical account of
how biological components
implement cognitive functions such as sensory processing,
memory formation, reasoning, and motor control.
Much work has been put into neural simulators
that attempt to recreate neuroscientific
data in precise detail with the thought that
cognition will emerge by connecting
detailed neuron models according
to the statistics of biological synapses \citep{markram2006}.
However, cognition has not yet emerged
from data-driven large scale models,
and there are good reasons to think
that cognition may never emerge \citep{eliasmith2013a}.
At the other end of the spectrum,
cognitive architectures \citep{anderson2004,aisa2008}
and machine learning approaches \citep{hinton2006}
have solved high-dimensional statistical problems,
but do so without respecting biological constraints.
Nengo\footnote{Nengo is available for download through
the Python Package Index at
\url{https://pypi.python.org/pypi/nengo}.
The full source is available at
\url{https://github.com/ctn-waterloo/nengo}.}
is a neural simulator
based on a theoretical framework proposed
by \citet{eliasmith2003}
called the Neural Engineering Framework
(NEF).
The NEF is a large-scale modeling approach
that can leverage single neuron models
to build neural networks with
demonstrable cognitive abilities.
Nengo and the NEF has been used to build
increasingly sophisticated neural subsystems
for the last decade
(e.g., path integration [\citealp{conklin2005}],
working memory [\citealp{singh2006}],
list memory [\citealp{choo2010}],
inductive reasoning [\citealp{rasmussen2014}],
motor control [\citealp{dewolf2011}],
decision making [\citealp{stewart2012}])
culminating recently with Spaun,
currently the world's
largest functional brain model \citep{eliasmith2012}.
Spaun is a network of 2.5 million spiking neurons
that can perform eight cognitive tasks
including memorizing lists and inductive reasoning.
It can perform any of these eight tasks
at any time by being presented
the appropriate series of images
representing the task to be performed;
for example, sequentially presenting images
containing the characters $A3[1234]$ instructs Spaun
to memorize the list $1234$.
If asked to recall the memorized list,
Spaun generates motor commands for a simulated arm,
writing out the digits $1234$.
While the tasks that Spaun performs are diverse,
all of the tasks use a common set of
functional cortical and subcortical components.
Each functional component corresponds
to a brain area that has been hypothesized
to perform those functions
in the neuroscientific literature.
The NEF provides principles
to guide the construction of
a neural model
that incorporates anatomical constraints,
functional objectives, and
dynamical systems or control theory.
Constructing models from this starting point,
rather than from single cell electrophysiology
and connectivity statistics alone,
produces simulated data that explains
and predicts a wide variety of experimental results.
Single cell activity \citep{stewart2012},
response timing \citep{stewart2009a},
behavioral errors \citep{choo2010},
and age-related cognitive decline \citep{rasmussen2014},
of NEF-designed models match
physiological and psychological findings
without being built specifically into the design.
These results are a consequence of
the need to satisfy functional objectives
within anatomical and neurobiological constraints.
The transformation principle of the NEF
proposes that the connection weight matrix
between two neural populations
can compute a nonlinear function,
and can be factored into
two significantly smaller matrices.
By using these factors
instead of full connection weight matrices,
NEF-designed models are
more computationally efficient,
which allows Nengo to run
large-scale neural models
on low-cost commodity hardware.
In order to make Nengo more simple, extensible, and fast,
we have rewritten Nengo 2.0 from scratch in Python,
leveraging NumPy \citep{oliphant2007}
for manipulating large amounts of data.
While NumPy is its only dependency,
Nengo contains optional extensions
for plotting if Matplotlib is available
\citep{hunter2007}
and for interactive exploration
if IPython is available \citep{perez2007}.
Since Nengo only depends on one third-party library,
it is easy to integrate Nengo models
in arbitrary CPython programs,
opening up possibilities
for using neurally implemented algorithms
in web services, games, and other applications.
Nengo 2.0 has a simple object model,
which makes it easy to
document, test, and modify.
Model creation and simulation are decoupled,
allowing for models to be run with
other simulators as drop-in replacements for Nengo 2.0's
platform-independent reference simulator.
To date, we have implemented one other simulator
that uses PyOpenCL to take advantage
of a GPU or multicore CPU.
The OpenCL simulator can simulate
large models on the scale of Spaun
at least 50 times faster than Nengo 1.4
using inexpensive commodity hardware.
In all, Nengo 2.0 provides a platform for
simulating larger and more complex models than Spaun,
and can therefore further test the NEF
as a theory of neural computation.
\section{Neural Engineering Framework (NEF)} \label{sec:nef}
The Neural Engineering Framework (NEF; \citealp{eliasmith2003})
proposes three quantitatively specified principles
that enable the construction
of large-scale neural models.
Briefly, this mathematical theory defines:
\begin{enumerate}
\item \textbf{Representation:} A population of neurons
collectively represents a time-varying vector of real numbers
through nonlinear encoding and linear decoding.
\item \textbf{Transformation:} Linear and nonlinear
functions on those vectors
are computed by linear decodings
that are used to analytically compute
the connections between populations of neurons.
\item \textbf{Dynamics:} The vectors represented
by neural populations can be considered state variables
in a (linear or nonlinear) dynamical system,
and recurrent connections can be computed
using principle 2.
\end{enumerate}
Figure~\ref{fig:nef} provides a graphical
summary of these three principles.
\paragraph{Representation}
Information is encoded by populations of neurons.
The NEF represents information
with time-varying vectors of real numbers,
allowing theorists to propose possible
neural computations by
manipulating that information
using conventional mathematics.
The NEF suggests that we can characterize
the \textit{encoding} of
those vectors by injecting
specific amounts of current into
single neuron models based on
the vector being encoded.
This drives the neuron,
causing it to spike.
With enough neurons,
the originally encoded vector
can be estimated
through a \textit{decoding} process.
This idea is a kind of population coding
\citep{georgopoulos1986, salinas1994}, but generalized
to vectors of arbitrary dimensionality.
In the encoding process, the input signal drives
each neuron based on its \textit{tuning curve},
which describes how likely
that neuron is to respond to a given input signal.
The tuning curve is a function of the gain
of a neuron (how quickly the activity rises),
the bias (the activity of a neuron given no signal),
and the \textit{encoding weight}
(the direction in the input vector space
that causes the neuron to be the most active).
Importantly, tuning curves can be determined
for any type of neuron,
and therefore the encoding process
(and the NEF as a whole)
is not dependent on any particular neuron model.
In the decoding process,
the spike trains are first filtered
with an exponentially decaying filter
accounting for the process
of a spike generating a postsynaptic current.
Those filtered spike trains are summed together
with weights that are determined
by solving a least-squares minimization problem.
Note that these decoding weights
do not necessarily depend on the input signal;
instead, we typically perform
this minimization on points
sampled from
the vector space
that the population represents.
In Nengo, the representation principle
can be seen in the \texttt{Ensemble}
object (see Section~\ref{sec:ensemble}).
\paragraph{Transformation}
Neurons communicate through
unidirectional connections called synapses.
When a neuron spikes,
it releases neurotransmitter across the synapse,
which typically causes some amount of current
to be imparted in the postsynaptic (downstream) neuron.
Many factors affect the
amplitude of the imparted current;
we summarize those factors
in a scalar connection weight
representing the strength
of the connection between two neurons.
In order to compute any function,
we set the connection weights between
two populations to be the product of
the decoding weights for that function
in the first population,
the encoding weights
for the downstream population,
and any linear transform.
This implies that the NEF makes
a hypothesis about synaptic weight matrices;
specifically, that they
have low rank, and can be factored
into encoders, decoders, and a linear transform.
Note that, in practice, we rarely use
the full connection weight matrix,
and instead store
the encoders, decoders, and linear transform separately
(i.e., the three factors of the connection weight matrix).
This provides significant
space and time savings during simulation.
In Nengo, the transformation principle
can bee seen in the \texttt{Connection}
object (see Section~\ref{sec:connection}).
\paragraph{Dynamics}
While feedforward vector transformations
suffice to describe
some neural systems,
many require persistent activity through recurrent connections.
When recurrent connections are introduced,
the vectors represented by neural populations
can be thought of as state variables
in a dynamical system.
The equations governing dynamics
in such a system
can be designed and analyzed
using the methods of control theory,
and translated into neural circuitry
using the principles
of representation and transformation.
In Nengo, dynamics can be seen when
an \texttt{Ensemble} is connected to itself.
Several of the \texttt{Network}s
implemented in Nengo also exhibit dynamics.
\paragraph{NEF and Nengo}
Large models can be built
by using the principles of the NEF
as connectable components
that describe neural systems,
just as a circuit diagram
describes an electronic circuit.
The goal of Nengo is to enable
modellers to create and connect those components.
Ensembles describe
what information is being represented,
and connections describe
how that information is transformed.
Nengo implements those descriptions
with its object model,
and translates those objects
to a network of interconnected neurons,
situating it as a ``neural compiler''
that translates
a high-level functional model
to a low-level neural model.
\section{Nengo object model}
To describe an NEF model,
Nengo defines six core objects.
\begin{enumerate}
\item The \texttt{Ensemble} contains a group of neurons
that encodes a time-varying vector of real numbers.
\item The \texttt{Node} represents non-neural information,
such as sensory inputs and motor outputs.
\item The \texttt{Connection} describes how
nodes and ensembles are connected.
\item The \texttt{Probe} gathers data during a simulation
for later analysis.
\item The \texttt{Network} encapsulates a functionally related
group of interconnected nodes and ensembles.
\item The \texttt{Model} encapsulates a Nengo model.
\end{enumerate}
These six objects contain symbolic information
about a Nengo model,
enabling a strict division between
model construction and simulation.
This allows a Nengo model
to be run on multiple simulators.
\subsection{Ensemble} \label{sec:ensemble}
An \texttt{Ensemble} is
a population of neurons
that represents information
in the form of a real-valued vector.
When creating an ensemble,
the user must provide a name,
an object that describes
a population of neurons,
and the dimensionality
(i.e., the length of the vector it represents).
For example,
\begin{quote}
\texttt{nengo.Ensemble(nengo.LIF(50, tau\_ref=0.002), 1)}
\end{quote}
describes an ensemble
that uses 50 leaky integrate-and-fire neurons \citep{lapicque1907}
with a 2 millisecond refractory period
to represent a one-dimensional vector.
The \texttt{nengo.LIF} class defines
the parameters of the LIF neurons symbolically
so that each simulator can compute
the LIF nonlinearity efficiently.
The neuron model used by the ensemble
is changed by passing in a different symbolic neuron object;
however, the simulator used must be aware
of that type of neuron.
Other attributes of the \texttt{Ensemble},
such as its encoding weights,
can be specified
either as keyword arguments
to the \texttt{Ensemble} constructor,
or by setting an attribute on the instantiated object.
While an ensemble makes a hypothesis
about the information being represented by neurons,
these additional attributes
allow modellers to set
neural parameters according to \textit{in vivo}
electrophysiology data.
If these attributes are not set,
Nengo attempts to maintain
neurobiological constraints
by using default parameters
consistent with
neocortical pyramidal cells.
\subsection{Node}
A \texttt{Node} contains a user-defined
Python function that directly calculates
the node's outputs from its inputs at each timestep.
Available inputs include
the simulator timestep,
the decoded output of an ensemble,
or the output of another node.
However, unlike ensembles,
there are no constraints on the type
of function that the node computes.
A node can track any number of variables internally,
and use the state of those variables
when computing its function.
For example, it can interact directly with hardware,
and interface with other programs
using shared memory or sockets.
Generally, a node represents information
that cannot be decoded from an ensemble.
As a simple example,
a node can be used to model sensory stimuli
that are predefined functions of time.
As a more sophisticated example,
a node can be used to model
a complex experimental environment that
both provides input to the neural model
and responds to the neural model's output.
Nodes allow Nengo to represent
neural components,
the body that those components drive,
and the environment that body interacts with
in a single unified model.
This makes Nengo models more explicit,
and enables simulators
to control and optimize node execution.
\subsection{Connection} \label{sec:connection}
Ensembles and nodes can be connected together
in several ways.
A \texttt{Connection} contains symbolic information
about how two objects are connected.
That information either includes
a factored or full connection weight matrix,
or includes enough information
to generate weights during simulation.
When an ensemble is connected
to another object,
the connection implements
the NEF's transformation principle.
In other words, the \texttt{Connection}
allows ensembles to project
encoded information---or
a transformation of that information---to
another ensemble or node.
This functionality is what enables Nengo models
to appear conceptual,
even though the underlying implementation
can translate that connection
to synaptic weights.
However, neurons in an ensemble can be directly connected
to neurons in another ensemble
with synaptic connection weights
by connecting an ensemble's
neurons directly to another ensemble's neurons
(e.g., \texttt{nengo.Connection(ens1.neurons, ens2.neurons, ...)}).
All connections can be temporally filtered,
and the weights involved in the connection
can be modified over time with learning rules.
\subsection{Probe}
A \texttt{Probe} monitors
a particular part of another object
in order to record its value throughout a simulation.
Nengo models contain many variables
that change over time,
including membrane potentials,
spike events, and encoded vectors.
It is resource intensive to store the values of
large numbers of variables
at each timestep, and it is also not necessary,
as typically only a small fraction
of these variables are analyzed after a simulation.
The modeller chooses which variables to
record by connecting a probe to an object.
Like nodes, a probe could be implemented
outside of the neural model.
However, doing so requires detailed knowledge
of the simulator,
and can incur significant overhead
if not implemented carefully.
For these reasons, we have made probes
a core component of a Nengo model,
and are therefore explicit
and optimizable.
Further, since probes are described
at a symbolic level,
the underlying implementation
can output probed data in many different formats.
Currently, simulators store probed data
directly in memory,
but the ability to store data
in files or to stream data
directly to sockets is forthcoming.
\subsection{Network}
A network is a collection of interconnected ensembles and nodes.
Networks provide a way of grouping together
a set of connected objects
that collectively perform a complex function.
Encapsulating them in a network
makes its purpose explicit
and hides the complexity of the function
(see Section~\ref{sec:cconv} for an example).
This grouping can be hierarchical,
as networks can contain other network.
\texttt{Network} is a base class designed to be
subclassed by modellers.
The code that creates and connects
several objects in a model can be
grouped into a \texttt{Network} subclass
with only minor changes.
Nengo comes with several networks already implemented
which can be used directly,
or can be used as a template
for modelers wanting to implement their own networks.
As a simple example, the \texttt{Integrator} network
is composed of only one recurrently connected ensemble.
By encapsulating that logic in a network,
the purpose of that ensemble is made explicit.
As a complex example,
the \texttt{BasalGanglia} network
is composed of five groups of ensembles
connected with several specific functions
that together implement a ``winner-take-all'' circuit.
Encapsulating the code to create those ensembles
and connections in a network
makes a complicated section of code
easy to include in many different models.
\subsection{Model}
The \texttt{Model} object is a container
for Nengo objects.
Conceptually, they are similar to networks,
but are privileged in that
simulators must have a model
passed into their constructor,
making the \texttt{Model} akin
to a network that contains
all of the objects defined for a Nengo model.
A simulator's job is to simulate a model.
\section{Nengo simulators} \label{sec:simulators}
Decoupling model creation and simulation
has been done previously
by PyNN \citep{davison2009}.
In PyNN, the same Python script
can be used to run a model
on four different simulators.
Nengo follows this programming model by
decoupling neural model creation and simulation,
which enables Nengo simulators
to allocate memory and schedule computations
in the most efficient ways possible.
Simulators are given a \texttt{Model}
as an argument;
this \texttt{Model} is a static symbolic description.
The simulator can take the model description
and build whatever data structures
are best suited to implement the simulation.
We have implemented a platform-independent
reference simulator as an example
for simulator designers.
This simulator is not a specification;
any object that accepts a Nengo \texttt{Model}
as an argument is considered a Nengo simulator.
To show that model creation and simulation
are fully decoupled,
we have also implemented
an OpenCL simulator
that uses PyOpenCL to parallelize
computations on GPUs and multicore CPUs.
However, in the remainder of this section,
we will describe
the reference simulator implementation;
the OpenCL simulator shares many
of the reference simulator's architectural choices,
but the details of its implementation
include OpenCL-specific optimizations
that are beyond the scope of this paper.
\subsection{Nengo reference simulator}
The Nengo reference simulator
makes a copy of the objects in the model
and fills in many of the details
not specified at the symbolic level.
For example, \textit{encoders}
are often not specified when the model is created,
so the reference simulator randomly chooses
them as unit vectors in the space that
the ensemble is representing.
After filling in these details,
the reference simulator
builds a reduced set of objects
that describe the computations
occurring in the model.
Specifically, the simulator
uses signals, which represent values,
and operators, which represent computations
performed on signals.
Figure~\ref{fig:sim} shows the signals
and operators used in a simple model.
\paragraph{Signals}
A \texttt{Signal} represents any number that
will be used by the simulator.
Several signals are created
for each high-level Nengo object;
for example, for each ensemble,
the simulator creates signals
that represent the high-level input
signal that will be encoded
to input currents,
and the encoding weights.
The ensemble also contains a neural population,
for which the simulator creates signals that represent
input currents, bias currents,
membrane voltages, and refractory times for each cell.
As can be seen in Figure~\ref{fig:sim},
the signals used in a Nengo simulation
can be conceptually grouped into
those that track low-level neural signals,
and those that track high-level signals
defined by the NEF.
Other neural simulators only track
low-level signals.
Operators commonly map
between related low- and high-level signals.
\paragraph{Operators}
Operators represent computations
to be performed on signals on each timestep.
Once the model has been built,
only a small set of mathematical
operations are necessary for simulation.
Many of the computations
done in a simulation
are linear transformations (e.g.,
the decoding and encoding steps
in Figure~\ref{fig:sim}),
and therefore can share a common operator;
this is helpful for parallelizing computations.
Nonlinear functions, however,
require specific operators.
Each supported neuron model and learning rule
has an associated operator.
The simulator explicitly maps
from symbolic neuron objects in ensembles
and from symbolic learning rule objects
in connections to their associated operators.
\paragraph{Reference simulator}
Before the first timestep, the reference simulator
\begin{enumerate}
\item fills in unspecified details of high-level objects,
\item translates high-level objects to
a set of signals and operators,
\item allocates NumPy arrays for each signal, and
\item sorts operators based on a dependency graph.
\end{enumerate}
On each timestep, the reference simulator
\begin{enumerate}
\item computes each operator in order, and
\item copies probed signals to memory.
\end{enumerate}
Figure~\ref{fig:sim} depicts
the state of the reference simulator
after two timesteps of a simple model;
all subsequent timesteps perform the same
operations as the first two.
\section{Example scripts} \label{sec:examples}
The scripting interface provides
a simple way to add Nengo objects to a model,
simulate that model,
and extract data collected during the simulation.
Rather than list the functions in the scripting interface,
we instead provide three concrete example scripts
that highlight the types of models that can be
built with Nengo.
We have also implemented two of these three examples
in PyNN to provide a comparison
for the length and clarity of the code
describing the models.
\subsection{Communication channel} \label{sec:comm-channel}
% A communication channel represents some signal
% and transmits it unchanged to another population
% (i.e. it implements an identify function $f(x) = x$).
% One of the most important operations
% in large neural models is routing with this sort of channel.
% When connected recurrently,
% a communication channel can also be seen as
% a simple memory, mapping a real-valued number
% $x$ to itself at a future time [awkward wording].
% In this simple case,
% we can see how the principles of the NEF
% help to translate a mathematical description
% of our model to neural circuitry.
% An Ensemble embodies the idea
% that a population of neurons
% should represent a real-valued quantity
% $x \in \mathbb{R}^1$.
% Technically, Nengo does this
% by creating a random projection matrix
% $E$ and driving the first population
% with current $Ex + b$,
% where $b$ is a vector of bias values.
% A vector $s$ of spikes emitted
% by this population are weighted and combined
% by a {\em decoder} matrix D
% so that $Ds \approx f(x)$.
% Similarly the second population
% has encoders $E_2$ and $D_2$.
% A full weight matrix $W$
% of synapse strengths
% between populations 1 and 2
% can be obtained
% by multiplying matrices $E_2$ and $D_1$ together:
% $W=E_2 D_1$.
% We ran simulations in PyNN
% by computing this product explicitly
% and using $W$ and the connection matrix.
% Unfortunately it much slower to multiply
% $s$ by $W$ than it is to compute $E_2(D_1s)$,
% which is why Nengo
% is a faster simulator for NEF-style models.
As detailed in Section~\ref{sec:nef},
NEF models are based on the principles
of representation, transformation, and dynamics.
One of the most important operations
in a large neural model is to route
represented information from
one ensemble to another without any change.
For example, in the visual system of Spaun,
a high-dimensional representation of the visual field
is compressed to a low-dimensional representation,
and then sent unchanged to several areas,
including the working memory
and action selection networks.
This routing is implemented
with a transformation
called a communication channel.
This transform simply implements
the identity function, $f(x) = x$.
Figure~\ref{fig:comm-channel}
depicts a scalar communication channel
in which band-limited Gaussian white noise
is represented in one ensemble
and projected to another ensemble.
The communication channel
is a simple enough model
that it can be readily implemented in PyNN.
Figure~\ref{fig:pynn} compares the code
for implementing a communication channel in Nengo and PyNN.
This figure highlights many of the differences
between Nengo models and conventional neural models;
we also use these script for benchmarking
(see Section~\ref{sec:benchmark}).
\subsection{Lorenz attractor network} \label{sec:lorenz}
While the communication channel exemplifies
the representation and transformation
principles of the NEF,
the Lorenz attractor exemplifies the dynamics principle.
Many models in theoretical neuroscience
are based on attractor networks \citep{amit1992, deco2003}.
The NEF has been used in the past
to implement many different types of
attractor networks by recurrently connecting
ensembles with functions that implement
dynamical systems \citep{eliasmith2005}.
Figure~\ref{fig:lorenz} depicts
a Nengo implementation of the Lorenz chaotic attractor
with a single ensemble
composed of 2000 leaky integrate-and-fire neurons.
We have implemented the Lorenz attractor
in PyNN for benchmarking purposes
(code not shown; the PyNN script is $\sim$100 lines long,
while the Nengo script in Figure~\ref{fig:lorenz}
is 20 lines long).
\subsection{Circular convolution} \label{sec:cconv}
Communication channels and attractor networks
show up in many Nengo models,
but are still relatively simple
to implement without Nengo,
as can be seen with the PyNN implementation
in Figure~\ref{fig:pynn}.
As the NEF has been used to construct
larger models that have the capabilities
of non-neural cognitive models,
a theory called the
Semantic Pointer Architecture \citep{eliasmith2013}
has emerged.
This theory uses high-dimensional vectors
as symbol-like structures
that be combined together to form
novel concepts.
One of the functions that
is performed on these vectors
is to compress two $n$-dimensional vectors
into a single $n$-dimensional vector,
which can be decompressed
into noisy versions of
the two originally compressed vectors.
We implement this compression
using the circular convolution function.
Circular convolution
is best implemented in a two-layer network,
rather than in a single connection,
which we have simplified through
the \texttt{CircularConvolution} network.
The complexity encapsulated in that network
can be seen in Figure~\ref{fig:cconv}.
Unlike the previous two examples,
we do not implement
circular convolution in PyNN.
The resulting script would be
too long to be instructive.
\section{Benchmarks} \label{sec:benchmark}
While benchmark models are not indicative
of performance on all models,
increasing simulation speed
was a primary goal of Nengo 2.0.
To validate that performance has improved,
we ran the models described in Section~\ref{sec:examples}
for various numbers of neurons and dimensions
for each ensemble.
The communication channel and Lorenz attractor
are small models that demonstrate
the principles of the NEF.
Their small size enables us to write
PyNN scripts that implement roughly
the same functionality
with Brian \citep{goodman2008}, NEURON \citep{hines2009},
and NEST \citep{eppler2009}.\footnote{We
were unable to compile PCSim \citep{pecevski2009} on the
machine on which we ran benchmarks.}
We ran each parameter set five times
on the same machine,
and plot the mean time elapsed
in Figure~\ref{fig:benchmarks}.
In most cases, the coefficient of variation
for the five sample times
is well below 0.1, except for two
outliers with coefficients of 0.18 and 0.22,
overall indicating that the reported means are robust.
The results, shown in Figure~\ref{fig:benchmarks}A and B,
suggest that all versions of Nengo are significantly
faster than the simulators accessible
through PyNN, especially
as the size of models increases.
This is likely due to Nengo's
use of factorized weight matrices,
rather than storing and computing with
the entire weight matrix
on each timestep.
While NEST and NEURON were not
run on multiple cores using message passing,
the reference simulator of Nengo
also only uses one CPU core.
The results further suggest that Nengo 2.0's
simulators are faster than Nengo 1.4's simulator.
As a larger-scale example,
we have also benchmarked
the circular convolution model.
Circular convolution is an important test case,
as a significant portion of Spaun's
2.5 million neurons are used to
implement circular convolution.
In this case, only versions of Nengo were tested.
Instead of running each simulation multiple times,
we instead ran the simulator for 10 timesteps
in order to fill various levels of CPU or GPU cache,