Flux.jl
我想使用和绘制一个函数及其梯度Plots.jl
using Flux.Tracker
using Plots
f(x::Float64) = 3x^2 + 2x + 1
df(x::Float64) = Tracker.gradient(f, x)[1]
d2f(x::Float64) = Tracker.gradient(df, x)[1]
plot([f], -2, 2)
plot!([df], -2, 2)
我得到:
ERROR: LoadError: MethodError: no method matching Float64(::Flux.Tracker.TrackedReal{Float64})
Closest candidates are:
Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:194
Float64(::T<:Number) where T<:Number at boot.jl:741
Float64(::Int8) at float.jl:60
所以我想这个想法是转换Flux.Tracker.TrackedReal{Float64}
成Float64
. 我怎么能做到?