<?php
function facdef($n) {
switch($n) {
case 0:
return 1;
case 1:
return 1;
case 2:
return 2;
case 3:
return 6;
case 4:
return 24;
case 5:
return 120;
case 6:
return 720;
case 7:
return 5040;
case 8:
return 40320;
case 9:
return 362880;
case 10:
return 3628800;
case 11:
return 39916800;
case 12:
return 479001600;
case 13:
return 6227020800;
case 14:
return 87178291200;
case 15:
return 1307674368000;
case 16:
return 20922789888000;
case 17:
return 355687428096000;
case 18:
return 6402373705728000;
case 19:
return 121645100408832000;
case 20:
return 2432902008176640000;
case 21:
return 51090942171709440000;
case 22:
return 1124000727777607680000;
case 23:
return 25852016738884976640000;
}
}
function constify($a) { #regression constants
return $a*0.424+0.548;
}
function scorefix($avg) { #if predicted score is small or negative, return something reasonable
if ( $avg < 0.01 ) { return 10^(10^$avg-1) / 105.50984676065602; }
else { return $avg; }
}
function sim($homeoff,$homedef,$awayoff,$awaydef,$mul,$natavg) { #returns homemu,awaymu for poisson to deal with
return array(scorefix((($homeoff-$natavg)*max(constify($awaydef*$mul),0.25)/constify($natavg*$mul)+$awaydef)*$mul),scorefix((($homedef-$natavg)*max(constify($awayoff/$mul),0.25)/constify($natavg/$mul)+$awayoff)/$mul));
}
function poisson($mu,$shift) { #returns array of poisson probabilities for scores
$x = [];
for ($i = 1 ; $i <= $shift ; $i++ ) {
array_push($x,0.0);
}
$pcdf = 0.0;
$a = exp(-1*$mu);
echo count($a);
while ( $pcdf < 0.999999 || count($x) < 5 ) {
echo $mu^(count($x)-$shift)."\n";
echo facdef(count($x)-$shift)."\n";
array_push($x,$a*($mu^(count($x)-$shift))/facdef(count($x)-$shift));
echo count($x);
$pcdf+=end($x);
}
return $x;
}
var_dump(poisson(1.1,0));
?>
preferences:
27.62 ms | 402 KiB | 5 Q