Skip to content

[Bug] Incorrect Output in time_histogram for Single Unit Spike Train with output='rate' #648

@utwrd

Description

@utwrd

Description
When using time_histogram with output='rate', the result differs between using a single spike train (time_histogram(spiketrain, output='rate')) and wrapping it in a list (time_histogram([spiketrain], output='rate')). The correct result is obtained with the latter (time_histogram([spiketrain], output='rate')), but this discrepancy is confusing when we want to calculate the firing rate for each unit.

Expected Behavior
Both calls to time_histogram should yield the same result, regardless of whether a single spiketrain or a list of one spiketrain is provided.

Actual Behavior
time_histogram(spiketrain, output='rate') produces an incorrect result, whereas time_histogram([spiketrain], output='rate') provides the correct output. This discrepancy is due to how the function calculates the sample length based on the input type.

Cause
This issue arises from a condition in statistics.py, line 1191, where len(spiketrains) is used. When spiketrains is not provided as a list, len(spiketrains) mistakenly returns the length of the spike train sample rather than counting the number of spike trains, leading to an incorrect rate calculation.

Suggested Solution
To fix this issue, modify the code to ensure that spiketrains is always treated as a list, even if it contains only one unit. This can be done by wrapping spiketrain in a list if it is not already, ensuring consistent behavior for both single and multiple spike train inputs.

Steps to Reproduce

  1. Create a single spike train, spiketrain.
  2. Run time_histogram(spiketrain, output='rate') and observe the incorrect result.
  3. Wrap spiketrain in a list and run time_histogram([spiketrain], output='rate').
  4. Compare the results; the correct output is produced only when spiketrain is wrapped in a list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorenhancementEditing an existing module, improving something

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions