def test_eemd_noiseSeed(self): T = np.linspace(0, 1, 100) S = np.sin(2 * np.pi * T + 4**T) + np.cos((T - 0.4)**2) # Compare up to machine epsilon cmpMachEps = lambda x, y: np.abs(x - y) <= 2 * np.finfo(x.dtype).eps config = {"processes": 1} eemd = eemd(trials=10, **config) # First run random seed eIMF1 = eemd(S) # Second run with defined seed, diff than first eemd.noise_seed(12345) eIMF2 = eemd(S) # Extremly unlikely to have same seed, thus different results msg_false = "Different seeds, expected different outcomes" if eIMF1.shape == eIMF2.shape: self.assertFalse(np.all(cmpMachEps(eIMF1, eIMF2)), msg_false) # Third run with same seed as with 2nd eemd.noise_seed(12345) eIMF3 = eemd(S) # Using same seeds, thus expecting same results msg_true = "Used same seed, expected same results" self.assertTrue(np.all(cmpMachEps(eIMF2, eIMF3)), msg_true)
def test_eemd_passingArgumentsViaDict(self): trials = 10 noise_kind = 'uniform' spline_kind = 'linear' # Making sure that we are not testing default options eemd = eemd() self.assertFalse(eemd.trials == trials, self.cmp_msg(eemd.trials, trials)) self.assertFalse(eemd.noise_kind == noise_kind, self.cmp_msg(eemd.noise_kind, noise_kind)) self.assertFalse(eemd.EMD.spline_kind == spline_kind, self.cmp_msg(eemd.EMD.spline_kind, spline_kind)) # Testing for passing attributes via params params = { "trials": trials, "noise_kind": noise_kind, "spline_kind": spline_kind } eemd = eemd(**params) self.assertTrue(eemd.trials == trials, self.cmp_msg(eemd.trials, trials)) self.assertTrue(eemd.noise_kind == noise_kind, self.cmp_msg(eemd.noise_kind, noise_kind)) self.assertTrue(eemd.EMD.spline_kind == spline_kind, self.cmp_msg(eemd.EMD.spline_kind, spline_kind))
def test_default_call_EEMD(): T = np.arange(50) S = np.cos(T * 0.1) max_imf = 2 eemd = eemd() eemd(S, T, max_imf)
def test_eemd_passingCustomEMD(self): spline_kind = "linear" params = {"spline_kind": spline_kind} eemd = eemd() self.assertFalse( eemd.EMD.spline_kind == spline_kind, "Not" + self.cmp_msg(eemd.EMD.spline_kind, spline_kind)) from EMD import emd emd = emd(**params) eemd = eemd(ext_EMD=emd) self.assertTrue(eemd.EMD.spline_kind == spline_kind, self.cmp_msg(eemd.EMD.spline_kind, spline_kind))
def test_eemd_simpleRun(self): T = np.linspace(0, 1, 100) S = np.sin(2 * np.pi * T) config = {"processes": 1} eemd = eemd(trials=10, max_imf=1, **config) eemd.EMD.FIXE_H = 5 eemd.eemd(S) self.assertTrue('pool' in eemd.__dict__)
def test_eemd_notParallel(self): S = np.random.random(100) eemd = eemd(trials=5, max_imf=2, parallel=False) eemd.EMD.FIXE_H = 2 eIMFs = eemd.eemd(S) self.assertTrue(eIMFs.shape[0] > 0) self.assertTrue(eIMFs.shape[1], len(S)) self.assertFalse('pool' in eemd.__dict__)
def test_eemd_unsupportedNoiseKind(self): noise_kind = "whoever_supports_this_is_wrong" eemd = eemd(noise_kind=noise_kind) with self.assertRaises(ValueError): eemd.generate_noise(1., 100)
from EMD import eemd import numpy as np import pylab as plt # Define signal t = np.linspace(0, 1, 200) sin = lambda x, p: np.sin(2 * np.pi * x * t + p) S = 3 * sin(18, 0.2) * (t - 0.2)**2 S += 5 * sin(11, 2.7) S += 3 * sin(14, 1.6) S += 1 * np.sin(4 * 2 * np.pi * (t - 0.8)**2) S += t**2.1 - t # Assign EEMD to `eemd` variable eemd = eemd() # Say we want detect extrema using parabolic method emd = eemd.EMD emd.extrema_detection = "parabol" # Execute EEMD on S eIMFs = eemd.eemd(S, t) nIMFs = eIMFs.shape[0] # Plot results plt.figure(figsize=(12, 9)) plt.subplot(nIMFs + 1, 1, 1) plt.plot(t, S, 'r') for n in range(nIMFs):