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

Fix: Incorrect use of partial in TweedieDistribution._rowwise_gradient_hessian #889

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bili2002
Copy link

This PR addresses issue #888 by fixing the incorrect use of partial in the TweedieDistribution._rowwise_gradient_hessian function.

Checklist

  • Added a CHANGELOG.rst entry

Copy link
Collaborator

@stanmart stanmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding fixing this! I believe there is a similar mistake here:

f = partial(inv_gaussian_log_eta_mu_deviance, p=self.power)

Could you please address it too so that they are in the same PR?

Also, I think it'd be worth adding a test case that would have spotted these bugs (maybe here?), but I'm also o kay with doing it later.

@stanmart
Copy link
Collaborator

Hm, it might be a bit more involved than that. Is it possible that inv_gaussian_log_rowwise_gradient_hessian is incorrect? Shouldn't it be

@@ -276,12 +276,12 @@ def inv_gaussian_log_rowwise_gradient_hessian(
         inv_mu = 1 / mu[i]
         inv_mu2 = inv_mu ** 2
 
-        gradient_rows_out[i] = 2 * weights[i] * (inv_mu - y[i] * inv_mu2)
-        hessian_rows_out[i] = 2 * weights[i] * (inv_mu - 2 * y[i] * inv_mu2)
+        gradient_rows_out[i] = weights[i] * (y[i] * inv_mu2 - inv_mu)
+        hessian_rows_out[i] = weights[i] * (2 * y[i] * inv_mu2 - inv_mu)

instead?

Copy link
Collaborator

@stanmart stanmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants