GeneralNetworkFeatures

GeneralNetworkFeatures implements the preprocessing of spiketrains, and create NEO spiketrains, but does not implement any features in itself. This set of features require that the model returns the simulation end time and a list of spiketrains, which are the times a given neuron spikes. The preprocess() method changes the input given to the feature functions, and as such each network feature function has the following input arguments:

  1. End time of the simulation (end_time).
  2. A list of NEO spiketrains (spiketrains).

API Reference

class uncertainpy.features.GeneralNetworkFeatures(new_features=None, features_to_run=u'all', interpolate=None, labels={}, units=None, logger_level=u'info')[source]

Class for creating NEO spiketrains from a list of spiketrains, for network models. The model must return the simulation end time and a list of spiketrains.

Parameters:
  • new_features ({None, callable, list of callables}) – The new features to add. The feature functions have the requirements stated in reference_feature. If None, no features are added. Default is None.

  • features_to_run ({“all”, None, str, list of feature names}, optional) – Which features to calculate uncertainties for. If "all", the uncertainties are calculated for all implemented and assigned features. If None, or an empty list [], no features are calculated. If str, only that feature is calculated. If list of feature names, all the listed features are calculated. Default is "all".

  • new_utility_methods ({None, list}, optional) – A list of new utility methods. All methods in this class that is not in

    the list of utility methods, is considered to be a feature. Default is None.

    interpolate : {None, “all”, str, list of feature names}, optional

    Which features are irregular, meaning they have a varying number of time points between evaluations. An interpolation is performed on each irregular feature to create regular results. If "all", all features are interpolated. If None, or an empty list, no features are interpolated. If str, only that feature is interpolated. If list of feature names, all listed features are interpolated. Default is None.

  • labels (dictionary, optional) – A dictionary with key as the feature name and the value as a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

    new_labels = {"0d_feature": ["x-axis"],
                  "1d_feature": ["x-axis", "y-axis"],
                  "2d_feature": ["x-axis", "y-axis", "z-axis"]
                 }
    
  • units ({None, Quantities unit}, optional) – The Quantities unit of the time in the model. If None, ms is used. The default is None.

  • 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 is performed. Default logger level is “info”.

Variables:
  • features_to_run (list) – Which features to calculate uncertainties for.
  • interpolate (list) – A list of irregular features.
  • utility_methods (list) – A list of all utility methods implemented. All methods in this class that is not in the list of utility methods is considered to be a feature.
  • labels (dictionary) – Labels for the axes of each feature, used when plotting.

Notes

All features in this set of features take the following input arguments:

simulation_end : float
The simulation end time
neo_spiketrains : list
A list of Neo spiketrains.

The model must return:

simulation_end : float
The simulation end time
spiketrains : list
A list of spiketrains, each spiketrain is a list of the times when a given neuron spikes.
Raises:ImportError – If neo or quantities is not installed.

See also

GeneralNetworkFeatures.preprocess

GeneralNetworkFeatures.reference_feature
reference_feature showing the requirements of a feature function.
add_features(new_features, labels={})

Add new features.

Parameters:
  • new_features ({callable, list of callables}) – The new features to add. The feature functions have the requirements stated in reference_feature.

  • labels (dictionary, optional) – A dictionary with the labels for the new features. The keys are the feature function names and the values are a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

    new_labels = {"0d_feature": ["x-axis"],
                  "1d_feature": ["x-axis", "y-axis"],
                  "2d_feature": ["x-axis", "y-axis", "z-axis"]
                 }
    
Raises:

TypeError – Raises a TypeError if new_features is not callable or list of callables.

Notes

The features added are not added to features_to_run. features_to_run must be set manually afterwards.

See also

uncertainpy.features.Features.reference_feature()
reference_feature showing the requirements of a feature function.
calculate_all_features(*model_results)

Calculate all implemented features.

Parameters:*model_results – Variable length argument list. Is the values that model.run() returns. By default it contains time and values, and then any number of optional info values.
Returns:results – A dictionary where the keys are the feature names and the values are a dictionary with the time values time and feature results on values, on the form {"time": t, "values": U}.
Return type:dictionary
Raises:TypeError – If feature_name is a utility method.

Notes

Checks that the feature returns two values.

See also

uncertainpy.features.Features.calculate_feature()
Method for calculating a single feature.
calculate_feature(feature_name, *preprocess_results)

Calculate feature with feature_name.

