degree = $degree; } /** * Return the data types that this transformer is compatible with. * * @internal * * @return list */ public function compatibility() : array { return [ DataType::continuous(), ]; } /** * Transform the dataset in place. * * @param array $samples */ public function transform(array &$samples) : void { array_walk($samples, [$this, 'expand']); } /** * Expand the continuous features of a sample. * * @param list $sample */ protected function expand(array &$sample) : void { $vector = []; foreach ($sample as $value) { $vector[] = $value; for ($exponent = 2; $exponent <= $this->degree; ++$exponent) { $vector[] = $value ** $exponent; } } $sample = $vector; } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return "Polynomial Expander (degree: {$this->degree})"; } }