Last active
February 8, 2024 13:48
-
-
Save ferreiro/2b5caac126b58bebce82 to your computer and use it in GitHub Desktop.
Poisson distribution formula in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var k_total = 10; // number of times the event is repeated | |
var landa = 8; // Promedian number of error expected in a given time (Landa symbol) | |
var exponential = 2.718281828; | |
var total = 0; | |
var numerator, denominator; | |
// Sumatorio de k terminos usando la formula de poisson | |
function poisson(k, landa) { | |
exponentialPower = Math.pow(exponential, -landa); // negative power k | |
landaPowerK = Math.pow(landa, k); // Landa elevated k | |
numerator = exponentialPower * landaPowerK; | |
denominator = fact(k); // factorial of k. | |
return (numerator / denominator); | |
} | |
for (var i = 0; i < k_total; i++) { | |
total += poisson(i, landa); | |
} | |
console.log("Total sum is " + total); | |
function fact(x) { | |
if(x==0) { | |
return 1; | |
} | |
return x * fact(x-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for share your code. This has helped me a lot.