bin_spikes#

torch_brain.utils.bin_spikes(spikes, num_units, bin_size, max_spikes=None, right=True, eps=0.001, dtype=<class 'numpy.int32'>)[source]#

Bins spikes into time bins of size bin_size. If the total time spanned by the spikes is not a multiple of bin_size, the spikes are truncated to the nearest multiple of bin_size. If right is True, the spikes are truncated from the left end of the time series, otherwise they are truncated from the right end.

Notes

  • The number of units cannot be inferred from a subset of spikes, so num_units must be provided explicitly.

  • Floating-point roundoff can cause (end - start) / bin_size to be very close to an integer without being exact (e.g. 9.99999999). The eps parameter is added before flooring to make the bin-count computation numerically robust.

Parameters:
  • spikes (IrregularTimeSeries) – IrregularTimeSeries object containing the spikes.

  • num_units (int) – Number of units in the population.

  • bin_size (float) – Size of the time bins in seconds.

  • max_spikes (Optional[int]) – Maximum number of spikes to include per unit per bin. If None, no clipping is applied.

  • right (bool) – Decide which side gets truncated when duration is not a multiple of bin_size. If True, excess spikes are truncated from the left edge.

  • eps (float) – Small numerical margin used during bin assignment.

  • dtype (dtype) – Data type of the output binned array. (default np.int32)

Return type:

ndarray

Returns:

Binned spike counts with shape (T, N), where T is the number of time bins and N is num_units.