mfdfa

Multifractal Detrended Fluctuation Analysis in Python

https://github.com/lrydin/mfdfa

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 10 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.9%) to scientific vocabulary

Keywords

detrended-fluctuation-analysis fractional-gaussian-noise multifractal-analysis self-similarity stochastic-processes
Last synced: 6 months ago · JSON representation

Repository

Multifractal Detrended Fluctuation Analysis in Python

Basic Info
  • Host: GitHub
  • Owner: LRydin
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 2.89 MB
Statistics
  • Stars: 147
  • Watchers: 9
  • Forks: 31
  • Open Issues: 7
  • Releases: 0
Topics
detrended-fluctuation-analysis fractional-gaussian-noise multifractal-analysis self-similarity stochastic-processes
Created over 6 years ago · Last pushed over 3 years ago
Metadata Files
Readme License

README.md

DOI:10.1016/j.cpc.2021.108254 arXiv zenodo PyPI - License PyPI PyPI - Python Version Build Status codecov Documentation Status

MFDFA

Multifractal Detrended Fluctuation Analysis MFDFA is a model-independent method to uncover the self-similarity of a stochastic process or auto-regressive model. DFA was first developed by Peng et al.1 and later extended to study multifractality MFDFA by Kandelhardt et al.2.

In the latest release there is as well added a moving window system, especially useful for short timeseries, a recent extension to DFA called extended DFA, and the extra feature of Empirical Mode Decomposition as detrending method.

Installation

To install MFDFA you can simply use

pip install MFDFA And on your favourite editor simply import MFDFA as python from MFDFA import MFDFA There is an added library fgn to generate fractional Gaussian noise.

You can find the latest published paper of this library in Computer Physics Communications L. Rydin Gorjão, G. Hassan, J. Kurths, and D. Witthaut, MFDFA: Efficient multifractal detrended fluctuation analysis in python, Computer Physics Communications 273, 108254 2022. You can find the paper here.

The MFDFA library

MFDFA basis is solely dependent on numpy, especially numpy's polynomial. In version 0.3 a Empirical Mode Decomposition method was added for an alternative method of detrending timeseries, relying on Dawid Laszuk's PyEMD.

Employing the MFDFA library

An exemplary one-dimensional fractional Ornstein–Uhlenbeck process

The rationale here is simple: Numerically integrate a stochastic process in which we know exactly the fractal properties, characterised by the Hurst coefficient, and recover this with MFDFA. We will use a fractional Ornstein–Uhlenbeck, a commonly employ stochastic process with mean-reverting properties. For a more detailed explanation on how to integrate an Ornstein–Uhlenbeck process, see the kramersmoyal's package. You can also follow the fOU.ipynb

Generating a fractional Ornstein–Uhlenbeck process

This is one method of generating a (fractional) Ornstein–Uhlenbeck process with H=0.7, employing a simple Euler–Maruyama integration method

```python

Imports

from MFDFA import MFDFA from MFDFA import fgn

where this second library is to generate fractional Gaussian noises

integration time and time sampling

tfinal = 2000 deltat = 0.001

Some drift theta and diffusion sigma parameters

theta = 0.3 sigma = 0.1

The time array of the trajectory

time = np.arange(0, tfinal, deltat)

The fractional Gaussian noise

H = 0.7 dB = (t_final ** H) * fgn(N = time.size, H = H)

Initialise the array y

y = np.zeros([time.size])

Integrate the process

for i in range(1, time.size): y[i] = y[i-1] - theta * y[i-1] * delta_t + sigma * dB[i] ``` And now you have a fractional process with a self-similarity exponent H=0.7

Using the MFDFA

To now utilise the MFDFA, we take this exemplary process and run the (multifractal) detrended fluctuation analysis. For now lets consider only the monofractal case, so we need only q=2. ```python

Select a band of lags, which usually ranges from

very small segments of data, to very long ones, as

lag = np.unique(np.logspace(0.5, 3, 100).astype(int))

Notice these must be ints, since these will segment

the data into chucks of lag size

Select the power q

q = 2

The order of the polynomial fitting

order = 1

Obtain the (MF)DFA as

lag, dfa = MFDFA(y, lag = lag, q = q, order = order) ```

