Skip to content

Commit

Permalink
Merge pull request #32 from LRydin/dev-singspect
Browse files Browse the repository at this point in the history
Correcting calculation of the singularity spectrum. Adding more examples.
  • Loading branch information
LRydin authored Jun 15, 2022
2 parents a1d576f + 6d6cd1e commit 3ba6b7c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions MFDFA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from . import singspect

__name__ = "MFDFA"
__version__ = "0.4.1"
__version__ = "0.4.2"
__author__ = "Leonardo Rydin Gorjão"
__copyright__ = "Copyright 2019-2021 Leonardo Rydin Gorjão, MIT License"
__copyright__ = "Copyright 2019-2022 Leonardo Rydin Gorjão, MIT License"
20 changes: 10 additions & 10 deletions MFDFA/singspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def singularity_spectrum(lag: np.array, mfdfa: np.ndarray, q: np.array,
q: np.array
Fractal exponents used. Must be more than 2 points.
lim: list (default `[1, lag.size//2]`)
lim: list (default `[int(lag.size // 1.5), int(lag.size // 8)]`)
List of lower and upper lag limits. If none, the polynomial fittings
will be restrict to half the maximal lag and discard the first lag
point.
Expand Down Expand Up @@ -72,7 +72,7 @@ def singularity_spectrum(lag: np.array, mfdfa: np.ndarray, q: np.array,

# if no limits given
if lim[0] is None and lim[1] is None:
lim = [1, lag.size // 2]
lim = [int(lag.size // 8), int(lag.size // 1.5)]

# clean q
q = _clean_q(q)
Expand Down Expand Up @@ -117,7 +117,7 @@ def scaling_exponents(lag: np.array, mfdfa: np.ndarray, q: np.array,
q: np.array
Fractal exponents used. Must be more than 2 points.
lim: list (default `[1, lag.size//2]`)
lim: list (default `[int(lag.size // 1.5), int(lag.size // 8)]`)
List of lower and upper lag limits. If none, the polynomial fittings
will be restrict to half the maximal lag and discard the first lag
point.
Expand Down Expand Up @@ -152,7 +152,7 @@ def scaling_exponents(lag: np.array, mfdfa: np.ndarray, q: np.array,

# if no limits given
if lim[0] is None and lim[1] is None:
lim = [1, lag.size // 2]
lim = [int(lag.size // 8), int(lag.size // 1.5)]

# clean q
q = _clean_q(q)
Expand Down Expand Up @@ -184,7 +184,7 @@ def hurst_exponents(lag: np.array, mfdfa: np.ndarray, q: np.array,
q: np.array
Fractal exponents used. Must be more than 2 points.
lim: list (default `[1, lag.size//2]`)
lim: list (default `[int(lag.size // 1.5), int(lag.size // 8)]`)
List of lower and upper lag limits. If none, the polynomial fittings
will be restrict to half the maximal lag and discard the first lag
point.
Expand Down Expand Up @@ -217,7 +217,7 @@ def hurst_exponents(lag: np.array, mfdfa: np.ndarray, q: np.array,

# if no limits given
if lim[0] is None and lim[1] is None:
lim = [1, lag.size // 2]
lim = [int(lag.size // 8), int(lag.size // 1.5)]

# clean q
q = _clean_q(q)
Expand All @@ -229,7 +229,7 @@ def hurst_exponents(lag: np.array, mfdfa: np.ndarray, q: np.array,


def _slopes(lag: np.array, mfdfa: np.ndarray, q: np.array,
lim: list = [None, None], interpolate: int = False
lim: list = [None, None], modified=True, interpolate: int = False
) -> np.array:
"""
Extra the slopes of each `q` power obtained with MFDFA to later produce
Expand All @@ -243,7 +243,7 @@ def _slopes(lag: np.array, mfdfa: np.ndarray, q: np.array,

# if no limits given
if lim[0] is None and lim[1] is None:
lim = [lag[1], lag[lag.size // 2]]
lim = [int(lag.size // 8), int(lag.size // 1.5)]

# clean q
q = _clean_q(q)
Expand All @@ -265,7 +265,7 @@ def _slopes(lag: np.array, mfdfa: np.ndarray, q: np.array,
slopes[i] = polyfit(np.log(lag[lim[0]:lim[1]]),
np.log(mfdfa[lim[0]:lim[1], i]),
1
)[1]
)[1] - 1

return slopes

Expand Down Expand Up @@ -418,7 +418,7 @@ def _plotter(x: np.array, y: np.array) -> Tuple['plt.fig', 'plt.Axes']:

fig, ax = plt.subplots(1, 1)

ax.plot(x, y, lw=2, color='black')
ax.plot(x, y, 'o', color='black')

fig.tight_layout()

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ print('Estimated H = '+'{:.3f}'.format(H_hat[0]))
You can find more about multifractality in the [documentation](https://mfdfa.readthedocs.io/en/latest/1dLevy.html).

# Changelog
- Version 0.4.2 - Corrected spectral plots. Added [examples](https://github.com/LRydin/MFDFA/tree/master/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.
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
author = 'Leonardo Rydin'

# The full version, including alpha/beta/rc tags
release = '0.4.1'
version = '0.4.1'
release = '0.4.2'
version = '0.4.2'


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="MFDFA",
version="0.4.1",
version="0.4.2",
author="Leonardo Rydin Gorjao",
author_email="[email protected]",
description="Multifractal Detrended Fluctuation Analysis in Python",
Expand All @@ -22,5 +22,5 @@
"Operating System :: OS Independent",
],
license="MIT License",
python_requires='>=3.5',
python_requires='>=3.6',
)

0 comments on commit 3ba6b7c

Please sign in to comment.