threshold = $threshold; } /** * Compute the activation. * * @internal * * @param Matrix $input * @return Matrix */ public function activate(Matrix $input) : Matrix { return $input->map([$this, '_activate']); } /** * Calculate the derivative of the activation. * * @internal * * @param Matrix $input * @param Matrix $output * @return Matrix */ public function differentiate(Matrix $input, Matrix $output) : Matrix { return $input->greater($this->threshold); } /** * @internal * * @param float $input * @return float */ public function _activate(float $input) : float { return $input > $this->threshold ? $input : 0.0; } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return "Thresholded ReLU (threshold: {$this->threshold})"; } }