Giter Club home page Giter Club logo

Comments (4)

dschmitz89 avatar dschmitz89 commented on June 15, 2024

Thanks for the report. Could you elaborate with a minimal working example for which parameter values the error occurs? I have a hard time interpreting the Wolfram Alpha computarion. The same holds for the other issue you opened.

from scipy.

dschmitz89 avatar dschmitz89 commented on June 15, 2024

Thanks for adding the MWE, that helps a lot.

from scipy.

tk-yoshimura avatar tk-yoshimura commented on June 15, 2024

For example, if the following code is executed:

import numpy as np
import scipy.stats as stats

x = np.arange(0, 16).astype(np.int32)
dist = stats.zipf(9.0)
pmf = dist.pmf(x)

print(pmf)

The values are as expected.

[0.00000000e+00 9.97995633e-01 1.94921022e-03 5.07034310e-05
3.80705121e-06 5.10973764e-07 9.90301387e-08 2.47312621e-08
7.43564690e-09 2.57600117e-09 9.97995633e-10 4.23247571e-10
1.93418240e-10 9.41105843e-11 4.83032464e-11 2.59601567e-11]

However, if the shape parameter is an integer, an incorrect value is obtained for x>=11, as shown below.

import numpy as np
import scipy.stats as stats

x = np.arange(0, 16).astype(np.int32)
dist = stats.zipf(9)
pmf = dist.pmf(x)

print(pmf)

[0.00000000e+00 9.97995633e-01 1.94921022e-03 5.07034310e-05
3.80705121e-06 5.10973764e-07 9.90301387e-08 2.47312621e-08
7.43564690e-09 2.57600117e-09 9.97995633e-10 0.00000000e+00
1.15400158e-09 4.95390192e-10 0.00000000e+00 0.00000000e+00]

When executing the following lines
_discrete_distns.py L1309

def _pmf(self, k, a):
    # zipf.pmf(k, a) = 1/(zeta(a) * k**a)
    Pk = 1.0 / special.zeta(a, 1) / k**a
    return Pk

The input value k and the shape parameter a are both integer types, which may be causing the overflow.

from scipy.

dschmitz89 avatar dschmitz89 commented on June 15, 2024

That is indeed the issue. The maximum value for int32 is $2147483647$ but $11^9=2357947691$. We could cast k to float, then do *k**-a instead. Would you be interested in drafting a PR?

from scipy.

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.