LRydin / MFDFA

Multifractal Detrended Fluctuation Analysis in Python
MIT License
128 stars 27 forks source link

Implement also modification when q = 0 #33

Open DominiqueMakowski opened 2 years ago

DominiqueMakowski commented 2 years ago

In Faini 2021, they suggest a "seemingly simple" modification of the equation for when q = 0

image

Currently it seems like we do:

fluctuation = np.float_power(np.mean(np.float_power(var, q / 2), axis=1), 1 / q.T)

My fluency with equations is not there yet to be able to implement the adaptation, but if you have any ideas or leads I'm all ears :)

LRydin commented 2 years ago

Hey @DominiqueMakowski,

yeah, this was introduced already in the original MFDFA paper by Kantelhardt et at. ¹ in Eq. (6):

MFDFA

I haven't implemented this because of the usual uninterest of this particular measure. Admittedly there is a meaning associated with some measures at q=0. We can go back to one of the grounding papers in 1983 by Hentschel & Procaccia ²:

1983

Where D is the similarity dimension, σ the information dimension, and ν the correlation dimension.

It should be simple to implement, we just need to create a separate routine to perform the MFDFA at values close to q=0. Let me see if I find the patience to implement this, I go a vacation week coming up so it might take a bit :). It should look like:

fluctuation = np.exp(np.mean(np.log(var), axis=1))

(I haven't check this expression too thoroughly!)


¹ Kantelhardt, 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. doi:10.1016/s0378-4371(02)01383-3 ² Hentschel, H. G. E., & Procaccia, I. (1983). The infinite number of generalized dimensions of fractals and strange attractors. Physica D: Nonlinear Phenomena, 8(3), 435–444. doi:10.1016/0167-2789(83)90235-x

DominiqueMakowski commented 2 years ago

Thanks a lot for this additional info! I'll add your experimental expression to NK and will try to run some tests to see if it doesn't do anything weird, I'll link the PR to this issue and will report back how it goes :)

enjoy your holidays!

Vexvare commented 12 months ago

Hello Dr. Rydin, I appreciate the work you have put into this MFDFA python project. I have used it in my personal repository for solar analysis work used in my thesis, and without it, I would not have been able to conduct the work I have done for it in Python. So thank you very much!

In pursuit of my thesis, I have added a calculation for the q=0 fluctuation. I went ahead and forked your repository over to my projects if you wish to check it out. It simply separates the negative, positive, and 0th q's and their respective fluctuation functions, calculates the necessary values over them, and appends them back together at the end.

I recognize that it's not the most robust solution for the q=0 fluctuation, but it is a solution nonetheless. If you have time, I would appreciate you check it out and give your thoughts and feedback. Thanks once again, I hope it helps!

(The major code changes in my branch of your project are from lines 150-158, 173-179, 232-242, 272-280, 290-292, and 305-307. However, I am not too sure I implemented the q=0 standard deviation on line 291 correctly.)

LRydin commented 11 months ago

Hey @Vexvare! Great to know the package helped you! That's what it's here for :). I'll be honest that I indeed neglected the q=0 since I so rarely am interested in finding out what happens at q=0, so it's nice to know that you looked into this.

I'll check out your fork and see what can be used from it (it might take a bit, I got a bit on my plate right now at work).

Thanks a bunch for the message and the work!

Cheers, Leo