You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
zscore fails when using whitenoise as an input. #1972
I thought more about this this morning. It is just a statistical problem with the test. This is not a bug.
The thing is that if you scale your data by a standadrd deviation you increase the standard error:
$ SE = \frac{\sigma}{\sqrt{n}} $
Then you need a larger n. If you calculate the standard error of the mean for the chunks available you get that the standard error is not small enough for the test above to be sound.
Plus, casting to int is not a linear function (it behaves like floor for positives and like ceiling for negatives) which also increases the standard deviation of the samples and will make the standard error larger in practice.
Here, I estimate taking the mean 1_000 times with 100_000 samples. You can see that most of the estimates are farther from the true (which is zero) than 1 and therefore will fail on the test above.
estimates= (256*np.random.randn(int(5e4), 1000).astype("int16")).mean(axis=0)
plt.hist(estimates, bins=100)
plt.xlabel("Estimated mean from the process")
plt.ylabel("Frequency")
I would like for us to shutdown this test and slowly deprecate the int range functionality in ZScoreRecording so we can confine this complexity to kilosort only. Probably Sam tested this a lot there when he was implementing kilosort and as this is is an ad-hoc processing step for them we don't neeed to test it in the general.
Within the kilosort pipeline or anywhere else if the need for an operation like this arises the operation can be performed by composing the casting and scaling operations already available in the pre-processing module. No need for flags.
As far as I can tell the std landing slightly off from int_scale (257 vs 256) is a sampling effect: the gain/offset are estimated from get_random_data_chunks rather than the full recording, and Center/NormalizeByQuantile/ZScore all do it the same way — which matches the # I think this is a bad test note already in the test. So this might be expected rather than a code bug, though you'd know better than me.
While looking, I did notice the integer-dtype casts in a few preprocessors truncate instead of round (filter.py already rounds) — opened #4653 for that.
Activity
h-mayorquin commentedon Sep 6, 2023
This functionality was implemented here:
#1437
alejoe91 commentedon Sep 7, 2023
Interesting! I'll also take a look! Thanks for tracking this down @h-mayorquin
h-mayorquin commentedon Sep 7, 2023
I thought more about this this morning. It is just a statistical problem with the test. This is not a bug.
The thing is that if you scale your data by a standadrd deviation you increase the standard error:
Then you need a larger n. If you calculate the standard error of the mean for the chunks available you get that the standard error is not small enough for the test above to be sound.
Plus, casting to int is not a linear function (it behaves like floor for positives and like ceiling for negatives) which also increases the standard deviation of the samples and will make the standard error larger in practice.
Here, I estimate taking the mean 1_000 times with 100_000 samples. You can see that most of the estimates are farther from the true (which is zero) than 1 and therefore will fail on the test above.
h-mayorquin commentedon Sep 7, 2023
I would like for us to shutdown this test and slowly deprecate the int range functionality in
ZScoreRecordingso we can confine this complexity to kilosort only. Probably Sam tested this a lot there when he was implementing kilosort and as this is is an ad-hoc processing step for them we don't neeed to test it in the general.Within the kilosort pipeline or anywhere else if the need for an operation like this arises the operation can be performed by composing the casting and scaling operations already available in the pre-processing module. No need for flags.
Simliar to previous discussions:
#1815 (comment)
#914
zm711 commentedon Jul 7, 2026
Any updates @h-mayorquin ?
CodeBlackwell commentedon Jul 7, 2026
As far as I can tell the std landing slightly off from
int_scale(257 vs 256) is a sampling effect: the gain/offset are estimated fromget_random_data_chunksrather than the full recording, and Center/NormalizeByQuantile/ZScore all do it the same way — which matches the# I think this is a bad testnote already in the test. So this might be expected rather than a code bug, though you'd know better than me.While looking, I did notice the integer-dtype casts in a few preprocessors truncate instead of round (
filter.pyalready rounds) — opened #4653 for that.