How can I efficiently calculate the binomial cumulative distribution function?

后端 未结 10 937
你的背包
你的背包 2020-12-07 22:10

Let\'s say that I know the probability of a \"success\" is P. I run the test N times, and I see S successes. The test is akin to tossing an unevenly weighted coin (perhaps

10条回答
  •  轮回少年
    2020-12-07 22:46

    An efficient and, more importantly, numerical stable algorithm exists in the domain of Bezier Curves used in Computer Aided Design. It is called de Casteljau's algorithm used to evaluate the Bernstein Polynomials used to define Bezier Curves.

    I believe that I am only allowed one link per answer so start with Wikipedia - Bernstein Polynomials

    Notice the very close relationship between the Binomial Distribution and the Bernstein Polynomials. Then click through to the link on de Casteljau's algorithm.

    Lets say I know the probability of throwing a heads with a particular coin is P. What is the probability of me throwing the coin T times and getting at least S heads?

    • Set n = T
    • Set beta[i] = 0 for i = 0, ... S - 1
    • Set beta[i] = 1 for i = S, ... T
    • Set t = p
    • Evaluate B(t) using de Casteljau

    or at most S heads?

    • Set n = T
    • Set beta[i] = 1 for i = 0, ... S
    • Set beta[i] = 0 for i = S + 1, ... T
    • Set t = p
    • Evaluate B(t) using de Casteljau

    Open source code probably exists already. NURBS Curves (Non-Uniform Rational B-spline Curves) are a generalization of Bezier Curves and are widely used in CAD. Try openNurbs (the license is very liberal) or failing that Open CASCADE (a somewhat less liberal and opaque license). Both toolkits are in C++, though, IIRC, .NET bindings exist.

提交回复
热议问题