DFA
- class fathon.DFA(tsVec)
Bases:
object
Detrended Fluctuation Analysis class.
- Parameters:
tsVec (iterable) – Time series used for the analysis.
- computeFlucVec(winSizes, polOrd=1, revSeg=False, unbiased=False)
Computation of the fluctuations in each window.
- Parameters:
winSizes (numpy ndarray) – Array of window’s sizes.
polOrd (int, optional) – Order of the polynomial to be fitted in each window (default : 1).
revSeg (bool, optional) – If True, the computation of F is repeated starting from the end of the time series (default : False).
unbiased (bool, optional) – If True, the unbiased version of DFA is computed, and revSeg is ignored. To be used on short time series (default : False).
- Returns:
numpy ndarray – Array n of window’s sizes.
numpy ndarray – Array F containing the values of the fluctuations in each window.
- fitFlucVec(nStart=-999, nEnd=-999, logBase=2.718281828459045, verbose=False)
Fit of the fluctuations values.
- Parameters:
nStart (int, optional) – Size of the smaller window used to fit F (default : first value of n).
nEnd (int, optional) – Size of the bigger window used to fit F (default : last value of n).
logBase (float, optional) – Base of the logarithm for the log-log fit of n vs F (default : e).
verbose (bool, optional) – Verbosity (default : False).
- Returns:
float – Slope of the fit.
float – Intercept of the fit.
- multiFitFlucVec(limitsList, logBase=2.718281828459045, verbose=False)
Fit of the fluctuations values in different intervals at the same time.
- Parameters:
limitsList (numpy ndarray) – kx2 array with the sizes of k starting and ending windows used to fit F.
logBase (float, optional) – Base of the logarithm for the log-log fit of n vs F (default : e).
verbose (bool, optional) – Verbosity (default : False).
- Returns:
numpy ndarray – Slopes of the fits.
numpy ndarray – Intercepts of the fits.
- saveObject(outFileName)
Save current object state to binary file.
- Parameters:
outFileName (str) – Output binary file. .fathon extension will be appended to the file name.
Usage examples
import numpy as np
import fathon
from fathon import fathonUtils as fu
#time series
a = np.random.randn(10000)
#zero-mean cumulative sum
a = fu.toAggregated(a)
#initialize dfa object
pydfa = fathon.DFA(a)
#compute fluctuation function and Hurst exponent
wins = fu.linRangeByStep(10, 2000)
n, F = pydfa.computeFlucVec(wins, revSeg=True, polOrd=3)
H, H_intercept = pydfa.fitFlucVec()
#compute Hurst exponent in different ranges
limits_list = np.array([[15,2000], [200,1000]], dtype=int)
list_H, list_H_intercept = pydfa.multiFitFlucVec(limits_list)