NeuronModel

NEURON is a widely used simulator for multi-compartmental neural models. Uncertainpy has support for NEURON models through the NeuronModel class, a subclass of Model. Among others, NeuronModel takes the arguments:

model = un.NeuronModel(path="path/to/neuron_model",
                    interpolate=True,
                    stimulus_start=1000,               # ms
                    stimulus_end=1900)                 # ms

path is the path to the folder where the NEURON model is saved (the location of the mosinit.hoc file). interpolate indicates whether the NEURON model uses adaptive time steps. stimulus_start and stimulus_end denotes the start and end time of any stimulus given to the neuron. NeuronModel loads the NEURON model from mosinit.hoc, sets the parameters of the model, evaluates the model and returns the somatic membrane potential of the neuron. NeuronModel therefore does not require a model function. An example of a NEURON model analysed with Uncertainpy is found in the interneuron example.

If changes are needed to the standard NeuronModel, such as measuring the voltage from other locations than the soma, or recalculate properties after the parameters have been set, the Model class with an appropriate model function should be used instead. Alternatively, NeuronModel can be subclassed and the existing methods customized as required. An example of the later is shown in /examples/bahl/.

API Reference

class uncertainpy.models.NeuronModel(file=u'mosinit.hoc', path=u'', interpolate=True, stimulus_start=None, stimulus_end=None, name=None, ignore=False, run=None, record_from=u'soma', labels=[u'Time (ms)', u'Membrane potential (mV)'], suppress_graphics=True, logger_level=u'info', info={}, **model_kwargs)[source]

Class for Neuron simulator models.

Loads a Neuron simulation, runs it, and measures the voltage in the soma.

Parameters:
  • file (str, optional) – Filename of the Neuron model. Default is "mosinit.hoc".
  • path (str, optional) – Path to the Neuron model. If None, the file is considered to be in the current folder. Default is “”.
  • stimulus_start ({int, float, None}, optional) – The start time of any stimulus given to the neuron model. This is added to the info dictionary. If None, no stimulus_start is added to the info dictionary. Default is None.
  • stimulus_end ({int, float, None}, optional) – The end time of any stimulus given to the neuron model. This is added to the info dictionary. If None, no stimulus_end is added to the info dictionary. 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.
  • name ({None, str}, optional) – Name of the model, if None the model gets the name of the current class. Default is None.
  • ignore (bool, optional) – Ignore the model results when calculating uncertainties, which means the uncertainty is not calculated for the model. Default is False.
  • run ({None, callable}, optional) – A function that implements the model. See the run method for requirements of the function. Default is None.
  • record_from ({str}, optional) – Name of the section in the NEURON model where voltage should be recorded. Default is "soma".
  • 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)", "Membrane potential (mv)"].
  • suppress_graphics (bool, optional) – Suppress all graphics created by the Neuron model. Default is True.
  • 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”.
  • info (dict, optional) – Dictionary added to info. Default is an empty dictionary.
  • **model_kwargs – Any number of arguments passed to the model function when it is run.
Variables:
  • run (uncertainpy.models.Model.run) –
  • labels (list) – 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.
  • 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.
  • suppress_graphics (bool) – Suppress all graphics created by the model.
  • ignore (bool) – Ignore the model results when calculating uncertainties, which means the uncertainty is not calculated for the model. The model results are still postprocessed if a postprocessing is implemented. Default is False.
Raises:

RuntimeError – If no section with name soma is found in the Neuron model.

Notes

Measures the voltage in the section with name soma.

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.
Returns:
  • 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.

See also

uncertainpy.models.Model.run()
Requirements for the model run function.
load_neuron(path, file)[source]

Import neuron and a neuron simulation file.

Parameters:
  • file (str) – Filename of the Neuron model. must be a .hoc file.
  • path (str) – Path to the Neuron model.
Returns:

h – Neurons h object.

Return type:

Neuron object

Raises:

ImportError – If neuron is not installed.

load_python(path, file, name)[source]

Import a Python neuron simulation located in function in path/file with name name.

Parameters:
  • file (str) – Filename of the Neuron model. must be a .hoc file.
  • path (str) – Path to the Neuron model.
  • name (str) – Name of the run function.
Returns:

