Speeding up the calculation of a binomial sum

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Is it possible to speed up this calculation?
A[j_, p_, n_] := Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j]
Plot[A[j, 0.5, 12000], j, 0, 12000]
Thanks!
performance-tuning probability-or-statistics summation
add a comment |Â
up vote
2
down vote
favorite
Is it possible to speed up this calculation?
A[j_, p_, n_] := Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j]
Plot[A[j, 0.5, 12000], j, 0, 12000]
Thanks!
performance-tuning probability-or-statistics summation
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Is it possible to speed up this calculation?
A[j_, p_, n_] := Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j]
Plot[A[j, 0.5, 12000], j, 0, 12000]
Thanks!
performance-tuning probability-or-statistics summation
Is it possible to speed up this calculation?
A[j_, p_, n_] := Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j]
Plot[A[j, 0.5, 12000], j, 0, 12000]
Thanks!
performance-tuning probability-or-statistics summation
performance-tuning probability-or-statistics summation
asked 1 hour ago
GambitSquared
1,010518
1,010518
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
The expression inside the Sum is actually built into Mathematica as BernsteinBasis, which gets primarily used in the construction of Bézier curves. Applied to this situation, we have the formula
A[j_, p_, n_] := Sum[BernsteinBasis[n, k, p], k, 0, j, Method -> "Procedural"]
which ought to be very stable to evaluate. If needed, however, one can also implement the de Casteljau formula so that the Bernstein polynomials are recursively generated instead.
(back to gedanken Mathematica, so untested)
add a comment |Â
up vote
2
down vote
The summation can be evaluated to a closed form, which can speed up the further usage:
Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j] // FullSimplify
(1 - p)^n ((1/(1 - p))^n - (1 - p)^(-1 - j) p^(1 + j)
Binomial[n, 1 + j] Hypergeometric2F1[1, 1 + j - n, 2 + j,
p/(-1 + p)])
add a comment |Â
up vote
2
down vote
Mathematica complains due to the occurence of very small numbers that cannot be represented in machine precision. However, the built-in cummulative distribution function (CDF) of the BinomialDistribution is sufficiently robust against that (replacing very small numbers simply by 0.).
A[j_, p_, n_] := CDF[BinomialDistribution[n, p], j]
nn = 120;
Plot[A[j, 0.5, nn], j, 0, nn]

nn = 12000;
Plot[A[j, 0.5, nn], j, 0, nn]

