示例#1
0
def test_dcca():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n, F = pydcca.computeFlucVec(winSizes, polOrd=2)
    H, H_int = pydcca.fitFlucVec()

    assert math.isclose(H, 0.9604004237165071)
示例#2
0
def test_rho_thresholds():
    np.random.seed(42)
    pydcca = fathon.DCCA()
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n4, int1, int2 = pydcca.rhoThresholds(len(ts1), winSizes, 10, 0.95)

    assert math.isclose(int1[53], 0.2619278369335029) and math.isclose(
        int2[53], -0.41952479444776136)
示例#3
0
def test_rho_thresholds():
    np.random.seed(42)
    pydcca = fathon.DCCA()
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n4, int1, int2 = pydcca.rhoThresholds(len(ts1), winSizes, 10, 0.95)

    assert math.isclose(int1[53], 0.03131478865331007) and math.isclose(
        int2[53], -0.05672796198121624)
示例#4
0
def test_dcca_3():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n, F = pydcca.computeFlucVec(winSizes,
                                 polOrd=1,
                                 absVals=False,
                                 overlap=False,
                                 revSeg=True)

    assert math.isclose(F[23], 8.611065211944974)
示例#5
0
def test_dcca_2():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n, F = pydcca.computeFlucVec(winSizes,
                                 polOrd=2,
                                 absVals=False,
                                 overlap=False,
                                 revSeg=False)

    assert math.isclose(F[9], 0.08470236108797902)
示例#6
0
def test_dcca_5():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n, F = pydcca.computeFlucVec(winSizes,
                                 polOrd=1,
                                 absVals=True,
                                 overlap=False,
                                 revSeg=False)
    H, H_int = pydcca.fitFlucVec()

    assert math.isclose(H, 0.8259796205478073)
示例#7
0
def test_rho():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n3, rho = pydcca.computeRho(winSizes)

    assert math.isclose(rho[53], 0.48503322468665233)
示例#8
0
def test_dcca_save_load():
    dcca = fathon.DCCA(fu.toAggregated(ts), fu.toAggregated(ts))
    # save and load with empty results
    dcca.saveObject(get_object_path('dcca_obj'))
    n_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'F')
    n_rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nRho')
    rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'rho')
    n_thr_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nThr')
    conf_up_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                      'confUp')
    conf_down_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                        'confDown')
    assert np.array_equal(n_load, [])
    assert np.array_equal(F_load, [])
    assert np.array_equal(n_rho_load, [])
    assert np.array_equal(rho_load, [])
    assert np.array_equal(n_thr_load, [])
    assert np.array_equal(conf_up_load, [])
    assert np.array_equal(conf_down_load, [])
    #save and load with results
    n, F = dcca.computeFlucVec(fu.linRangeByStep(10, 200))
    H, I = dcca.fitFlucVec(100, 150)
    dcca.saveObject(get_object_path('dcca_obj'))
    n_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'F')
    n_rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nRho')
    rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'rho')
    n_thr_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nThr')
    conf_up_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                      'confUp')
    conf_down_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                        'confDown')
    assert np.array_equal(n_load, n)
    assert np.array_equal(F_load, F)
    assert np.array_equal(n_rho_load, [])
    assert np.array_equal(rho_load, [])
    assert np.array_equal(n_thr_load, [])
    assert np.array_equal(conf_up_load, [])
    assert np.array_equal(conf_down_load, [])
    # DCCA from file
    dcca_2 = fathon.DCCA(get_object_path('dcca_obj', ext=True))
    H_2, I_2 = dcca_2.fitFlucVec(100, 150)
    assert np.array_equal(H_2, H)
    assert np.array_equal(I_2, I)
    # rho
    n_rho, rho = dcca.computeRho(fu.linRangeByStep(10, 30))
    dcca.saveObject(get_object_path('dcca_obj'))
    n_rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nRho')
    rho_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True), 'rho')
    n_thr_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nThr')
    conf_up_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                      'confUp')
    conf_down_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                        'confDown')
    assert np.array_equal(n_load, n)
    assert np.array_equal(F_load, F)
    assert np.array_equal(n_rho_load, n_rho)
    assert np.array_equal(rho_load, rho)
    assert np.array_equal(n_thr_load, [])
    assert np.array_equal(conf_up_load, [])
    assert np.array_equal(conf_down_load, [])
    # thresholds
    n_thr, conf_up, conf_down = dcca.rhoThresholds(len(ts),
                                                   fu.linRangeByStep(10, 30),
                                                   10, 0.95)
    dcca.saveObject(get_object_path('dcca_obj'))
    n_thr_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                    'nThr')
    conf_up_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                      'confUp')
    conf_down_load = fu.getObjectMember(get_object_path('dcca_obj', ext=True),
                                        'confDown')
    assert np.array_equal(n_load, n)
    assert np.array_equal(F_load, F)
    assert np.array_equal(n_rho_load, n_rho)
    assert np.array_equal(rho_load, rho)
    assert np.array_equal(n_thr_load, n_thr)
    assert np.array_equal(conf_up_load, conf_up)
    assert np.array_equal(conf_down_load, conf_down)
示例#9
0
def test_rho_2():
    pydcca = fathon.DCCA(ts1, ts2)
    winSizes = fu.linRangeByStep(10, 200, step=2)
    n3, rho = pydcca.computeRho(winSizes, overlap=False, revSeg=False)

    assert math.isclose(rho[28], 0.39579454461767466)
示例#10
0
import numpy as np
import matplotlib.pyplot as plt
import fathon

print('This is fathon v{}'.format(fathon.__version__))

a = np.random.randn(10000)
b = np.random.randn(10000)

a = fathon.toAggregated(a)
b = fathon.toAggregated(b)

pydcca = fathon.DCCA(a, b)

nMin = 20
nMax = 1000
nStep = 50
polOrd = 1

n, F = pydcca.computeFlucVec(nMin, nMax=nMax, nStep=nStep, polOrd=polOrd)

H, H_intercept = pydcca.fitFlucVec()

plt.plot(np.log(n), np.log(F), 'ro')
plt.plot(np.log(n),
         H_intercept + H * np.log(n),
         'k-',
         label='H = {:.2f}'.format(H))
plt.xlabel('ln(n)', fontsize=14)
plt.ylabel('ln(F(n))', fontsize=14)
plt.title('DCCA', fontsize=14)