ghammad / pyActigraphy

Python-based open source package for actigraphy data analysis
https://ghammad.github.io/pyActigraphy
GNU General Public License v3.0
137 stars 25 forks source link

Bugs in adaptive median filter implementation (Crespo algorithm) #69

Open juliusandretti opened 3 years ago

juliusandretti commented 3 years ago

Greetings, hope you're doing well.

I've been running a few tests with your implementation of the Crespo algorithm confronting it with my own implementation and I've come across a few divergences, some are bugs and cause inaccuracies. On a previous issue, I told you about a bug in the inactivity mask, the ones I'm going to discuss now are newly discovered.

  1. In line 1130 of your /sleep/scoring_base.py script you use the rolling class from pandas with parameter min_periods. You should check that because min_periods may produce unexpected results when applied to series containing NaNs.
  2. Starting at line 1136 you use the expanding class from pandas with parameter center=True and it produces "unexpected" results. Please refer to expanding-git-issue.
  3. In line 1141 you apply an index reversion using "[::-1]". You should check that because it leads to indexing problems in subsequent pandas-related operations.

I hope this will help to improve the library. Keep up the good work.

Julius

ghammad commented 3 years ago

Hi Julius,

thank you for the feedback. It will definitely help to improve the package.

In order to proceed now, may I ask you to:

Or, if you have your own implementation of the Crespo algorithm, you could make a pull request and become a contributor of the package? Open-sourcing the project was done in that perspective.

Either way, thank you in advance for your help.

PS: I'll try to have all your issues resolved (#65 and #69) asap.

juliusandretti commented 3 years ago

Hello,

I'm referring to the latest commit on branch master. I'm attaching a script to this reply that I used to visualize the results of several rolling and expanding configurations, I think it will help you to understand what I'm talking about on points 1 and 2 and how it relates to your implementation. I've also added a minimal example demonstrating the issue with the [::-1] inversion.

Hope it helps. Julius

operation_probe.zip

juliusandretti commented 3 years ago

Hello,

I've just updated my first post. The link was missing on point 2, please check it out. Also, I've noticed that I had forgotten to write about one last point, so let me add it now:

  1. Slicing with [... : -1] causes the last point to be ignored. Correct slice should be [... : ]

Julius