Monitors are used to record properties of your network. The two most important are SpikeMonitor which records spikes, and StateMonitor which records values of state variables. These objects are just added to the network like a NeuronGroup or Connection.
Implementation note: monitors that record spikes are classes derived from Connection, and overwrite the propagate method to store spikes. If you want to write your own custom spike monitors, you can do the same (or just use SpikeMonitor with a custom function). Monitors that record values are classes derived from NetworkOperation and implement the __call__ method to store values each time the network updates. Custom state monitors are most easily written by just writing your own network operation using the network_operation decorator.
Counts or records spikes from a NeuronGroup
Initialised as one of:
SpikeMonitor(source(,record=True))
SpikeMonitor(source,function=function)
Where:
Has attributes:
For M a SpikeMonitor, you can also write:
Notes:
SpikeMonitor is subclassed from Connection. To define a custom monitor, either define a subclass and rewrite the propagate method, or pass the monitoring function as an argument (function=myfunction, with def myfunction(spikes):...)
Counts spikes from a NeuronGroup
Initialised as:
SpikeCounter(source)
With argument:
Has two attributes:
For a SpikeCounter M you can also write M[i] for the number of spikes counted for neuron i.
Counts spikes from a NeuronGroup
Initialised as:
PopulationSpikeCounter(source)
With argument:
Has one attribute:
Counts or records spikes and state variables at spike times from a NeuronGroup
Initialised as:
StateSpikeMonitor(source, var)
Where:
Has two attributes:
The number of recorded spikes
A time ordered list of tuples (i,t,v) where neuron i fired at time t and the specified variable had value v. If you specify multiple variables, each tuple will be of the form (i,t,v0,v1,v2,...) where the vi are the values corresponding in order to the variables you specified in the var keyword.
And two methods:
Returns an array of the spike times for the whole monitored group, or just for neuron i if specified.
Returns an array of the values of variable var for the whole monitored group, or just for neuron i if specified.
Records the values of a state variable from a NeuronGroup.
Initialise as:
StateMonitor(P,varname(,record=False)
(,when='end)(,timestep=1)(,clock=clock))
Where:
The StateMonitor object has the following properties:
In addition, if M` is a StateMonitor object, you write:
M[i]
for the recorded values of neuron i (if it was specified with the record keyword). It returns a numpy array.
Methods:
Plots the recorded values using pylab. You can specify an index or list of indices, otherwise all the recorded values will be plotted. The graph plotted will have legends of the form name[i] for name the variable name, and i the neuron index. If cmap is specified then the colours will be set according to the matplotlib colormap cmap. refresh specifies how often (in simulation time) you would like the plot to refresh. Note that this will only work if pylab is in interactive mode, to ensure this call the pylab ion() command. If you are using the refresh option, showlast specifies a fixed time window to display (e.g. the last 100ms). If you are using more than one realtime monitor, only one of them needs to issue a redraw command, therefore set redraw=False for all but one of them.
Note that with some IDEs, interactive plotting will not work with the default matplotlib backend, try doing something like this at the beginning of your script (before importing brian):
import matplotlib
matplotlib.use('WXAgg')
You may need to experiment, try WXAgg, GTKAgg, QTAgg, TkAgg.
Inserts spikes into recorded traces (for plotting). State values at spike times are replaced with the given value (peak value of spike).
Monitors multiple state variables of a group
This class is a container for multiple StateMonitor objects, one for each variable in the group. You can retrieve individual StateMonitor objects using M[name] or retrieve the recorded values using M[name, i] for neuron i.
Initialised with a group G and a list of variables vars. If vars is omitted then all the variables of G will be recorded. Any additional keyword argument used to initialise the object will be passed to the individual StateMonitor objects (e.g. the when keyword).
Methods:
Attributes:
Usage:
G = NeuronGroup(N, eqs, ...)
M = MultiStateMonitor(G, record=True)
...
run(...)
...
plot(M['V'].times, M['V'][0])
figure()
for name, m in M.iteritems():
plot(m.times, m[0], label=name)
legend()
show()
StateMonitor that records only the most recent fixed amount of time.
Works in the same way as a StateMonitor except that it has one additional initialiser keyword duration which gives the length of time to record values for, the record keyword defaults to True instead of False, and there are some different or additional attributes:
The __getitem__ method also returns values in sorted order.
To plot, do something like:
plot(M.times, M.values[:, i])
Records spikes to an AER file
Initialised as:
FileSpikeMonitor(source, filename[, record=False])
Does everything that a SpikeMonitor does except ONLY records the spikes to the named file in AER format, during the simulation. These spikes can then be reloaded via the io.load_aer function and used later into a SpikeGeneratorGroup.
It is about three times faster than the FileSpikeMonitor and creates smaller files. On the other hand those files are not human-readable because they are in binary format.
Has one additional method:
Records spikes to a file
Initialised as:
FileSpikeMonitor(source, filename[, record=False])
Does everything that a SpikeMonitor does except also records the spikes to the named file. note that spikes are recorded as an ASCII file of lines each of the form:
i, t
Where i is the neuron that fired, and t is the time in seconds.
Has one additional method:
Records the interspike interval histograms of a group.
Initialised as:
ISIHistogramMonitor(source, bins)
Has properties:
This object can be passed directly to the plotting function hist_plot().
Monitors and stores the (time-varying) population rate
Initialised as:
PopulationRateMonitor(source,bin)
Records the average activity of the group for every bin.
Properties:
van Rossum spike train metric. From M. van Rossum (2001): A novel spike distance (Neural Computation).
Compute the van Rossum distance between every spike train from the source population.
Arguments:
Has one attribute:
Coincidence counter class.
Counts the number of coincidences between the spikes of the neurons in the network (model spikes), and some user-specified data spike trains (target spikes). This number is defined as the number of target spikes such that there is at least one model spike within +- delta, where delta is the half-width of the time window.
Initialised as:
cc = CoincidenceCounter(source, data, delta = 4*ms)
with the following arguments:
The list of spike times. Several spike trains can be passed in the following way. Define a single 1D array data which contains all the target spike times one after the other. Now define an array spiketimes_offset of integers so that neuron i should be linked to target train: data[spiketimes_offset[i]], data[spiketimes_offset[i]+1], etc.
It is essential that each spike train with the spiketimes array should begin with a spike at a large negative time (e.g. -1*second) and end with a spike that is a long time after the duration of the run (e.g. duration+1*second).
Has three attributes:
Records the histogram of a state variable from a NeuronGroup.
Initialise as:
StateHistogramMonitor(P,varname,range(,period=1*ms)(,nbins=20))
Where:
The StateHistogramMonitor object has the following properties:
In addition, if M` is a StateHistogramMonitor object, you write:
M[i]
for the histogram of neuron i.