Steganalysis/PhaseAwareNet_SRC/MatConvNet/matconvnet-1.0-beta20/matlab/vl_nntanh.m

22 lines
636 B
Mathematica
Raw Normal View History

2021-12-30 11:48:37 +00:00
function out = vl_nntanh(x,dzdy)
%VL_NNTANH CNN TanH hyperbolic non-linearity
% Y = VL_NNTANH(X) computes the hyperbolic tangent non-linearity of the
% data X. X can have an arbitrary size. The tanh is defined as follows:
%
% TANH(X) = (EXP(2X) - 1 )/( EXP(2x) + 1 ).
%
% DZDX = VL_NNTANH(X, DZDY) computes the derivative of the
% block projected onto DZDY. DZDX and DZDY have the same
% dimensions as X and Y respectively.
%
% NOTE: Matlab build-in function TANH() is used since it has extended
% support for gpuArray
y = tanh( x );
if nargin <= 1 || isempty(dzdy)
out = y;
else
out = dzdy .* ( 1 - y.*y );
end