neuromodulation / py_neuromodulation

Real-time analysis of intracranial neurophysiology recordings.
https://neuromodulation.github.io/py_neuromodulation/
MIT License
47 stars 11 forks source link

Optimize Hjorth and LineLength calculation #340

Closed toni-neurosc closed 5 months ago

toni-neurosc commented 5 months ago

So I was looking at the profiling info, and I was quite happy that Bursts and Sharpwaves are now as fast as Hjorth. But after messing with Bursts and Sharpwaves for so many hours, I know that they're very complex features, so how come Hjorth is taking so long? Is it also super-complex?

Well it turns out no, it was just doing quite a lot of redundant work so I streamlined it a bit, which brought the computation time to 20% of the previous code, or a 5x speed-up.

Summary of changes:

EDIT: did the same for LineLength, basically just applying the numpy functions directly to the 2D matrix, got a ~3x speed increase, although this feature was already very cheap.

EDIT2: just for reference, we're at this speed of computing for the default settings: Total time to process 10.0s of data with 5 channels: 5.7076427936553955 seconds per run. And I still have some aces up my sleeve, but I think the low hanging fruit has been more or less covered to I'm changing focus to GUI for now.

timonmerk commented 5 months ago

That's great! Thanks @toni-neurosc. Didn't know that such speed improvements would be possible even with those simple np functions!

toni-neurosc commented 5 months ago

That's great! Thanks @toni-neurosc. Didn't know that such speed improvements would be possible even with those simple np functions!

Well for 5 channels a 5x speed-up checks out, and the more channels you have in your experiment, the more speed-up in theory.