*/ 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, 'normalize']); } /** * Normalize a sample by its L2 norm. * * @param list $sample */ protected function normalize(array &$sample) : void { $norm = 0.0; foreach ($sample as $value) { $norm += $value ** 2; } if ($norm === 0.0) { return; } $norm = sqrt($norm); foreach ($sample as &$value) { $value /= $norm; } } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'L2 Normalizer'; } }