map('tanh'); } /** * Calculate the derivative of the activation. * * @internal * * @param \Tensor\Matrix $input * @param \Tensor\Matrix $output * @return \Tensor\Matrix */ public function differentiate(Matrix $input, Matrix $output) : Matrix { return $output->map([$this, '_differentiate']); } /** * @internal * * @param float $output * @return float */ public function _differentiate(float $output) : float { return 1.0 - ($output ** 2); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Hyperbolic Tangent'; } }