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

Strange behaviour of the derivative #26

Closed
Arkoniak opened this issue Jul 30, 2021 · 4 comments
Closed

Strange behaviour of the derivative #26

Arkoniak opened this issue Jul 30, 2021 · 4 comments

Comments

@Arkoniak
Copy link

I do not know, maybe I am missing something simple here

using Diffractor
using Plots

function f1(x)
    res = 0.0
    for i in 1:10
        res += x^i
    end
    res
end

f(x) = let var"'" = Diffractor.PrimeDerivativeFwd 
    f1'(x)
end


xs = -0.5:0.01:0.5
plot(xs, f1.(xs), legend = nothing)
plot!(xs, f.(xs))

It has this weird glitch in zero.

flameshot-2021-07-30T12-23-07

Info:

julia> versioninfo()
Julia Version 1.8.0-DEV.74
Commit ba5fffca7b (2021-06-24 02:52 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_PKG_SERVER =

(Diffractor) pkg> st
      Status `~/Projects/BabySteps/Diffractor/Project.toml`
  [d360d2e6] ChainRulesCore v1.0.2
  [9f5e2b26] Diffractor v0.1.1 `~/.julia/dev/Diffractor`
  [91a5bcdd] Plots v1.19.4
@antoine-levitt
Copy link
Collaborator

Simpler probably related issue:

julia> Diffractor.PrimeDerivativeFwd(x -> x^1)(0.0)
NaN

@mcabbott
Copy link
Member

Looks like it might be the same as FluxML/Zygote.jl#1036, Antoine's example on Zygote:

julia> using Zygote

julia> gradient(x -> x^1, 0.0)
(1.0,)

julia> gradient(x -> x^1.0, 0.0)
(0.0,)

@antoine-levitt
Copy link
Collaborator

Looks unrelated: this current bug is fixed by JuliaDiff/ChainRules.jl#485. The linked issue is about fractional powers, which is much more tricky to get right (because it is singular in general for float powers, although happens to be well-defined at integers)

@mcabbott
Copy link
Member

mcabbott commented Sep 5, 2021

I got some strange answers from reverse mode for this function, BTW. Only with Julia 1.8, details here: JuliaDiff/ChainRules.jl#513 (comment)

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

Successfully merging a pull request may close this issue.

3 participants