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

Negative weights for KDE #16

Open
Pablobala opened this issue Nov 21, 2022 · 2 comments
Open

Negative weights for KDE #16

Pablobala opened this issue Nov 21, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Pablobala
Copy link

I wanted to use the kalepy package on a SWeighted distribution, so there are many events with negative weights and I can't normalize them as the distribution would change. There is a ValueError in kalepy/kde.py, line 214: "Invalid weights entries, all must be finite and > 0!".
I would want to know if there is the possibility to adapt the code to run with negative weights or if the method just not allow the use of negative weights for some reason. Could someone clarify this to me?

Thanks in advance and Kind Regards.

@lzkelley lzkelley self-assigned this Nov 25, 2022
@lzkelley lzkelley added enhancement New feature or request good first issue Good for newcomers labels Nov 25, 2022
@lzkelley
Copy link
Owner

Hi, in principle it seems like this should be possible, but I've never explored negative weights. There will be some points in the code that need modification, for example, how does one calculate covariances using negative weights?

You're welcome to try implementing this in the code. If you disable the error message you're getting, it will allow negative weights, but then I think some numpy functions will probably throw errors.

@Pablobala
Copy link
Author

Hi, just to let you know. I didn't find a way to handle negative weights because of the errors numpy throws when trying to calculate the covariances. So what I did is to split my sample into positive and negative weights, apply the KDE to both samples, and then rest the weights from "negative" sample renormalizing them by the sum of the sWeights. This seems to work but there are some downsides. If someone could find a way for handling negative weights it would be better.
Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants