Пример #1
0
def test_rng_seed_equal():
    N = 64
    x = normal(0, 1, N)
    seed = randint(1 << 30)
    imfs1 = eemd(x, rng_seed=seed)
    imfs2 = eemd(x, rng_seed=seed)
    assert_allclose(imfs1, imfs2)
Пример #2
0
def test_ones():
    N = 64
    x = [1] * N
    imfs = eemd(x, ensemble_size=100)
    for n in range(imfs.shape[0] - 1):
        imf = imfs[n, :]
        assert all(abs(imf) < 1e-9)
    assert_allclose(imfs[-1, :], x)
Пример #3
0
def test_extract_residual():
    N = 100
    t = linspace(1, 10, num=N)
    x = t**2
    xn = x + normal(0, 0.5, N)
    imfs = eemd(xn)
    # the residual should be approximately equal to the signal without the
    # added noise, at least away from the ends
    residual = imfs[-1, :]
    print(abs(residual - x)[10:-10])
    assert_allclose(residual[10:-10], x[10:-10], rtol=0.1, atol=1)
Пример #4
0
def test_zeros():
    x = zeros(64)
    imfs = eemd(x, ensemble_size=10)
    # the zero signal has zero standard deviation so no noise should be added
    assert all(imfs == 0)
Пример #5
0
def test_invalid_arguments8():
    x = []
    eemd(x, num_imfs=-5)
Пример #6
0
def test_invalid_arguments6():
    x = []
    eemd(x, num_imfs="Lots")
Пример #7
0
def test_invalid_arguments4():
    x = []
    eemd(x, num_siftings=-3)
Пример #8
0
def test_invalid_arguments3():
    x = []
    eemd(x, num_siftings=0, S_number=0)
Пример #9
0
def test_invalid_arguments2():
    x = []
    eemd(x, noise_strength=-2)
Пример #10
0
def test_wrong_dims():
    x = zeros((2, 2))
    eemd(x)
Пример #11
0
def test_bogus2():
    x = eemd(7)
Пример #12
0
def test_bogus1():
    x = eemd("I am a banana")
Пример #13
0
def test_num_imfs_output_size():
    N = 64
    x = normal(0, 1, N)
    imfs = eemd(x, num_imfs=3)
    assert imfs.shape[0] == 3
Пример #14
0
def test_num_imfs():
    N = 64
    x = normal(0, 1, N)
    imfs1 = eemd(x, num_imfs=3, num_siftings=10, rng_seed=1234)
    imfs2 = eemd(x, num_imfs=4, num_siftings=10, rng_seed=1234)
    assert_allclose(imfs1[:2, :], imfs2[:2, :])
Пример #15
0
def test_rng_seed_nonequal():
    N = 64
    x = normal(0, 1, N)
    imfs1 = eemd(x, rng_seed=3141)
    imfs2 = eemd(x, rng_seed=5926)
    assert not allclose(imfs1, imfs2)
Пример #16
0
def test_invalid_arguments1():
    x = []
    eemd(x, ensemble_size=0)
Пример #17
0
if __name__ == "__main__":
    # os settings
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'

    # load data from csv file
    data = pd.read_csv('data.csv', index_col='date', parse_dates=['date'])

    # normalize data
    data_max = data.max()
    data_min = data.min()
    data = (data - data_min) / (data_max - data_min)

    # get imfs via eemd
    imfs = pyeemd.eemd(data.values.reshape(-1))

    # plot imfs
    # i = 1
    # plt.figure(2)
    # for imf in imfs:
    #     plt.subplot(len(imfs), 1, i)
    #     plt.plot(imf)
    #     i += 1
    # plt.show()

    timestep = 10
    train_size = int(len(data) * 0.8)

    # i = 1
    imfs_prediction = []
Пример #18
0
import numpy as np
from numpy import pi

# An example signal with a lower frequency sinusoid modulated by an
# intermittent higher-frequency sinusoid
x = np.linspace(0, 2 * pi, num=500)
signal = np.sin(4 * x)
intermittent = 0.1 * np.sin(80 * x)
y = signal * (1 + np.select([signal > 0.7], [intermittent]))

figure()
title("Original signal")
plot(x, y)

# Decompose with EEMD
imfs = eemd(y, num_siftings=10)

# Plot high-frequency IMFs (1-3) and the rest separately. This illustrates how EEMD can extract the intermittent signal.

highfreq_sum = np.sum([imfs[i] for i in range(0, 3)], axis=0)
lowfreq_sum = np.sum([imfs[i] for i in range(3, imfs.shape[0])], axis=0)

figure()
title("Sum of IMFs 1 to 3")
plot(x, highfreq_sum)

figure()
title("Sum of rest of IMFs")
plot(x, lowfreq_sum)

show()