NetworkFeatures¶
NetworkFeatures
contains a set of features
relevant for the output of network models and are calculated using the
Elephant software.
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 implemented features are:
average_firing_rate
– Mean firing rate (for a single recorded neuron).instantaneous_rate
– Instantaneous firing rate (averaged over all recorded neurons within a small time window).mean_isi
– Average interspike interval (averaged over all recorded neurons).cv
– Coefficient of variation of the interspike interval (for a single recorded neuron).average_cv
– average coefficient of variation of the interspike interval (averaged over all recorded neurons).local_variation
– Local variation (variability of interspike intervals for a single recorded neuron).average_local_variation
– Mean local variation (variability of interspike intervals averaged over all recorded neurons).fanofactor
– Fanofactor (variability of spiketrains).victor_purpura_dist
– Victor purpura distance (spiketrain dissimilarity between two recorded neurons).van_rossum_dist
– Van rossum distance (spiketrain dissimilarity between two recorded neurons).binned_isi
– Histogram of the interspike intervals (for all recorded neurons).corrcoef
– Pairwise Pearson’s correlation coefficients (between the spiketrains of two recorded neurons).covariance
– Covariance (between the spiketrains of two recorded neurons).
The use of the NetworkFeatures
class in Uncertainpy follows the
same logic as the use of the other feature classes,
and custom features can easily be included.
As with SpikingFeatures,
NetworkFeatures
implements a preprocess()
method.
This preprocess
returns the following objects:
- End time of the simulation (
end_time
). - A list of NEO spiketrains (
spiketrains
).
Each feature function therefore require the same objects as input arguments.
Note that a info
object is not used.
API Reference¶
-
class
uncertainpy.features.
NetworkFeatures
(new_features=None, features_to_run=u'all', interpolate=None, labels={}, units=None, instantaneous_rate_nr_samples=50, isi_bin_size=1, corrcoef_bin_size=1, covariance_bin_size=1, logger_level=u'info')[source]¶ Network features of a model result, works with all models that 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"
.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.
instantaneous_rate_nr_samples (int) – The number of samples used to calculate the instantaneous rate. Default is 50.
isi_bin_size (int) – The size of each bin in the
binned_isi
method. Default is 1.corrcoef_bin_size (int) – The size of each bin in the
corrcoef
method. Default is 1.covariance_bin_size (int) – The size of each bin in the
covariance
method. Default is 1.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 to be interpolated.
- 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.
- logger (logging.Logger) – Logger object responsible for logging to screen or file.
- instantaneous_rate_nr_samples (int) – The number of samples used to calculate the instantaneous rate. Default is 50.
- isi_bin_size (int) – The size of each bin in the
binned_isi
method. Default is 1. - corrcoef_bin_size (int) – The size of each bin in the
corrcoef
method. Default is 1. - covariance_bin_size (int) – The size of each bin in the
covariance
method. Default is 1.
Notes
Implemented features are:
cv average_cv average_isi, local_variation mean local_variation average_firing_rate instantaneous_rate fanofactor van_rossum_dist victor_purpura_dist binned_isi corrcoef covariance 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 elephant or quantities is not installed.See also
uncertainpy.features.Features.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.
-
average_cv
(simulation_end, spiketrains)[source]¶ Calculate the average coefficient of variation.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- values (float) – The average coefficient of variation of each spiketrain.
-
average_firing_rate
(simulation_end, spiketrains)[source]¶ Calculate the mean firing rate.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- average_firing_rate (float) – The mean firing rate of all neurons.
-
average_isi
(simulation_end, spiketrains)[source]¶ Calculate the average interspike interval (isi) variation for each neuron.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- average_isi (float) – The average interspike interval.
-
average_local_variation
(simulation_end, spiketrains)[source]¶ Calculate the average of the local variation.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- average_local_variation (float) – The average of the local variation for each spiketrain.
-
binned_isi
(simulation_end, spiketrains)[source]¶ Calculate a histogram of the interspike interval.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (array) – The center of each bin.
- binned_isi (array) – The binned interspike intervals.
-
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 thatmodel.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.
-
corrcoef
(simulation_end, spiketrains)[source]¶ Calculate the pairwise Pearson’s correlation coefficients.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- values (2D array) – The pairwise Pearson’s correlation coefficients.
-
covariance
(simulation_end, spiketrains)[source]¶ Calculate the pairwise covariances.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- values (2D array) – The pairwise covariances.
-
cv
(simulation_end, spiketrains)[source]¶ Calculate the coefficient of variation for each neuron.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- values (array) – The coefficient of variation for each spiketrain.
-
fanofactor
(simulation_end, spiketrains)[source]¶ Calculate the fanofactor.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- fanofactor (float) – The fanofactor.
-
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
-
instantaneous_rate
(simulation_end, spiketrains)[source]¶ Calculate the mean instantaneous firing rate.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (array) – Time of the instantaneous firing rate.
- instantaneous_rate (float) – The instantaneous firing rate.
-
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"] }
-
local_variation
(simulation_end, spiketrains)[source]¶ Calculate the measure of local variation.
Parameters: - simulation_end (float) – The simulation end time.
- neo_spiketrains (list) – A list of Neo spiketrains.
Returns: - time (None)
- local_variation (list) – The local variation for each spiketrain.
-
preprocess
(simulation_end, spiketrains)¶ 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)¶ An example of an GeneralNetworkFeature. The feature functions have the following requirements, and the given parameters must either be returned by
model.run
orfeatures.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.
- model_results – Any type of model results returned by