From 555241282bb812ba979ae34d34dd95fb1d97ef12 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 25 Jan 2019 21:27:01 -0500 Subject: [PATCH] Compute tanh derivative as 1 - tanh(x)^2 The intention here is to allow CSE to re-use the value it computed on the forward pass. --- src/rules.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules.jl b/src/rules.jl index 4285d87..f6a976e 100644 --- a/src/rules.jl +++ b/src/rules.jl @@ -47,7 +47,7 @@ @define_diffrule Base.acotd(x) = :( -180 / π / (1 + $x^2) ) @define_diffrule Base.sinh(x) = :( cosh($x) ) @define_diffrule Base.cosh(x) = :( sinh($x) ) -@define_diffrule Base.tanh(x) = :( sech($x)^2 ) +@define_diffrule Base.tanh(x) = :( 1 - tanh($x)^2 ) @define_diffrule Base.sech(x) = :( -tanh($x) * sech($x) ) @define_diffrule Base.csch(x) = :( -coth($x) * csch($x) ) @define_diffrule Base.coth(x) = :( -(csch($x)^2) )