Closed DominiqueMakowski closed 2 years ago
Hi @DominiqueMakowski
wow, you were fast, I didn't know that the dev branch was under regular scrutiny, I should be careful pushing more polished code :sweat_smile:.
Yes, this implementation is definitely helping, and I think also more valid. I had the feeling that some clever vectorization could help with these things, but as I just started looking at more advanced nonlinear technics this week I was just wrapping my head around the math. The iterative approach will definitely be penalized if running in pure Python, the disadvantage was quite mitigated with Numba otherwise, even if still present. I have then implemented this approach that is taking advantage of the Scipy implementation of Euclidean distance.
I still cannot reproduce precisely all the metrics reported by Kubios (recurrence, determinism...), I think that might be related to the way I extract the diagonals. Do you have something already working in NeuroKit?
I didn't know that the dev branch was under regular scrutiny
big brother is watching you 👁️ ^^
Do you have something already working in NeuroKit
Until now we were relying on pyRQA to get them, but it's a bit of a hassle to get it working, so we'd like to have an in-house implementation too
Regarding recurrence rate, we compute it under the hood in the context of the optimization of r:
(with the difference that here it computes the RR for a vector of r-values), but if I'm not mistaken this looked a bit different from your current RR last time I checked, so we might want to double check that.
For all the remaining indices, we can also take a look at pyRQA to see how they get these variables
I am closing here as this implementation will be part of the next release but I will come on NeuroKit someday so we can start a systematic comparison between the indices extracted here and other software like Kubios.
Hey @LegrandNico hope you're doing great,
just saw that you were in the process of implementing recurrence matrix stuff for HRV, and thought you might be interested in this (much) faster implementation below:
https://github.com/neuropsychology/NeuroKit/blob/dev/neurokit2/complexity/complexity_recurrence.py
The neurokit one is tested against PyRQA and gives the same results, which are different from your current implementation. In order for it to match it, the
np.flip()
must be removed, and the subsamples must be cut short by one (I am not 100% certain that this is incorrect though, I would tend to trust pyRQA but 🤷).Anyway, feel free to steal that code :)
Here are some benchmarks (not taking into account numba gains):
looking forward to chatting with you sometime ☺️