Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mean BigFloat precision #239

Open
edljk opened this issue Sep 18, 2023 · 0 comments
Open

mean BigFloat precision #239

edljk opened this issue Sep 18, 2023 · 0 comments

Comments

@edljk
Copy link

edljk commented Sep 18, 2023

I observed a loss of precision using ReverseDiff with respect to ForwardDiff on the following simple example:

julia> testprecision()
type precision eps(T)     = 1.7272337110188889250772703725600799142232e-77 

ForwardDiff error         = 0.0000000000000000000000000000000000000000e+00 
ReverseDiff error         = 8.6560832651618551196119417711416155844212e-19

Is it expected?
Thanks!

using Statistics, LinearAlgebra
using ForwardDiff, ReverseDiff, Printf

setprecision(2 ^ 8)

function testprecision(n::Int64 = 1_000, T::DataType = BigFloat)
    x = rand(T, n)
    f(x) = mean(x .^ 3) 
    gf = ForwardDiff.gradient(f, x)
    gr = ReverseDiff.gradient(f, x)
    gth = 3 * x .^ 2 / n 
    @printf "type precision eps(T)     = %4.40e \n\n" eps(T)
    @printf "ForwardDiff error         = %4.40e \n" norm(gf - gth)
    @printf "ReverseDiff error         = %4.40e \n" norm(gr - gth)
    nothing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant