# NestModel¶

NEST is a simulator for large networks of spiking neurons. NEST models are supported through the NestModel class, another subclass of Model:

model = un.NestModel(run=nest_model_function)


NestModel requires the model function to be specified through the run argument, unlike NeuronModel. The NEST model function has the same requirements as a regular model function, except it is restricted to return only two objects: the final simulation time (denoted simulation_end), and a list of spike times for each neuron in the network, which we refer to as spiketrains (denoted spiketrains).

A spike train returned by a NEST model is a set of irregularly spaced time points where a neuron fired a spike. NEST models therefore require postprocessing to make the model output regular. Such a postprocessing is provided by the implemented postprocess() method, which converts a spiketrain to a list of zeros (no spike) and ones (a spike) for each time step in the simulation. For example, if a NEST simulation returns the spiketrain [0, 2, 3.5], it means the neuron fired three spikes occurring at $$t= 0, 2, \text{and } 3.5$$ ms. If the simulation have a time resolution of $$0.5$$ ms and ends after $$4$$ ms, NestModel.postprocess returns the postprocessed spiketrain [1, 0, 0, 0, 1, 0, 0, 1, 0], and the postprocessed time array [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4]. The final uncertainty quantification of a NEST network therefore predicts the probability for a spike to occur at any specific time point in the simulation. An example on how to use NestModel is found in the Brunel exampel.

## API Reference¶

class uncertainpy.models.NestModel(run=None, interpolate=False, ignore=False, labels=[u'Time (ms)', u'Neuron nr', u'Spiking probability'], logger_level=u'info', **model_kwargs)[source]

Class for NEST simulator models.

The run method must either be implemented or set to a function, and is responsible for running the NEST model.

Parameters: run ({None, function}, optional) – A function that implements the model. See Note for requirements of the function. Default is None. interpolate (bool, optional) – True if the model is irregular, meaning it has a varying number of return values between different model evaluations, and an interpolation of the results is performed. Default is False. ignore (bool, optional) – Ignore the model results when calculating uncertainties, which means the uncertainty is not calculated for the model. Default is False. labels (list, optional) – A list of label names for the axes when plotting the model. On the form ["x-axis", "y-axis", "z-axis"], with the number of axes that is correct for the model output. Default is ["Time (ms)", "Neuron nr", "Spiking probability"]. logger_level ({“info”, “debug”, “warning”, “error”, “critical”, None}, optional) – Set the threshold for the logging level. Logging messages less severe than this level is ignored. If None, no logging to file is performed. Default logger level is “info”. **model_kwargs – Any number of arguments passed to the model function when it is run. run (uncertainpy.models.Model.run) – labels (list, optional) – A list of label names for the axes when plotting the model. interpolate (bool) – True if the model is irregular, meaning it has a varying number of return values between different model evaluations, and an interpolation of the results is performed. Default is False. ignore (bool, optional) – Ignore the model results when calculating uncertainties, which means the uncertainty is not calculated for the model. The model results are still postprocessed. Default is False. ImportError – If nest is not installed.
evaluate(**parameters)

Run the model with parameters and default model_kwargs options, and validate the result.

Parameters: **parameters (A number of named arguments (name=value).) – The parameters of the model. These parameters must be assigned to the model, either setting them with Python, or assigning them to the simulator. time ({None, numpy.nan, array_like}) – Time values of the model, if no time values returns None or numpy.nan. values (array_like) – Result of the model. Note that values myst either be regular (have the same number of points for different paramaters) or be able to be interpolated. info, optional – Any number of info objects that is passed on to feature calculations. It is recommended to use a single dictionary with the information stored as key-value pairs. This is what the implemented features requires, as well as require that specific keys to be present.

uncertainpy.models.Model.run()
Requirements for the model run function.
postprocess(simulation_end, spiketrains)[source]

Postprocessing of the spiketrains from a Nest model.

For each neuron, convert a spiketrain to a list of the probability for a spike at each timestep, as well as creating a time array. For each timestep in the simulation the result is 0 if there is no spike and 1 if there is a spike.

Parameters: simulation_end ({int, float}) – The final simulation time. spiketrains (list) – A list of spike trains for each neuron. time (array) – A time array of all time points in the Nest simulation. spiketrains (list) – A list of the probability for a spike at each timestep, for each neuron.

Example

In a simulation that gives the spiketrain [0, 2, 3], with a time resolution of 0.5 ms and that ends after 4 ms, the resulting spike train become: [1, 0, 0, 0, 1, 0, 1, 0, 0].

run

Run a Nest model and return the final simulation time and the spiketrains.

This method must either be implemented or set to a function and is responsible for running the model. See Notes for requirements.

Parameters: **parameters (A number of named arguments (name=value).) – The parameters of the model. These parameters must be assigned to the NEST model. simulation_end ({int, float}) – The final simulation time. spiketrains (list) – A list of spike trains for each neuron. NotImplementedError – If no run method have been implemented or set to a function.

Notes

The run method must either be implemented or set to a function. Both options have the following requirements:

1. Input. The model function takes a number of arguments which define the uncertain parameters of the model.

2. Run the model. The NEST model must then be run using the parameters given as arguments.

3. Output. The model function must return:

1. Time (simulation_end). The final simulation time of the NEST model.
2. Model output (spiketrains). A list if spike trains from each recorded neuron.

The model results simulation_end and spiketrains are used to calculate the features, and is postprocessed to create a regular result before the calculating the uncertainty of the model.

uncertainpy.model.Model.postprocess

set_parameters(**parameters)

Set all named arguments as attributes of the model class.

Parameters: **parameters (A number of named arguments (name=value).) – All set as attributes of the class.
validate_postprocess(postprocess_result)

Validate the results from postprocess.

This method ensures that postprocess returns time and values.

Parameters: model_results – Any type of postprocessed model results returned by postprocess. ValueError – If the postprocessed model result does not fit the requirements. TypeError – If the postprocessed model result does not fit the requirements.

Notes

Tries to verify that time and values are returned from postprocess. postprocess must return two objects on the format: return time, values, where:

• time_postprocessed : {None, numpy.nan, array_like}.

The first object is the postprocessed time (or equivalent) of the model. We can return None if the model has no time. Note that the automatic interpolation of the postprocessed time can only be performed if a postprocessed time is returned (if an interpolation is required).

• values_postprocessed : array_like.

The second object is the postprocessed model output.

Both of these must be regular or on a form that can be interpolated.

validate_run(model_result)

Validate the results from run.

This method ensures run returns time, values, and optional info objects.

Parameters: model_results – Any type of model results returned by run. ValueError – If the model result does not fit the requirements. TypeError – If the model result does not fit the requirements.

Notes

Tries to verify that at least, time and values are returned from run. model_result should follow the format: return time, values, info_1, info_2, .... Where:

• time : {None, numpy.nan, array_like}. Time values of the model. If no time values it should return None or numpy.nan.
• values : array_like Result of the model.
• info, optional. Any number of info objects that is passed on to feature calculations. It is recommended to use a single dictionary with the information stored as key-value pairs. This is what the implemented features requires, as well as require that specific keys to be present.