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

Gradients, second derivatives and hessians at pi not working #144

Open
islent opened this issue Dec 12, 2019 · 0 comments · May be fixed by #148
Open

Gradients, second derivatives and hessians at pi not working #144

islent opened this issue Dec 12, 2019 · 0 comments · May be fixed by #148

Comments

@islent
Copy link

islent commented Dec 12, 2019

You might need some fixes with README 😄
Related issues #40 #52 : float(pi) could fix this:

julia> using Calculus

julia> h1 = second_derivative(sin)
#6 (generic function with 1 method)

julia> h1(0.0)
0.0

julia> h1(1.0)
-0.841471649579559

julia> h1(pi)
ERROR: MethodError: no method matching eps(::Type{Irrational{:π}})
Closest candidates are:
  eps(::Dates.Time) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Dates\src\types.jl:387
  eps(::Dates.Date) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Dates\src\types.jl:386
  eps(::Dates.DateTime) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Dates\src\types.jl:385
  ...
Stacktrace:
 [1] finite_difference(::Calculus.var"#1#3"{typeof(sin),Symbol}, ::Irrational{:π}, ::Symbol) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\finite_difference.jl:27lus\mbqhh\src\finite_difference.jl:27
 [2] finite_difference_hessian(::Function, ::Function, ::Irrational{:π}, ::Symbol) at C:\Users\islent\.julia\packages\Calculus\mbqhh\ckages\Calculus\mbqhh\src\derivative.jl:27src\finite_difference.jl:224
 [3] (::Calculus.var"#6#8"{typeof(sin),Calculus.var"#1#3"{typeof(sin),Symbol},Symbol})(::Irrational{:π}) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\derivative.jl:27
 [4] top-level scope at REPL[5]:1

julia> h1(float(pi))
-1.3553766145945872e-7
julia> g2 = Calculus.gradient(x -> sin(x[1]) + cos(x[2]))
#2 (generic function with 1 method)

julia> g2([0.0, 0.0])
2-element Array{Float64,1}:
 0.9999999999868854
 0.0

julia> g2([1.0, 1.0])
2-element Array{Float64,1}:
  0.5403023058631036
 -0.8414709847974693

julia> g2([pi, pi])
ERROR: MethodError: no method matching Irrational{:π}(::Int64)
Closest candidates are:
  Irrational{:π}(::T) where T<:Number at boot.jl:718
  Irrational{:π}() where sym at irrationals.jl:18
  Irrational{:π}(::Complex) where T<:Real at complex.jl:37
  ...
Stacktrace:
 [1] convert(::Type{Irrational{:π}}, ::Int64) at .\number.jl:7
 [2] zero(::Type{Irrational{:π}}) at .\number.jl:266
 [3] float(::Array{Irrational{:π},1}) at .\float.jl:896
 [4] (::Calculus.var"#2#4"{var"#3#4",Symbol})(::Array{Irrational{:π},1}) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\derivative.jl:5
 [5] top-level scope at REPL[9]:1
julia> h2 = hessian(x -> sin(x[1]) + cos(x[2]))
#7 (generic function with 1 method)

julia> h2([0.0, 0.0])
2×2 Array{Float64,2}:
 -7.5693e-7   0.0     
  0.0        -0.999999

julia> h2([1.0, 1.0])
2×2 Array{Float64,2}:
 -0.841472   0.0
  0.0       -0.540303

julia> h2([pi, pi])
ERROR: MethodError: no method matching Irrational{:π}(::Int64)
Closest candidates are:
  Irrational{:π}(::T) where T<:Number at boot.jl:718
  Irrational{:π}() where sym at irrationals.jl:18
  Irrational{:π}(::Complex) where T<:Real at complex.jl:37
  ...
Stacktrace:
 [1] convert(::Type{Irrational{:π}}, ::Int64) at .\number.jl:7
 [2] zero(::Type{Irrational{:π}}) at .\number.jl:266
 [3] float(::Array{Irrational{:π},1}) at .\float.jl:896
 [4] (::Calculus.var"#2#4"{var"#5#6",Symbol})(::Array{Irrational{:π},1}) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\derivative.jl:5
 [5] finite_difference_jacobian(::Calculus.var"#2#4"{var"#5#6",Symbol}, ::Array{Irrational{:π},1}, ::Symbol) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\finite_difference.jl:197
 [6] finite_difference_hessian(::Function, ::Function, ::Array{Irrational{:π},1}, ::Symbol) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\finite_difference.jl:284
 [7] (::Calculus.var"#7#9"{var"#5#6",Calculus.var"#2#4"{var"#5#6",Symbol},Symbol})(::Array{Irrational{:π},1}) at C:\Users\islent\.julia\packages\Calculus\mbqhh\src\derivative.jl:29
 [8] top-level scope at REPL[15]:1
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.

1 participant