/** * Calculate the regression parameters by least squares on linearized data * y⁻¹ = K * V⁻¹ * x⁻¹ + V⁻¹ */ public function calculate() { // Linearize the relationship by taking the inverse of both x and y $x’ = Single::pow($this->xs, -1); $y’ = Single::pow($this->ys, -1); // Perform Least Squares Fit $linearized_parameters = $this->leastSquares($y’, $x’)->getColumn(0); // Translate the linearized parameters back. $V = 1 / $linearized_parameters[0]; $K = $linearized_parameters[1] * $V; $this->parameters = [$V, $K]; }
/** * p-norm (|x|p) * Also known as lp norm * * https://en.wikipedia.org/wiki/Norm_(mathematics)#p-norm * * |x|p = (∑|xᵢ|ᵖ)¹/ᵖ * * @return number */ public function pNorm($p) { return array_sum(Map\Single::pow($this->A, $p)) ** (1 / $p); }