Now we need to visualise the results, which can be understood in a log-log scale. To find H we need to fit a line to the results in the log-log plot ```python

To uncover the Hurst index, lets get some log-log plots

plt.loglog(lag, dfa, 'o', label='fOU: MFDFA q=2')

And now we need to fit the line to find the slope. Don't

forget that since you are plotting in a double logarithmic

scales, you need to fit the logs of the results

H_hat = np.polyfit(np.log(lag)[4:20],np.log(dfa[4:20]),1)[0]

Now what you should obtain is: slope = H + 1

print('Estimated H = '+'{:.3f}'.format(H_hat[0])) ```

Uncovering multifractality in stochastic processes

You can find more about multifractality in the documentation.

Changelog

  • Version 0.4.3 - Reverting negative values in the estimation of the singularity strenght α.
  • Version 0.4.2 - Corrected spectral plots. Added examples from the paper.
  • Version 0.4.1 - Added conventional spectral plots as h(q) vs q, τ(q) vs q, and f(α) vs α.
  • Version 0.4 - EMD is now optional. Restored back compatibility: py3.3 to py3.9. For EMD py3.6 or larger is needed.
  • Version 0.3 - Adding EMD detrending. First release. PyPI code.
  • Version 0.2 - Removed experimental features. Added documentation
  • Version 0.1 - Uploaded initial working code

Contributions

I welcome reviews and ideas from everyone. If you want to share your ideas or report a bug, open an issue here on GitHub, or contact me directly. If you need help with the code, the theory, or the implementation, do not hesitate to reach out, I am here to help. This package abides to a Conduct of Fairness.

Literature and Support

Submission history

This library has been submitted for publication at The Journal of Open Source Software in December 2019. It was rejected. The review process can be found here on GitHub. The plan is to extend the library and find another publisher.

History

This project was started in 2019 at the Faculty of Mathematics, University of Oslo in the Risk and Stochastics section by Leonardo Rydin Gorjão and is supported by Dirk Witthaut and the Institute of Energy and Climate Research Systems Analysis and Technology Evaluation. I'm very thankful to all the folk in Section 3 in the Faculty of Mathematics, University of Oslo, for helping me getting around the world of stochastic processes: Dennis, Anton, Michele, Fabian, Marc, Prof. Benth and Prof. di Nunno. In April 2020 Galib Hassan joined in extending MFDFA, particularly the implementation of EMD.

Funding

Helmholtz Association Initiative Energy System 2050 - A Contribution of the Research Field Energy and the grant No. VH-NG-1025; STORM - Stochastics for Time-Space Risk Models project of the Research Council of Norway (RCN) No. 274410, and the E-ON Stipendienfonds.

References

1Peng, C.-K., Buldyrev, S. V., Havlin, S., Simons, M., Stanley, H. E., & Goldberger, A. L. (1994). Mosaic organization of DNA nucleotides. Physical Review E, 49(2), 1685–1689\ 2Kantelhardt, J. W., Zschiegner, S. A., Koscielny-Bunde, E., Havlin, S., Bunde, A., & Stanley, H. E. (2002). Multifractal detrended fluctuation analysis of nonstationary time series. Physica A: Statistical Mechanics and Its Applications, 316(1-4), 87–114

Owner

  • Name: Rydin
  • Login: LRydin
  • Kind: user
  • Location: Oslo, Norway
  • Company: OsloMet

I had cereals for breakfast

GitHub Events

Total
  • Watch event: 14
  • Fork event: 4
Last Year
  • Watch event: 14
  • Fork event: 4

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 113
  • Total Committers: 2
  • Avg Commits per committer: 56.5
  • Development Distribution Score (DDS): 0.018
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
LRydin l****n@g****m 111
Galib Hassan g****0@g****m 2

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 22
  • Total pull requests: 15
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 10
  • Total pull request authors: 2
  • Average comments per issue: 2.77
  • Average comments per pull request: 0.6
  • Merged pull requests: 15
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • LRydin (11)
  • DominiqueMakowski (2)
  • galibhassan (1)
  • rsautter (1)
  • Rabia-Raja (1)
  • XiaoPachong999 (1)
  • 00stat (1)
  • iras (1)
  • ghost (1)
  • FuadYoussef (1)
Pull Request Authors
  • LRydin (13)
  • galibhassan (2)
Top Labels
Issue Labels
enhancement (8) documentation (2) help wanted (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1,132 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 5
  • Total maintainers: 1
pypi.org: mfdfa

Multifractal Detrended Fluctuation Analysis in Python

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 1,132 Last month
Rankings
Stargazers count: 6.8%
Forks count: 7.7%
Dependent packages count: 10.0%
Average: 12.3%
Downloads: 15.5%
Dependent repos count: 21.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • numpy *
setup.py pypi
  • numpy *