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

[ENH] - Add DFA to a new aperiodic module #167

Merged
merged 12 commits into from
Aug 1, 2020

Conversation

rdgao
Copy link
Contributor

@rdgao rdgao commented Sep 5, 2019

Add Detrended Fluctuation Analaysis.

Edit from Tom:

  • Eric & Ryan, I've tagged you into this PR, now that we're moving onto 2.2 & aperiodic additions.
    • whenever y'all get a chance, Eric if you can check math & Ryan if you can check code, that would be great!

neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
@neurodsp-tools neurodsp-tools deleted a comment from codecov-io Sep 5, 2019
@TomDonoghue
Copy link
Member

@rdgao : I refactored a bit to try and match NDSP format, and left a couple quick questions in a review. I want to sanity check I'm not missing anything before I go through with a couple other updates. Whenever you get a chance (no huge rush) throw an eye on the comments & sign off if things looks good. I'm happy to make the changes, if nothing looks weird.

Only other open question is naming. 'fractal' or 'scale-free' feels a little broad, as many other measures relate to those properties. I don't want to call everything DFA, as it isn't all DFA. Is 'fluctuation analysis' an at all reasonable catch-all term for the measures here? Can we call this file 'fluctuations.py'?

Copy link
Contributor Author

@rdgao rdgao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the demean thing, but everything else should be fine.

As for the name, I think fluctuations is a little too non-specific. In some sense, everything we do is looking at fluctuations, and this particular word is not usually used in that specific context. Could call it nonlinear? But yeah it really depends on what might go into that folder in the future. Could have just DFA as its own thing, or a more inclusive folder.

neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
@TomDonoghue
Copy link
Member

Okay @rdgao - I did the updates from the comments here. One convo is left open, if you want to throw an eye and make sure I didn't mess it up in the updates.

Other than potentially changing the name of the file, this should be ready to merge, I think, if everything looks good to you.

@neurodsp-tools neurodsp-tools deleted a comment from codecov-io Oct 9, 2019
@rdgao
Copy link
Contributor Author

rdgao commented Oct 14, 2019

Code looks okay. I think the test should run it on a simulated white noise signal and get back what we expect?

@TomDonoghue TomDonoghue changed the title added dfa in aperiodic module [ENH] - Add DFA to a new aperiodic module Jun 14, 2020
@TomDonoghue TomDonoghue added the 2.2 Updates to go into a 2.2.0 release label Jun 15, 2020
Copy link
Contributor

@elybrand elybrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, though I did catch an arithmetic error.

raise ValueError('Fluctuation method not understood.')

# Calculate the relationship between between fluctuations & time scales
exp = np.polyfit(np.log10(t_scales), np.log10(fluctuations), deg=1)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as a first step, I think fitting a line to the fluctuations in log-log land is fine. Looking down the road though, EEG signals have a DFA plot which is piecewise linear, at least empirically according to this work. Perhaps this is something we could add at a later point and wouldn't require too much extra work I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, I think this is a good point / idea - but is more of an extension for future work, that doesn't need to go into this PR necessarily. As I understand it, what we have here is "standard" DFA, which we can always build on later.

neurodsp/aperiodic/dfa.py Outdated Show resolved Hide resolved
Copy link
Member

@ryanhammonds ryanhammonds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests here fail due to a bug I noted below. I'm working on figuring out a fix and am open to any suggestions. After the bug is fixed, I'll push tests updates to increase coverage.

neurodsp/aperiodic/dfa.py Show resolved Hide resolved
@TomDonoghue TomDonoghue requested a review from elybrand July 30, 2020 04:48
@TomDonoghue
Copy link
Member

I made some mild updates, based on the reviews - fixing the math error noted by Eric, updating tests to be more specific, as suggested by Richard, and updating the approach the window length issue brought up by Ryan (go team!).

I think this should be good to go. @elybrand - maybe you want to take a quick look at my updates and how these functions are tested now? @ryanhammonds - everything new look good to you?

@TomDonoghue TomDonoghue mentioned this pull request Jul 30, 2020
Copy link
Contributor

@elybrand elybrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good!

@TomDonoghue
Copy link
Member

Okay, all looks good here! Thanks for the code @rdgao, and the reviews @elybrand & @ryanhammonds!

Merging in now to officially start our aperiodic module!

@TomDonoghue TomDonoghue merged commit 5a6b38d into neurodsp-tools:master Aug 1, 2020
@rdgao
Copy link
Contributor Author

rdgao commented Aug 1, 2020

wooo!

@ryanhammonds ryanhammonds mentioned this pull request May 3, 2021
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.2 Updates to go into a 2.2.0 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants