RatInABox
RatInABox copied to clipboard
Improving how RatInABox estimates and facilitates rate map estimation from observed data
Currently the way RatInABox estimates rate maps is using np.histogram2d. There are two main issues:
- This is not massively principled - it might be cleaner to do a proper KDE approach to rate map estimation.
- There is no way to export rate maps.
neurons.plot_rate_map()will visualise them but there is no way for users to cleanly export this.
The current best way for this would be for users to do something janky like:
rate_timeseries = np.array(neurons.history['firingrate']).T
pos = np.array(ag.history['pos'])
bin_size = 0.05 # bin size in meters
neuron_id = 10 # neuron id to plot
rate_map, zero_bins = ratinabox.utils.bin_data_for_histogramming(
data=pos,
extent=env.extent,
dx=bin_size,
weights=rate_timeseries[neuron_id],
norm_by_bincount=True,
return_zero_bins=True,
)
I solved a lot of the kernel density estimation stuff in the KalMax package. We could use this but it's an extra dependency for a not established package which seems unwise. It's also written in jax. Better perhaps would be to literally copy the code over and host it all here in house, using numpy.
Ideally we could have some nice API like:
neurons.get_KDE_rate_maps(
spikes_or_rates, # whether to use spikes or rates
bandwidth = 0.01 # gaussian kernel bandwidth
) # -> np.array containing rate map for each neuron