better / convoys

Implementation of statistical models to analyze time lagged conversions
https://better.engineering/convoys/
MIT License
258 stars 42 forks source link

Use more accurate gamma derivatives #96

Closed CamDavidsonPilon closed 5 years ago

CamDavidsonPilon commented 5 years ago

I too have struggled with gamma derivatives! This PR is my current best effort, so I can share it with convoys.

  1. Use an analytical solution for derivative w.r.t the x variable
  2. Use a O(h^4) order finite difference method w.r.t. the a (k) variable. This has much better stability in the second derivative too.

I've also included gammaincc, as gammaincc=1-gammainc and you have 1-gammainc in your code, so this is a possible small convenience.

erikbern commented 5 years ago

Nice! Really appreciate this. Maybe this should be its own (tiny) Python package that can be shared.

I can try to fix the build failure. Looks like logsumexp is missing for some reason.

CamDavidsonPilon commented 5 years ago

Maybe this should be its own (tiny) Python package that can be shared.

Yea! I thought about this too, something like autograd-gamma (I don't think the autograd folks would let an approximation in their library).

That might be the better solution - easier to accept contributions and add new extensions. hm..

CamDavidsonPilon commented 5 years ago

Yea, I think it's better: https://pypi.org/project/autograd-gamma/

erikbern commented 5 years ago

Awesome – will create a new PR to add this to convoys