def approximateFiringRate(S,(T_start,T_stop),N_bins):
    """
    Approximate the firing rate of a set of spikes by binning into equispaced
    bins and dividing by the bin width. Smooth with a Gaussian kernel.
    
    TODO: This could be improved with equimass bins as opposed to equispaced bins.
    """
#    assert np.all(S >= T_start), "ERROR: S lies below range [%f, %f]:\n%s" % (T_start,T_stop,str(S))
#    assert np.all(S <= T_stop), "ERROR: S lies above range [%f, %f]:\n%s" % (T_start,T_stop,str(S))
    
    # Bin predicted spikes to achieve firing rate
    bin_edges = np.linspace(T_start,T_stop,N_bins+1)
    bin_width = (T_stop-T_start)/N_bins
    
    # Approximate firing rate. Histogram returns bin counts and edges as tuple.
    # Take only the bin counts
    fr = np.histogram(S,bin_edges, range=(T_start,T_stop))[0] / bin_width
    
    # Number of bins to eval kernel at (must be odd to have point at 0)
    N_smoothing_kernel_bins = 9
    smoothing_kernel_bin_centers = np.linspace(-(N_smoothing_kernel_bins-1)/2*bin_width, 
                                               (N_smoothing_kernel_bins-1)/2*bin_width, 
                                               N_smoothing_kernel_bins
                                               )
    # Evaluate a standard normal pdf at the bin centers. Normalize to one
    # so that we don't change the total area under the firing rate
    smoothing_kernel = np.exp(-0.5*smoothing_kernel_bin_centers**2)
    smoothing_kernel = np.sum(smoothing_kernel) / smoothing_kernel
    
    # Since the kernel is symmetric we don't have to worry about flipping the kernel left/right
    # Before smoothing, pad fr to minimize boundary effects
    l_pad = np.mean(fr[:N_smoothing_kernel_bins])
    r_pad = np.mean(fr[-N_smoothing_kernel_bins:])
    fr_pad = np.hstack((l_pad*np.ones(N_smoothing_kernel_bins),fr,r_pad*np.ones(N_smoothing_kernel_bins)))
    fr_smooth = np.convolve(fr_pad, smoothing_kernel, "same")
    
    # Drop the pad components and keep the center of the convolution
    fr_smooth = fr_smooth[N_smoothing_kernel_bins:-N_smoothing_kernel_bins]
    
    assert np.size(fr_smooth) == N_bins, "ERROR: approximation returned invalid length firing rate"
    
    return fr_smooth
dataset/ETHPy150Open slinderman/pyhawkes/pyhawkes/utils/poisson_process.py/approximateFiringRate/swapped operands of `/`