spiketools.stats.shuffle.shuffle_bins¶
- spiketools.stats.shuffle.shuffle_bins(spikes, bin_width_range=[0.5, 7], n_shuffles=1000, start_time=0)[source]¶
Shuffle data with circular shuffles of randomly sized bins of the spike train.
- Parameters:
- spikes1d array
Spike times, in seconds.
- bin_width_rangelist of [float, float], optional, default
Range of bin widths in seconds from which bin sizes are randomly selected.
- n_shufflesint, optional, default: 1000
The number of shuffles to create.
- start_timefloat, optional
The start time of the input spikes, used to set the time values of the shuffled outputs.
- Returns:
- shuffled_spikes2d array
Shuffled spike times.
Notes
This approach shuffles spikes by creating bins of varying length and then circularly shuffling within those bins. This should disturb the spike to spike structure in a dynamic way while also conserving structure uniformly across the distribution of lags. This function can be a little slow when running a lot. The main holdup is np.roll (unclear if / how to optimize). The next biggest hold up is converting the spike train to spike times. This shuffling process is very dependent on the bin_width_range argument. It is recommended that bin_width_range[1] > 3, and that the difference between the two values of bin_width_range is at least 1.
Examples
Shuffle spike times using the circular bin method:
>>> from spiketools.sim.times import sim_spiketimes >>> spikes = sim_spiketimes(5, 30, 'poisson') >>> shuffled_spikes = shuffle_bins(spikes, bin_width_range=[3, 4], n_shuffles=5)