Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] vmdpy - use with odd length data leads to even length decomposition #6602

Open
kongxinz opened this issue Mar 23, 2022 · 8 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers lib:vmdpy vmdpy onboard library
Projects

Comments

@kongxinz
Copy link

kongxinz commented Mar 23, 2022

Thank you very much for the vmdpy template you provided, but I have the following problems when I use it: the length of my original sequence is fifty-nine, but the length of the subsequence obtained after decomposition has become fifty-eight. What is the reason for the situation? Is there any way to solve this problem?

@WenjieXuCN
Copy link

I found that the first line of that code has a function that identifies the length of the data.

if len(f)%2:
    f = f[:-1]

I don't really understand the intent of this code, but it is the reason for the reduced data length.

@kongxinz
Copy link
Author

kongxinz commented May 9, 2022 via email

@xuyaojian123
Copy link

me too.The length of the odd sequence length will be one less after decomposition. Does anyone know how to solve it?

@LorchZachery
Copy link

I believe I fixed the issue, (it now does not remove parts of the sequence if odd but I am unaware if the math overall still holds up) it has to do with directly copy from the matlab reference. In the matlab code

f_mirror(1:T/2) = signal(T/2:-1:1); 
f_mirror(T/2+1:3*T/2) = signal;
f_mirror(3*T/2+1:2*T) = signal(T:-1:T/2+1);

the authors did not FLOOR or CEIL T/2 which leads to half steps being rounded up automatically not floored. i.e. 5/2 will be 3.
So to fix this REMOVE (lines 40-41)

 if len(f)%2:
       f = f[:-1]

And REPLACE (lines 46-48)

ltemp = len(f)//2 
fMirr =  np.append(np.flip(f[:ltemp],axis = 0),f)  
fMirr = np.append(fMirr,np.flip(f[-ltemp:],axis = 0))

WITH

T = length(f)
fMirr = np.array(np.flip(f[0:math.ceil(T/2)]))
fMirr= np.append(fMirr,f)
fMirr = np.append(fMirr,np.flip(f[math.ceil(T/2):]))

You will need to import math and I also converted f to a numpy array as the first thing
ADD

f = np.array(f)

@xuyaojian123 @WenjieXu2000 If you could verify this solution works for you and the math remains unaffected that would be wonderful.

@anti-nadroj
Copy link

I believe I fixed the issue, (it now does not remove parts of the sequence if odd but I am unaware if the math overall still holds up) it has to do with directly copy from the matlab reference. In the matlab code

f_mirror(1:T/2) = signal(T/2:-1:1); 
f_mirror(T/2+1:3*T/2) = signal;
f_mirror(3*T/2+1:2*T) = signal(T:-1:T/2+1);

the authors did not FLOOR or CEIL T/2 which leads to half steps being rounded up automatically not floored. i.e. 5/2 will be 3. So to fix this REMOVE (lines 40-41)

 if len(f)%2:
       f = f[:-1]

And REPLACE (lines 46-48)

ltemp = len(f)//2 
fMirr =  np.append(np.flip(f[:ltemp],axis = 0),f)  
fMirr = np.append(fMirr,np.flip(f[-ltemp:],axis = 0))

WITH

T = length(f)
fMirr = np.array(np.flip(f[0:math.ceil(T/2)]))
fMirr= np.append(fMirr,f)
fMirr = np.append(fMirr,np.flip(f[math.ceil(T/2):]))

You will need to import math and I also converted f to a numpy array as the first thing ADD

f = np.array(f)

@xuyaojian123 @WenjieXu2000 If you could verify this solution works for you and the math remains unaffected that would be wonderful.

This worked for me. I compared a set of IMFs with even sequence lengths produced by the original code and the new code and the values are identical. And now it can also do odd sequence lengths. Thanks!

@LJD20000611
Copy link

万分感谢

@fkiraly fkiraly changed the title Thank you very much for the vmdpy template you provided, but I have the following problems when I use it: the length of my original sequence is fifty-nine, but the length of the subsequence obtained after decomposition has become fifty-eight. What is the reason for the situation? Is there any way to solve this problem? [BUG] vmdpy - use with odd length data leads to even length decomposition Jun 14, 2024
@fkiraly fkiraly transferred this issue from vrcarva/vmdpy Jun 14, 2024
@fkiraly
Copy link
Collaborator

fkiraly commented Jun 14, 2024

in #6598, @Cai-Chengyi posted a link to a repo with a potential fix: https://github.com/shenmusmart/VMD_python

@fkiraly fkiraly added bug Something isn't working lib:vmdpy vmdpy onboard library labels Jun 14, 2024
@fkiraly fkiraly added this to Needs triage & validation in Bugfixing via automation Jun 14, 2024
@fkiraly
Copy link
Collaborator

fkiraly commented Jun 14, 2024

@LorchZachery, this seems like a fix - would you, or anyone else in this thread, like to make a PR with the fix and add a test?

@fkiraly fkiraly moved this from Needs triage & validation to Reproduced/confirmed in Bugfixing Jun 14, 2024
@fkiraly fkiraly added the good first issue Good for newcomers label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers lib:vmdpy vmdpy onboard library
Projects
Bugfixing
Reproduced/confirmed
Development

No branches or pull requests

7 participants