Created
November 5, 2019 17:51
-
-
Save galo2099/69a65f1cfd1baa6362a731532ad090bb to your computer and use it in GitHub Desktop.
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
function poisson(k, landa) { | |
exponentialPower = Math.exp(-landa); // negative power k | |
landaPowerK = Math.pow(landa, k); // Landa elevated k | |
numerator = exponentialPower * landaPowerK; | |
denominator = fact(k); // factorial of k. | |
return (numerator / denominator); | |
} | |
function fact(x) { | |
if(x==0) { | |
return 1; | |
} | |
return x * fact(x-1); | |
} | |
function ESPERADO(g_home, xg_home, g_away, xg_away) { | |
var rps = 0.0; | |
var cdf_xhome = 0.0; | |
var cdf_xaway = 0.0; | |
var cdf_home = 0.0; | |
var cdf_away = 0.0; | |
for (var i = 0; i < 10; i++) { | |
cdf_xhome += poisson(i, xg_home); | |
cdf_xaway += poisson(i, xg_away); | |
if (i == g_home) cdf_home += 1.0; | |
if (i == g_away) cdf_away += 1.0; | |
rps += (cdf_xhome - cdf_home) * (cdf_xhome - cdf_home); | |
rps += (cdf_away - cdf_away) * (cdf_xaway - cdf_away); | |
} | |
return rps / 9; | |
} | |
function JUSTICA(g_home, xg_home, g_away, xg_away) { | |
var cdf_x = 0.0; | |
var cdf_y = 0.0; | |
var rps = 0.0; | |
for (var i = -9; i < 10; i++) { | |
for (var j = 0; j < 10; j++) { | |
for (var k = 0; k < 10; k++) { | |
if (j - k != i) continue; | |
cdf_x += poisson(j, xg_home) * poisson(k, xg_away); | |
if (j == g_home && k == g_away) { | |
cdf_y += 1.0; | |
} | |
} | |
} | |
rps += (cdf_x - cdf_y) * (cdf_x - cdf_y) | |
} | |
return rps / 18; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment