Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect tuning curves for unsampled bins #334

Closed
wulfdewolf opened this issue Sep 17, 2024 · 4 comments
Closed

Incorrect tuning curves for unsampled bins #334

wulfdewolf opened this issue Sep 17, 2024 · 4 comments

Comments

@wulfdewolf
Copy link

At the moment, when a particular bin of a feature is unsampled, the tuning curve functions will set the average firing rate for that bin to zero.
This seems incorrect?
We do not know if there is no firing for that bin, hence, does it not make more sense to set it to NaN?

@gviejo
Copy link
Contributor

gviejo commented Sep 18, 2024

The tuning curves are normalized by occupancy. NaNs represents bin that have never been visited. 0 indicate no spikes. You can see an example here or you can run this code :

import numpy as np
import pynapple as nap
import matplotlib.pyplot as plt

dt = 0.1
features = np.vstack((np.cos(np.arange(0, 1000, dt)), np.sin(np.arange(0, 1000, dt)))).T
features = nap.TsdFrame(t=np.arange(0, 1000, dt),d=features)

ts_group = nap.TsGroup({0:nap.Ts(t=[0, 500, 999])})

tcurves2d, binsxy = nap.compute_2d_tuning_curves(
    group=ts_group, features=features, nb_bins=10
)

plt.figure(figsize=(12, 6))
plt.subplot(121)
plt.plot(features[:,0], features[:,1])
tmp=ts_group[0].value_from(features)
plt.plot(tmp[:,0], tmp[:,1], 'o')
plt.title("Feature + Spikes")
plt.subplot(122)
extents = (
    np.min(features[:,1]),
    np.max(features[:,1]),
    np.min(features[:,0]),
    np.max(features[:,0]),
)
plt.imshow(tcurves2d[0].T, origin="lower", extent=extents, cmap="viridis")
plt.title("Tuning curve")
plt.show()

@gviejo gviejo closed this as completed Sep 18, 2024
@wulfdewolf
Copy link
Author

I understand, and it seems to be so for 2D tuning curves.
However, when I tried yesterday for 1D tuning curves:

138    for k in group_value:
139        count, _ = np.histogram(group_value[k].values, bins)
140        count = count / occupancy
141        count[np.isnan(count)] = 0.0
142        tuning_curves[k] = count
143        tuning_curves[k] = count * feature.rate

line 141 seems to be setting NaNs to 0.

In the 2D version, this line is commented.

@gviejo gviejo reopened this Sep 18, 2024
@gviejo
Copy link
Contributor

gviejo commented Sep 18, 2024

Good catch. In fact, it's quite rare to have a 1d feature that does not span its whole extent. This is high priority so I will bump a new version as soon as possible. Leaving it open until it is resolved.

@gviejo
Copy link
Contributor

gviejo commented Sep 26, 2024

New version 0.7.1 is out with a fix to this issue.
Closing it.

@gviejo gviejo closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants