dimensions = $dimensions; } /** * Return the data types that this transformer is compatible with. * * @internal * * @return list */ public function compatibility() : array { return [ DataType::continuous(), ]; } /** * Is the transformer fitted? * * @return bool */ public function fitted() : bool { return isset($this->r); } /** * Fit the transformer to a dataset. * * @param Dataset $dataset * @throws InvalidArgumentException */ public function fit(Dataset $dataset) : void { SamplesAreCompatibleWithTransformer::with($dataset, $this)->check(); $this->r = Matrix::gaussian($dataset->numFeatures(), $this->dimensions); } /** * Transform the dataset in place. * * @param list> $samples * @throws RuntimeException */ public function transform(array &$samples) : void { if (!$this->r) { throw new RuntimeException('Transformer has not been fitted.'); } $samples = Matrix::quick($samples) ->matmul($this->r) ->asArray(); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return "Gaussian Random Projector (dimensions: {$this->dimensions})"; } }