NeuroKit
NeuroKit copied to clipboard
[Feature] MFDFA: allow for q=0
https://github.com/LRydin/MFDFA/issues/33
- [x] Implement maxFDA
Codecov Report
Merging #683 (4d096cf) into dev (a192c0b) will decrease coverage by
0.00%
. The diff coverage is60.71%
.
@@ Coverage Diff @@
## dev #683 +/- ##
==========================================
- Coverage 52.52% 52.51% -0.01%
==========================================
Files 277 277
Lines 12501 12508 +7
==========================================
+ Hits 6566 6569 +3
- Misses 5935 5939 +4
Impacted Files | Coverage Δ | |
---|---|---|
neurokit2/misc/find_knee.py | 14.89% <7.69%> (-0.67%) |
:arrow_down: |
neurokit2/complexity/fractal_dfa.py | 58.86% <70.42%> (-1.93%) |
:arrow_down: |
neurokit2/misc/expspace.py | 75.00% <0.00%> (-12.50%) |
:arrow_down: |
neurokit2/eda/eda_eventrelated.py | 81.63% <0.00%> (-2.05%) |
:arrow_down: |
neurokit2/rsp/rsp_simulate.py | 98.21% <0.00%> (+4.46%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
import matplotlib
import neurokit2 as nk
signal = nk.signal_simulate(duration=10, frequency=[5, 7, 10, 14], noise=0.05)
mfdfa, info = nk.fractal_mfdfa(signal, q=np.linspace(-3, 3, 7), show=True, scale = nk.expspace(50, 500, 20))
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5)
@LRydin I tried to implement it but I suspect that something is off, from the plot as the fluctuation values for when q=0 are weird
Perfect, the result is correct, you can see that the maximum of the singularity dimension (D) is 1
, and that comes to be when we have q=0
, so that's perfect :). That was easier than I expected in the end 👍.
I added an "experimental" feature that I wanted your opinion on:
The fluctuations often display a non-linear pattern, and the longer the scales the more the coefficient of the linear slope is biased:
import matplotlib
import neurokit2 as nk
signal = nk.signal_simulate(duration=10, frequency=[5, 7, 10, 14], noise=0.05)
_, _ = nk.fractal_dfa(signal, show=True)
Intuitively the linear fit seems off.
I added the option to detect the knee of the fluctuation pattern (using the kneedle algorithm), and then use that knee as a max. scale before computing the slopes. This results in much closer fits:
_, _ = nk.fractal_dfa(signal, maxdfa=True, show=True)
For multifractal, I use the max. knee (of the patterns corresponding to different qs) as the limit:
Does that make sense to you?
@LRydin I'll merge this, but still do let me know if you have any thoughts on that when you have time ;) and thanks again for your help!
OMG, I never replied to this! I'm sorry :(! Yes, this makes absolute sense. That plateau that you see on your second image is fairly normal for computer-generated data. To be best of my understanding, i.e., I've never seen a paper discuss this, the plateau appears as a limit to the standard deviation of your entire process, so, putting it simply, (MF)DFA cannot detect changes in the standard deviation because the process signal
is "bounded" between to values (quotation marks there), so it makes much more sense to extract the flucutation function at a lag smaller than the kink/keen :)
It's great! Sorry I took forever to reply @DominiqueMakowski :|
No worries, thanks a lot @LRydin ;)