protected function differentiate(Matrix $z) : Matrix
    {
        if (!$this->alpha) {
            throw new RuntimeException('Layer has not been initlaized.');
        }

        $alphas = $this->alpha->w();

        $gradient = [];

        foreach ($z as $i => $row) {
            $alpha = $alphas[$i];

            $temp = [];

            foreach ($row as $value) {
                $temp[] = $value > 0. ? 1. : $alpha;
            }

            $gradient[] = $temp;
        }

        return Matrix::quick($gradient);
    }
protected function differentiate(Matrix $z) : Matrix
    {
        if (!$this->alpha) {
            throw new RuntimeException('Layer has not been initlaized.');
        }

        $alphas = $this->alpha->w();

        $gradient = [];

        foreach ($z as $i => $row) {
            $alpha = $alphas[$i];

            $temp = [];

            foreach ($row as $value) {
                $temp[] = $value > 0. ? 1. : $alpha;
            }

            $gradient[] = $temp;
        }

        return Matrix::quick($gradient);
    }
protected function differentiate ( Matrix $ z ) : Matrix { if ( ! $ this -> alpha ) { throw new RuntimeException ( 'Layer has not been initlaized.' ) ; } $ alphas = $ this -> alpha -> w ( ) ; $ gradient = [ ] ; foreach ( $ z as $ i => $ row ) { $ alpha = $ alphas [ $ i ] ; $ temp = [ ] ; foreach ( $ row as $ value ) { $ temp [ ] = $ value > 0. ? 1. : $ alpha ; } $ gradient [ ] = $ temp ; } return Matrix :: quick ( $ gradient ) ; }
Calculate the partial derivatives of the activation function.

@param \Rubix\Tensor\Matrix $z
@throws \RuntimeException
@return \Rubix\Tensor\Matrix
Calculate the partial derivatives of the activation function .