v = $force[0]; $this->w = $force[1]; parent::__construct($points); } /** * Calculates the regression parameters. * * @throws \MathPHP\Exception\BadDataException * @throws \MathPHP\Exception\IncorrectTypeException * @throws \MathPHP\Exception\MatrixException * @throws \MathPHP\Exception\MathException */ public function calculate() { $v = $this->v; $w = $this->w; $x’ = Single::subtract($this->xs, $v); $y’ = Single::subtract($this->ys, $w); $parameters = $this->leastSquares($y’, $x’, 1, 0)->getColumn(0); $m = $parameters[0]; $b = $this->w - $m * $this->v; $this->parameters = [$b, $m]; } /** * Evaluate the regression equation at x * Uses the instance model's evaluateModel method. * * @param float $x * * @return float */ public function evaluate(float $x): float { return $this->evaluateModel($x, $this->parameters); } }