stdDev = $stdDev; } /** * Return the width of the layer. * * @internal * * @throws RuntimeException * @return positive-int */ public function width() : int { if ($this->width === null) { throw new RuntimeException('Layer has not been initialized.'); } return $this->width; } /** * Initialize the layer with the fan in from the previous layer and return * the fan out for this layer. * * @internal * * @param positive-int $fanIn * @return positive-int */ public function initialize(int $fanIn) : int { $fanOut = $fanIn; $this->width = $fanOut; return $fanOut; } /** * Compute a forward pass through the layer. * * @internal * * @param Matrix $input * @return Matrix */ public function forward(Matrix $input) : Matrix { $noise = Matrix::gaussian(...$input->shape()) ->multiply($this->stdDev); $output = $input->add($noise); return $output; } /** * Compute an inferential pass through the layer. * * @internal * * @param Matrix $input * @return Matrix */ public function infer(Matrix $input) : Matrix { return $input; } /** * Calculate the gradients of the layer and update the parameters. * * @internal * * @param Deferred $prevGradient * @param Optimizer $optimizer * @return Deferred */ public function back(Deferred $prevGradient, Optimizer $optimizer) : Deferred { return $prevGradient; } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return "Noise (std dev: {$this->stdDev})"; } }