subtract() public static method

Map subtract
public static subtract ( array $xs, number $k ) : array
$xs array
$k number Number to subtract from each element
return array
 /**
  * Calculates the regression parameters.
  */
 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);
     $this->m = $parameters[0];
     $this->b = $this->w - $this->m * $this->v;
     $this->parameters = [$this->b, $this->m];
 }
示例#2
0
 /**
  * Evaluate for x
  * Use the smoothness parameter α to determine the subset of data to consider for
  * local regression. Perform a weighted least squares regression and evaluate x.
  *
  * @param  number $x
  *
  * @return number
  */
 public function evaluate($x)
 {
     $α = $this->α;
     $λ = $this->λ;
     $n = $this->n;
     // The number of points considered in the local regression
     $Δx = Single::abs(Single::subtract($this->xs, $x));
     $αᵗʰΔx = Average::kthSmallest($Δx, $this->number_of_points - 1);
     $arg = Single::min(Single::divide($Δx, $αᵗʰΔx * max($α, 1)), 1);
     // Kernel function: tricube = (1-arg³)³
     $tricube = Single::cube(Single::multiply(Single::subtract(Single::cube($arg), 1), -1));
     $weights = $tricube;
     // Local Regression Parameters
     $parameters = $this->leastSquares($this->ys, $this->xs, $weights, $λ);
     $X = new VandermondeMatrix([$x], $λ + 1);
     return $X->multiply($parameters)[0][0];
 }