Skip to content

rule for tanh has catastrophic cancellation for |x| > 20 #102

Closed

Description

@tpapp

One could simply revert #30 to fix this, but if one wants CSE then it can be calculated from first principles. I started a discussion which has numerical examples.

Activity

  1. devmotion commented on Dec 13, 2023

    @devmotion
    Member

    ChainRules should suffer from the same problem, possibly the rule was just copied to it from DiffRules: https://github.com/JuliaDiff/ChainRules.jl/blob/40b9058c1a6798a4f72bda1227786d584b44c822/src/rulesets/Base/fastmath_able.jl#L41

  2. stevengj commented on Dec 13, 2023

    @stevengj
    Contributor

    Note that the catastrophic cancellation happens way sooner than |x|=20 … by x = 4 the 1 - tanh(x)^2 formula has already lost 2 digits, by x = 6 it has lost 4 digits, and by x = 14 it has lost 10 digits.

    See also @tpapp's discourse thread on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions