ANNarchy 5.0.0
  • ANNarchy
  • Installation
  • Tutorial
  • Manual
  • Notebooks
  • Reference

  • ANNarchy
  • Core components
    • Network
    • Population
    • Projection
    • Monitor
    • PopulationView
    • Dendrite
  • Neuron and Synapse models
    • Neuron
    • Synapse
    • Parameter
    • Variable
    • Creating
    • Pruning
    • Constant
  • Neuron models
    • LeakyIntegrator
    • Izhikevich
    • IF_curr_exp
    • IF_cond_exp
    • IF_curr_alpha
    • IF_cond_alpha
    • HH_cond_exp
    • EIF_cond_alpha_isfa_ista
    • EIF_cond_exp_isfa_ista
  • Synapse models
    • Hebb
    • Oja
    • IBCM
    • STP
    • STDP
  • Inputs
    • InputArray
    • TimedArray
    • PoissonPopulation
    • TimedPoissonPopulation
    • SpikeSourceArray
    • HomogeneousCorrelatedSpikeTrains
    • CurrentInjection
    • DecodingProjection
    • ImagePopulation
    • VideoPopulation
  • Random Distributions
    • Uniform
    • DiscreteUniform
    • Normal
    • LogNormal
    • Exponential
    • Gamma
    • Binomial
  • Functions
    • add_function
    • functions
  • Callbacks
    • every
  • Utilities
    • report
    • timeit
    • sparse_random_matrix
    • sparse_delays_from_weights
    • magic_network
  • Convolution
    • Convolution
    • Pooling
    • Transpose
    • Copy
  • BOLD monitoring
    • BoldMonitor
    • BoldModel
    • balloon_RN
    • balloon_RL
    • balloon_CN
    • balloon_CL
    • balloon_maith2021
    • balloon_two_inputs
  • Tensorboard logging
    • Logger
  • ANN-to-SNN conversion
    • ANNtoSNNConverter
  • DEPRECATED Top-level API
    • setup
    • compile
    • clear
    • reset
    • set_seed
    • get_population
    • get_projection
    • populations
    • projections
    • monitors
    • simulate
    • simulate_until
    • step
    • enable_learning
    • disable_learning
    • get_time
    • set_time
    • get_current_step
    • set_current_step
    • dt
    • save
    • load
    • save_parameters
    • load_parameters
    • callbacks_enabled
    • disable_callbacks
    • enable_callbacks
    • clear_all_callbacks

On this page

  • Monitor
    • Attributes
    • Methods
      • get
      • start
      • pause
      • resume
      • stop
      • reset
      • save
      • times
      • raster_plot
      • histogram
      • inter_spike_interval
      • coefficient_of_variation
      • mean_fr
      • smoothed_rate
      • population_rate

Monitor

Monitor(
    self,
    obj,
    variables=[],
    period=None,
    period_offset=None,
    start=True,
    name=None,
    net_id=0,
)

Object allowing to record variables from Population, PopulationView, Dendrite or Projection instances.

This object should not be created directly, but returned by Network.monitor():

m = net.monitor(pop, ['g_exc', 'v', 'spike'], period=10.0, start=False)

Monitors are started by default after compile(). You can control their recording behavior with the start(), stop(), pause() and resume() methods.

m.start() # Start recording
net.simulate(T)
m.pause() # Pause recording
net.simulate(T)
m.resume() # Resume recording
net.simulate(T)

data = m.get() # Get the data

For spiking networks recording 'spike', some utilities allow to easily compute raster plots /other statistics or mean firing rates over time/neuron axes:

spikes = m.get('spike')

t, n = m.raster_plot(spikes)
histo = m.histogram()
isi = m.inter_spike_interval(spikes)
cov = m.coefficient_of_variation(spikes)
fr = m.mean_fr(spikes)
r = m.smoothed_rate(spikes, smooth=100.)
r_mean = m.population_rate(spikes, smooth=100.)

Attributes

Name Description
period Period of recording in milliseconds.
period_offset Offset of recording within a period, in milliseconds.
variables Current list of recorded variables.

Methods

Name Description
get Returns the recorded variables and empties the buffer.
start Starts recording the variable.
pause Pauses the recording.
resume Resumes the recording.
stop Stops the recording.
reset Reset the monitor to its initial state.
save Saves the recorded variables as a Numpy array (first dimension is time, second is neuron index).
times Returns the start and stop times (in ms) of the recorded variables as a dictionary.
raster_plot Returns two numpy arrays representing for each recorded spike 1) the spike times and 2) the ranks of the neurons.
histogram Returns a histogram for the recorded spikes in the population.
inter_spike_interval Computes the inter-spike intervals (ISI) for the recorded spikes in the population.
coefficient_of_variation Computes the coefficient of variation for the recorded spikes in the population.
mean_fr Computes the mean firing rate in the population during the recordings.
smoothed_rate Computes the smoothed firing rate of the recorded spiking neurons.
population_rate Computes a smoothed firing rate for the population of recorded neurons.

get

get(variables=None, keep=False, reshape=False, force_dict=False)

Returns the recorded variables and empties the buffer.