Parameters:
  • feature_name (str) – Name of feature to calculate.
  • *preprocess_results – The values returned by preprocess. These values are sent as input arguments to each feature. By default preprocess returns the values that model.run() returns, which contains time and values, and then any number of optional info values. The implemented features require that info is a single dictionary with the information stored as key-value pairs. Certain features require specific keys to be present.
Returns:

  • time ({None, numpy.nan, array_like}) – Time values, or equivalent, of the feature, if no time values returns None or numpy.nan.
  • values (array_like) – The feature results, values must either be regular (have the same number of points for different paramaters) or be able to be interpolated.

Raises:

TypeError – If feature_name is a utility method.

See also

uncertainpy.models.Model.run()
The model run method
calculate_features(*model_results)

Calculate all features in features_to_run.

Parameters:*model_results – Variable length argument list. Is the values that model.run() returns. By default it contains time and values, and then any number of optional info values.
Returns:results – A dictionary where the keys are the feature names and the values are a dictionary with the time values time and feature results on values, on the form {"time": time, "values": values}.
Return type:dictionary
Raises:TypeError – If feature_name is a utility method.

Notes

Checks that the feature returns two values.

See also

uncertainpy.features.Features.calculate_feature()
Method for calculating a single feature.
features_to_run

Which features to calculate uncertainties for.

Parameters:new_features_to_run ({“all”, None, str, list of feature names}) – Which features to calculate uncertainties for. If "all", the uncertainties are calculated for all implemented and assigned features. If None, or an empty list , no features are calculated. If str, only that feature is calculated. If list of feature names, all listed features are calculated. Default is "all".
Returns:A list of features to calculate uncertainties for.
Return type:list
implemented_features()

Return a list of all callable methods in feature, that are not utility methods, does not starts with “_” and not a method of a general python object.

Returns:A list of all callable methods in feature, that are not utility methods.
Return type:list
interpolate

Features that require an interpolation.

Which features are interpolated, meaning they have a varying number of time points between evaluations. An interpolation is performed on each interpolated feature to create regular results.

Parameters:new_interpolate ({None, “all”, str, list of feature names}) – If "all", all features are interpolated. If None, or an empty list, no features are interpolated. If str, only that feature is interpolated. If list of feature names, all listed features are interpolated. Default is None.
Returns:A list of irregular features to be interpolated.
Return type:list
labels

Labels for the axes of each feature, used when plotting.

Parameters:

new_labels (dictionary) – A dictionary with key as the feature name and the value as a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

new_labels = {"0d_feature": ["x-axis"],
              "1d_feature": ["x-axis", "y-axis"],
              "2d_feature": ["x-axis", "y-axis", "z-axis"]
             }
preprocess(simulation_end, spiketrains)[source]

Preprossesing of the simulation end time simulation_end and spiketrains spiketrains from the model, before the features are calculated.

Parameters:
  • simulation_end (float) – The simulation end time
  • spiketrains (list) – A list of spiketrains, each spiketrain is a list of the times when a given neuron spikes.
Returns:

  • simulation_end (float) – The simulation end time
  • neo_spiketrains (list) – A list of Neo spiketrains.

Raises:

ValueError – If simulation_end is np.nan or None.

Notes

This preprocessing makes it so all features get the input simulation_end and spiketrains.

See also

uncertainpy.models.Model.run()
The model run method
reference_feature(simulation_end, neo_spiketrains)[source]

An example of an GeneralNetworkFeature. The feature functions have the following requirements, and the given parameters must either be returned by model.run or features.preprocess.

Parameters:
  • simulation_end (float) – The simulation end time
  • neo_spiketrains (list) – A list of Neo spiketrains.
Returns:

  • time ({None, numpy.nan, array_like}) – Time values, or equivalent, of the feature, if no time values return None or numpy.nan.
  • values (array_like) – The feature results, values. Returns None if there are no feature results and that evaluation are disregarded.

See also

uncertainpy.features.GeneralSpikingFeatures.preprocess()
The GeneralSpikingFeatures preprocess method.
uncertainpy.models.Model.run()
The model run method
validate(feature_name, *feature_result)

Validate the results from calculate_feature.

This method ensures each returns time, values.

Parameters:
  • model_results – Any type of model results returned by run.
  • feature_name (str) – Name of the feature, to create better error messages.
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_feature : {None, numpy.nan, array_like}

    Time values, or equivalent, of the feature, if no time values return None or numpy.nan.

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

    The feature results, values must either be regular (have the same number of points for different paramaters) or be able to be interpolated. If there are no feature results return None or numpy.nan instead of values and that evaluation are disregarded.