add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
The expression inside the Sum is actually built into Mathematica as BernsteinBasis, which gets primarily used in the construction of Bézier curves. Applied to this situation, we have the formula
A[j_, p_, n_] := Sum[BernsteinBasis[n, k, p], k, 0, j, Method -> "Procedural"]
which ought to be very stable to evaluate. If needed, however, one can also implement the de Casteljau formula so that the Bernstein polynomials are recursively generated instead.
(back to gedanken Mathematica, so untested)
add a comment |Â
up vote
3
down vote
The expression inside the Sum is actually built into Mathematica as BernsteinBasis, which gets primarily used in the construction of Bézier curves. Applied to this situation, we have the formula
A[j_, p_, n_] := Sum[BernsteinBasis[n, k, p], k, 0, j, Method -> "Procedural"]
which ought to be very stable to evaluate. If needed, however, one can also implement the de Casteljau formula so that the Bernstein polynomials are recursively generated instead.
(back to gedanken Mathematica, so untested)
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The expression inside the Sum is actually built into Mathematica as BernsteinBasis, which gets primarily used in the construction of Bézier curves. Applied to this situation, we have the formula
A[j_, p_, n_] := Sum[BernsteinBasis[n, k, p], k, 0, j, Method -> "Procedural"]
which ought to be very stable to evaluate. If needed, however, one can also implement the de Casteljau formula so that the Bernstein polynomials are recursively generated instead.
(back to gedanken Mathematica, so untested)
The expression inside the Sum is actually built into Mathematica as BernsteinBasis, which gets primarily used in the construction of Bézier curves. Applied to this situation, we have the formula
A[j_, p_, n_] := Sum[BernsteinBasis[n, k, p], k, 0, j, Method -> "Procedural"]
which ought to be very stable to evaluate. If needed, however, one can also implement the de Casteljau formula so that the Bernstein polynomials are recursively generated instead.
(back to gedanken Mathematica, so untested)
answered 1 hour ago
J. M. is computer-lessâ¦
94.8k10294454
94.8k10294454
add a comment |Â
add a comment |Â
up vote
2
down vote
The summation can be evaluated to a closed form, which can speed up the further usage:
Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j] // FullSimplify
(1 - p)^n ((1/(1 - p))^n - (1 - p)^(-1 - j) p^(1 + j)
Binomial[n, 1 + j] Hypergeometric2F1[1, 1 + j - n, 2 + j,
p/(-1 + p)])
add a comment |Â
up vote
2
down vote
The summation can be evaluated to a closed form, which can speed up the further usage:
Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j] // FullSimplify
(1 - p)^n ((1/(1 - p))^n - (1 - p)^(-1 - j) p^(1 + j)
Binomial[n, 1 + j] Hypergeometric2F1[1, 1 + j - n, 2 + j,
p/(-1 + p)])
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The summation can be evaluated to a closed form, which can speed up the further usage:
Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j] // FullSimplify
(1 - p)^n ((1/(1 - p))^n - (1 - p)^(-1 - j) p^(1 + j)
Binomial[n, 1 + j] Hypergeometric2F1[1, 1 + j - n, 2 + j,
p/(-1 + p)])
The summation can be evaluated to a closed form, which can speed up the further usage:
Sum[Binomial[n, k] p^k (1 - p)^(n - k), k, 0, j] // FullSimplify
(1 - p)^n ((1/(1 - p))^n - (1 - p)^(-1 - j) p^(1 + j)
Binomial[n, 1 + j] Hypergeometric2F1[1, 1 + j - n, 2 + j,
p/(-1 + p)])
answered 1 hour ago
ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2,6741826
2,6741826
add a comment |Â
add a comment |Â
up vote
2
down vote
Mathematica complains due to the occurence of very small numbers that cannot be represented in machine precision. However, the built-in cummulative distribution function (CDF) of the BinomialDistribution is sufficiently robust against that (replacing very small numbers simply by 0.).
A[j_, p_, n_] := CDF[BinomialDistribution[n, p], j]
nn = 120;
Plot[A[j, 0.5, nn], j, 0, nn]

nn = 12000;
Plot[A[j, 0.5, nn], j, 0, nn]

add a comment |Â
up vote
2
down vote
Mathematica complains due to the occurence of very small numbers that cannot be represented in machine precision. However, the built-in cummulative distribution function (CDF) of the BinomialDistribution is sufficiently robust against that (replacing very small numbers simply by 0.).
A[j_, p_, n_] := CDF[BinomialDistribution[n, p], j]
nn = 120;
Plot[A[j, 0.5, nn], j, 0, nn]

nn = 12000;
Plot[A[j, 0.5, nn], j, 0, nn]

add a comment |Â
up vote
2
down vote
up vote
2
down vote
Mathematica complains due to the occurence of very small numbers that cannot be represented in machine precision. However, the built-in cummulative distribution function (CDF) of the BinomialDistribution is sufficiently robust against that (replacing very small numbers simply by 0.).
A[j_, p_, n_] := CDF[BinomialDistribution[n, p], j]
nn = 120;
Plot[A[j, 0.5, nn], j, 0, nn]

nn = 12000;
Plot[A[j, 0.5, nn], j, 0, nn]

Mathematica complains due to the occurence of very small numbers that cannot be represented in machine precision. However, the built-in cummulative distribution function (CDF) of the BinomialDistribution is sufficiently robust against that (replacing very small numbers simply by 0.).
A[j_, p_, n_] := CDF[BinomialDistribution[n, p], j]
nn = 120;
Plot[A[j, 0.5, nn], j, 0, nn]

nn = 12000;
Plot[A[j, 0.5, nn], j, 0, nn]

answered 1 hour ago
Henrik Schumacher
42k260125
42k260125
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184002%2fspeeding-up-the-calculation-of-a-binomial-sum%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
