map([$this, '_compute']); } /** * Calculate the derivative of the activation. * * @internal * * @param Matrix $input * @param Matrix $output * @return Matrix */ public function differentiate(Matrix $input, Matrix $output) : Matrix { $ones = Matrix::ones(...$output->shape()); return $output->divide($input) ->multiply($ones->subtract($output)) ->add($output); } /** * @internal * * @param float $input * @return float */ public function _compute(float $input) : float { return $input / (1.0 + exp(-$input)); } /** * Return the string representation of the object. * * @return string */ public function __toString() : string { return 'SiLU'; } }