laszukdawid / PyEMD

Python implementation of Empirical Mode Decompoisition (EMD) method
https://pyemd.readthedocs.io/
Apache License 2.0
857 stars 222 forks source link

ceemdan.noise_seed() doesn't work #131

Closed nealcha closed 1 year ago

nealcha commented 1 year ago

Hi I'm using ceemdan.noise_seed() for reproducibility, but I don't get what I want. Every time I run the code the decomposition results are different (there are no changes in codes or data). the first decomposition result: img_v2_ab7410ee-c9f7-4d29-88d0-d0df77aa8e9g the second decomposition result: img_v2_c9012ac9-727e-40fa-a91c-d9618bbe30dg It is strange because I usedceemdan.noise_seed(seed=2) for reproducibility . my codes are as belows:

def ceemdan_decompose_res(data):

    ceemdan = CEEMDAN()

    ceemdan.ceemdan(data)

    ceemdan.noise_seed(seed=2)

    imfs, res = ceemdan.get_imfs_and_residue()

    plt.figure(figsize=(8,24))

    plt.subplots_adjust(hspace=0.1)

    for i in range(imfs.shape[0]):

        plt.subplot(imfs.shape[0]+3,1,i+1)

        plt.plot(imfs[i], 'g')

        plt.ylabel("IMF %i" %(i))

        plt.locator_params(axis='x', nbins=10)

        IImfs.append(imfs[i])

    plt.subplot(imfs.shape[0]+3, 1, imfs.shape[0]+1)

    plt.ylabel("res")

    plt.plot(res,'g')

    return res,imfs

testdata =  np.sin(np.float64(np.arange(0,100,1)))

IImfs=[]

_,_=ceemdan_decompose_res(testdata)

Thank you!

laszukdawid commented 1 year ago

Hey, big apologies for late reply. I don't monitor this repo too often and always hope that someone else can help.

When using methods with random number generators, the seed for these needs to be set before using them. Specifically, in your case, you should change order of 3rd and 4th lines so that it's

def ceemdan_decompose_res(data):

    ceemdan = CEEMDAN()

    ceemdan.noise_seed(seed=2)  # Changed - set seed before decomposition

    ceemdan.ceemdan(data)  # Changed

    imfs, res = ceemdan.get_imfs_and_residue()

I've tested it locally and that should work. But, please let me know if it doesn't or you have other questions. Sorry if I'm too late with this answer.