Giter Site home page Giter Site logo

Tweedie loglikelihood returning inf for some values and impacting constrained optimization. Related to use of scipy's wrigh_bessel function in computing likelihood. about statsmodels HOT 8 OPEN

diegodebrito avatar diegodebrito commented on June 15, 2024 1
Tweedie loglikelihood returning inf for some values and impacting constrained optimization. Related to use of scipy's wrigh_bessel function in computing likelihood.

from statsmodels.

Comments (8)

lorentzenchr avatar lorentzenchr commented on June 15, 2024

The first (non-zero) value is x = 1.452e+5 and alpha=-1. Now, wright_bessel(1, 0, 1e5) = 2.356e+275 and np.finfo(np.float64).max = 1.798e+308. So the simple answer is that wright_bessel(1, 0, 1.4e5) is simply larger than the max floating point number.

I think the tweedie package treats it differently and works with the logarithm of Wright's Bessel function, thus avoiding the overflow.

from statsmodels.

diegodebrito avatar diegodebrito commented on June 15, 2024

Thanks for the answer and for opening the Scipy issue, @lorentzenchr

In your opinion, would it be better to wait/push for the Scipy update and then modify the wright_bessel here? Or would it be a good idea to remove wright_bessel and try to add the more detailed calculations here? I noticed that glum and tweedie packages have the latter. I'm not familiar with Scipy's release cycle, so not sure what the timeline for that feature would be.

Also interested on your input here, @josef-pkt

from statsmodels.

lorentzenchr avatar lorentzenchr commented on June 15, 2024

That's a question for @josef-pkt to answer and it also depends on you expected timeline. I will only pursue the "proper" solution with scipy. Let's see how they respond.

from statsmodels.

josef-pkt avatar josef-pkt commented on June 15, 2024

(I'm currently stuck in a very different neighborhood of statistics and have not looked at the details for this.)

If there is a workaround that can be added in statsmodels, then it would be good to have it because it would also work with older scipy versions, e.g. we copied some code from scipy to statsmodels.compat to make parts available faster.

However, if there is no good replacement for (compiled) scipy.special functions, then we just have to wait for the fix/enhancement in scipy and the release cycle.

from statsmodels.

diegodebrito avatar diegodebrito commented on June 15, 2024

Great point, @josef-pkt. An alternative implementation wouldn't limit users to the eventual version of SciPy with the fix. I'm interest in working on this. We would love to have everything available in Statsmodels and not have to rely on the Tweedie package.

A question for you both regarding licenses @josef-pkt @lorentzenchr Can I read code available in other packages to help with this? Or should I rely on papers only? I think Tweedie and GLUM licenses are pretty permissive, but I don't want to start looking at the source code if I'm not allowed to.

from statsmodels.

josef-pkt avatar josef-pkt commented on June 15, 2024

GLUM https://github.com/Quantco/glum is also BSD-3 licensed, so there is no restriction looking at their code, or even copying parts.
@thequackdaddy was the original contributor of tweedie in statsmodels. His package might not have much additional to our code, but I haven't looked at it.

from statsmodels.

josef-pkt avatar josef-pkt commented on June 15, 2024

related:
tweedie family is missing get_distribution. We currently do not have a distribution class for it, AFAICS

from statsmodels.

lorentzenchr avatar lorentzenchr commented on June 15, 2024

With scipy/scipy#20646 merged, as of (future) scipy 1.14, statsmodels can replace log(wright_bessel) with log_wright_bessel. This should solve this issue.

from statsmodels.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.