The recorded data is returned as a Numpy array (first dimension is time, second is neuron index).

If a single variable name is provided, the recorded values for this variable are directly returned as an array. If a list is provided or the argument left empty, a dictionary with all recorded variables is returned.

The spike variable of a population will be returned as a dictionary of lists, where the key is the neuron index, and the list contains the spike times (in steps; multiply by net.dt to get spike times in milliseconds) for each recorded neurons.

Parameters

Name Type Description Default
variables str | list[str] (list of) variables. By default, a dictionary with all variables is returned. None
keep bool defines if the content in memory for each variable should be kept (default: False). False
reshape bool transforms the second axis of the array to match the population’s geometry (default: False). False

start

start(variables=None, period=None)

Starts recording the variable.

It is called automatically after Network.compile() if the flag start=False was not passed to the constructor.

Parameters

Name Type Description Default
variables list single variable name or list of variable names to start recording (default: the variables argument passed to the constructor). None
period float delay in ms between two recording (default: dt). Not valid for the spike variable of a Population(View). None

pause

pause()

Pauses the recording.

resume

resume()

Resumes the recording.

stop

stop()

Stops the recording.

Warning: This will delete the content of the C++ object and all data not previously retrieved is lost.

reset

reset()

Reset the monitor to its initial state.

save

save(filename, variables=None, keep=False, reshape=False, force_dict=False)

Saves the recorded variables as a Numpy array (first dimension is time, second is neuron index).

If a single variable name is provided, the recorded values for this variable are directly saved. If a list is provided or the argument left empty, a dictionary with all recorded variables is saved.

The spike variable of a population will be returned as a dictionary of lists containing the spike times (in steps; multiply by net.dt to get spike times in milliseconds) for each recorded neurons.

Parameters

Name Type Description Default
filename str name of the save file. required
variables str | list[str] (list of) variables. By default, a dictionary with all variables is returned. None
keep bool defines if the content in memory for each variable should be kept (default: False). False
reshape bool transforms the second axis of the array to match the population’s geometry (default: False). False

times

times(variables=None)

Returns the start and stop times (in ms) of the recorded variables as a dictionary.

It should only be called after a call to get(), so that it describes when the variables have been recorded.

Parameters

Name Type Description Default
variables list[str] (list of) variables. By default, the times for all variables is returned. None

raster_plot

raster_plot(spikes=None)

Returns two numpy arrays representing for each recorded spike 1) the spike times and 2) the ranks of the neurons.

Example:

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

t, n = m.raster_plot()
plt.plot(t, n, '.')

or:

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
t, n = m.raster_plot(spikes)
plt.plot(t, n, '.')

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None

histogram

histogram(spikes=None, bins=None, per_neuron=False, recording_window=None)

Returns a histogram for the recorded spikes in the population.

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
histo = m.histogram(spikes)
plt.plot(histo)

Parameters

Name Type Description Default
spikes the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None
bins the bin size in ms (default: dt). None

inter_spike_interval

inter_spike_interval(spikes=None, ranks=None, per_neuron=False)

Computes the inter-spike intervals (ISI) for the recorded spikes in the population.

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
isi = m.inter_spike_interval(spikes)
plt.hist(isi)

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None
ranks list[int] a list of neurons that should be evaluated. By default None, all neurons are evaluated. None
per_neuron bool if set to True, the computed inter-spike intervals are stored per neuron (analog to spikes), otherwise all values are stored in one huge vector (default: False). False

coefficient_of_variation

coefficient_of_variation(spikes=None, ranks=None)

Computes the coefficient of variation for the recorded spikes in the population.

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
cov = m.coefficient_of_variation(spikes)
plt.hist(isi)

:ranks: a list of neurons that should be evaluated. By default (None), all neurons are evaluated.

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None

mean_fr

mean_fr(spikes=None)

Computes the mean firing rate in the population during the recordings.

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
fr = m.mean_fr(spikes)

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None

smoothed_rate

smoothed_rate(spikes=None, smooth=0.0)

Computes the smoothed firing rate of the recorded spiking neurons.

The first axis is the neuron index, the second is time.

m = net.monitor(pop, 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
r = m.smoothed_rate(spikes, smooth=100.)

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). If left empty, get('spike') will be called. Beware: this erases the data from memory. None
smooth float smoothing time constant. Default: 0.0 (no smoothing). 0.0

population_rate

population_rate(spikes=None, smooth=0.0)

Computes a smoothed firing rate for the population of recorded neurons.

This method is faster than calling smoothed_rate and then averaging.

If spikes is left empty, get('spike') will be called. Beware: this erases the data from memory.

Example:

m = net.monitor(P[:1000], 'spike')
net.simulate(1000.0)

spikes = m.get('spike')
r = m.population_rate(spikes, smooth=100.)

Parameters

Name Type Description Default
spikes dict the dictionary of spikes returned by get('spike'). None
smooth float smoothing time constant. Default: 0.0 (no smoothing). 0.0
Projection
PopulationView
 

Copyright Julien Vitay, Helge Ülo Dinkelbach, Fred Hamker