Skip to content

Instantly share code, notes, and snippets.

@fatihgune
Created December 6, 2020 16:46
Show Gist options
  • Save fatihgune/356bd8e135338660860cb71560bac925 to your computer and use it in GitHub Desktop.
Save fatihgune/356bd8e135338660860cb71560bac925 to your computer and use it in GitHub Desktop.
Return Probability From the Table (PHP)
<?
public function returnProbabilityFromTheTable($zValue)
{
return $this->CDF($zValue);
}
public function sgn($x)
{
if ($x < 0) {
return -1;
}
return 1;
}
public function erf($x)
{
$e = exp(-$x * $x);
$e2 = exp(-$x * $x * 2);
$q = sqrt(pi()) / 2 + 31 * $e / 200 - 341 * $e2 / 8000;
return 2 * $this->sgn($x) * sqrt(1 - $e) * $q / sqrt(pi());
}
public function CDF($x)
{
return (1 + $this->erf($x / sqrt(2))) / 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment