public static function inverse($target, ...$params)
{
$initial = static::mean(...$params);
if (is_nan($initial)) {
$initial = static::median(...$params);
}
array_unshift($params, $initial);
$classname = get_called_class();
$CDF_callback = [$classname, 'CDF'];
$PDF_callback = [$classname, 'PDF'];
$tolerance = 1.0E-10;
$dif = $tolerance + 1;
$guess = $params[0];
while ($dif > $tolerance) {
// load the guess into the arguments
$params[0] = $guess;
$y = call_user_func_array($CDF_callback, $params);
// Since the CDF is the integral of the PDF, the PDF is the derivative of the CDF
$slope = call_user_func_array($PDF_callback, $params);
$del_y = $target - $y;
$guess = $del_y / $slope + $guess;
$dif = abs($del_y);
}
return $guess;
}