neurotools.stats.density module
Functions for working with probability densities.
- neurotools.stats.density.kdepeak(x, x_grid=None)[source]
Convenience wrapper for scipy.stats.gaussian_kde,
- Parameters:
x (1D np.float32) – List of samples from distribution
- Returns:
grid (1D np.float32) – List of points that the KDE-smoothed density is evaluated at
kde (1D np.float32) – KDE smoothed density
- neurotools.stats.density.knn_1d_density(x, k=10, eps=0.01, pad=100, final=None)[source]
Uses local K nearest neighbors to estimate a density and center of mass at each point in a distribution. Returns a local density estimator in units of 1/input_units. For example, if a sequence of times in seconds is provided, the result is an estimate of the continuous time intensity function in units of Hz.
- Parameters:
x (ndarray) – List of points to model
k (integer) – Number of nearest neighbors to use in local density estimate Default is 10
eps (number) – Small correction factor to avoid division by zero
pad (positive int, default 100) – Number of time-points to reflect for padding
final (scalar) – Last time-point for which to estimate density. Defaults to none, in which case the time of the last spike will be used.
- Returns:
centers (ndarray) – Point location of density estimates
density – Density values at locations of centers
- neurotools.stats.density.adaptive_density_grid(grid, x, k=10, eps=0.01, fill=None, kind='linear')[source]
Follow the knn_1d_density estimation with interpolation of the density on a grid
- Parameters:
grid
x
k (int, default 10)
eps (float, default 0.01)
fill (assign missing values) – if not given will fill with the mean rate
kind (string, default ‘linear’) – Interpolation method parameter for scipy.interpolate.interp1d
- Returns:
Probability density on grid
- Return type:
y