model – A python function imported from path/file with name name.

Return type:

a run function

See also

uncertainpy.models.Model.run()
Requirements for the model run function.
postprocess(time, values, info)[source]

Postprocessing of the time and results from the Neuron model is generally not needed. The direct model result except the info is returned.

Parameters:
  • time (array_like) – Time values of the Neuron model.
  • values (array_like) – Voltage of the neuron.
  • info (dict) – Dictionary with information needed by features.
Returns:

  • time (array_like) – Time values of the Neuron model.
  • values (array_like) – Voltage of the neuron.

run

Run the model and return time and model result.

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 model, either setting them with Python, or assigning them to the simulator.
Returns:
  • 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.
Raises: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 model must then be run using the parameters given as arguments.

  3. Output. The model function must return at least two objects, the model time (or equivalent, if applicable) and model output. Additionally, any number of optional info objects can be returned. In Uncertainpy, we refer to the time object as time, the model output object as values, and the remaining objects as info. Note that while we refer to these objects as time, values and info in Uncertainpy, it does not matter what you call the objects returned by the run function.

    1. Time (time). The time can be interpreted as the x-axis of the model. It is used when interpolating (see below), and when certain features are calculated. We can return None if the model has no time associated with it.
    2. Model output (values). The model output must either be regular, or it must be possible to interpolate or postprocess the output to a regular form.
    3. Additional info (info). Some of the methods provided by Uncertainpy, such as the later defined model postprocessing, feature preprocessing, and feature calculations, require additional information from the model (e.g., the time a neuron receives an external stimulus). We recommend to use a single dictionary as info object, with key-value pairs for the information, to make debugging easier. Uncertainpy always uses a single dictionary as the info object. Certain features require that specific keys are present in this dictionary.

The model does not need to be implemented in Python, you can use any model/simulator as long as you are able to set the model parameters of the model from the run method Python and return the results from the model into the run method.

If you want to calculate features directly from the original model results, but still need to postprocess the model results to perform the uncertainty quantification, you can implement the postprocessing in the postprocess method.

See also

uncertainpy.features

uncertainpy.features.Features.preprocess
Preprocessing of model results before feature calculation
uncertainpy.model.Model.postprocess
Postprocessing of model result.
run_neuron(**parameters)[source]

Load and run a Neuron simulation from a .hoc file and return the model voltage in soma.

Parameters:**parameters (A number of named arguments (name=value).) – The parameters of the model which are set in Neuron.
Returns:
  • time (array) – Time values of the model.
  • values (array) – Voltage of the neuron. Note that values must either be regular (have the same number of points for different parameters) or be able to be interpolated.
  • info (dictionary) – A dictionary with information needed by features. Efel features require "stimulus_start" and "stimulus_end" as keys, while spiking_features require stimulus_start".
  • info (dictionary) – A dictionary with information needed by features. "stimulus_start" and "stimulus_end" are returned in the info dictionary if they are given as parameters to NeuronModel.

Notes

Efel features require "stimulus_start" and "stimulus_end" as keys, while spiking_features require stimulus_start".

See also

uncertainpy.models.Model.run()
Requirements for the model run function.
run_python(**parameters)[source]

Load and run a Python function that contains a Neuron simulation and return the model result. The Python neuron simulation is located in a function in path/file and name name.

Parameters:**parameters (A number of named arguments (name=value).) – The parameters of the model which are sent to the Python function.
Returns:
  • time (array) – Time values of the model.
  • values (array) – Voltage of the neuron. Note that values must either be regular (have the same number of points for different parameters) or be able to be interpolated.
  • info (dictionary) – A dictionary with information needed by features. If a info dictionary is returned by the model function it is updated with "stimulus_start" and "stimulus_end" if they are given as parameters to NeuronModel. If a info dictionary is not returned, a info dictionary is added as the third return argument.

Notes

Efel features require "stimulus_start" and "stimulus_end" as keys, while spiking_features require stimulus_start".

See also

uncertainpy.models.Model.run()
Requirements for the model run function.
set_parameters(parameters)[source]

Set parameters in the neuron model.

Parameters:parameters (dict) – A dictionary with parameter names as keys and the parameter value as value.
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.

Raises:
  • 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.

Raises:
  • 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.