DCCA
- class fathon.DCCA(tsVec1=[], tsVec2=[])
Bases:
object
Detrended Cross-Correlation Analysis class.
- Parameters:
tsVec1 (iterable) – First time series used for the analysis.
tsVec2 (iterable) – Second time series used for the analysis.
- computeFlucVec(winSizes, polOrd=1, absVals=True, overlap=False, revSeg=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).
absVals (bool, optional) – If True, the computation of F is performed using the abolute values of the fluctuations of both tsVec1 and tsVec2 (default : True).
overlap (bool, optional) – If True, computes F using overlapping segments (default : False).
revSeg (bool, optional) – If True, the computation of F is repeated starting from the end of the time series, ignored if overlap is True (default : False).
- Returns:
numpy ndarray – Array n of window’s sizes.
numpy ndarray – Array F containing the values of the fluctuations in each window.
- computeRho(winSizes, polOrd=1, verbose=False, overlap=False, revSeg=False)
Computation of the cross-correlation index 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).
verbose (bool, optional) – Verbosity (default : False).
overlap (bool, optional) – If True, computes F using overlapping segments (default : False).
revSeg (bool, optional) – If True, the computation of F is repeated starting from the end of the time series, ignored if overlap is True (default : False).
- Returns:
numpy ndarray – Array of window’s sizes.
numpy ndarray – Array containing the cross-correlation index.
- 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.
- rhoThresholds(L, winSizes, nSim, confLvl, polOrd=1, verbose=False)
Computation of the cross-correlation index’s confidence levels in each window.
- Parameters:
L (int) – Size of the random time series used to evaluate confidence levels.
winSizes (numpy ndarray) – Array of window’s sizes.
nSim (int) – Number of times the cross-correlation index between two random time series is computed in order to evaluate the confidence levels.
confLvl (float) – Confidence level.
polOrd (int, optional) – Order of the polynomial to be fitted in each window (default : 1).
verbose (bool, optional) – Verbosity (default : False).
- Returns:
numpy ndarray – Array of window’s sizes.
numpy ndarray – Array containing the first confidence interval.
numpy ndarray – Array containing the second confidence interval.
- 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)
b = np.random.randn(10000)
#zero-mean cumulative sum
a = fu.toAggregated(a)
b = fu.toAggregated(b)
#initialize non-empty dcca object
pydcca = fathon.DCCA(a, b)
#compute fluctuation function and Hurst exponent
wins = fu.linRangeByStep(20, 1000, step=50)
n, F = pydcca.computeFlucVec(wins, polOrd=1)
H, H_intercept = pydcca.fitFlucVec()
#compute Hurst exponent in different ranges
limits_list = np.array([[20,120], [220,870]], dtype=int)
list_H, list_H_intercept = pydcca.multiFitFlucVec(limits_list)
#compute rho index
wins = fu.linRangeByStep(20, 100, step=50)
n, rho = pydcca.computeRho(wins, polOrd=1)
#initialize empty dcca object
pythresh = fathon.DCCA()
#compute confidence levels
wins = fu.linRangeByStep(4, 100)
n, cInt1, cInt2 = pythresh.rhoThresholds(300, wins, 100, 0.95, polOrd=1)