Coder Social home page Coder Social logo

Comments (1)

cgobat avatar cgobat commented on June 7, 2024

I just checked the following:

from scipy.integrate import quad # function-based numeric integration/quadrature utility

p = a_u(200,10,15) # test value

integral, abserr = quad(p.pdf, p.value-(p.minus*6), p.value+(p.plus*6)) # arguments are (func, a, b)

print(integral) # outputs 0.9999999980336641

This seems like it's working as expected. Similarly, we could do

from scipy.integrate import trapezoid # array-based numeric integration utility

datap = a_u(200,10,15)
num_sigma = 5
discretization = 500
neg_x = np.linspace(datap.value-(num_sigma*datap.minus),datap.value,discretization)
pos_x = np.linspace(datap.value,datap.value+(num_sigma*datap.plus),discretization) # I changed this line relative to your example from datap.minus to datap.plus
x_arr = np.array(list(neg_x)+list(pos_x))

pdf = np.piecewise(x_arr, [x_arr<datap.value, x_arr>=datap.value],
                   [lambda y : np.sqrt(2)/np.sqrt(np.pi)/(datap.plus+datap.minus) * np.exp(-1*(y-datap.value)**2 / (2*datap.minus**2)),
                    lambda y : np.sqrt(2)/np.sqrt(np.pi)/(datap.plus+datap.minus) * np.exp(-1*(y-datap.value)**2 / (2*datap.plus**2))] )

integral = trapezoid(y=pdf, x=x_arr)

print(integral) # outputs 0.9999999980259466

Upon confirming that it seems to be doing the right thing, I realized the issue: in your second-to-last line, you divide by discretization to compute delta. The evaluation of the PDF uses a total of 2*discretization points, since there are discretization points both to the left and to the right of the nominal value. So there's the mystery factor of 2!

from asymmetric_uncertainty.

Related Issues (13)

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.