MathPHP\Probability\Distribution\Continuous\Continuous::inverse PHP Method

inverse() public static method

For example, if the calling class CDF definition is CDF($x, $d1, $d2) than the inverse is called as inverse($target, $d1, $d2)
public static inverse ( number $target, $params )
$target number The area for which we are trying to find the $x
$params List of all the parameters that are needed for the CDF of the calling class. This list must be absent the $x parameter.
    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;
    }