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

Zygote return Any[] for expectation() #19

Open
agerlach opened this issue Jul 24, 2020 · 0 comments
Open

Zygote return Any[] for expectation() #19

agerlach opened this issue Jul 24, 2020 · 0 comments

Comments

@agerlach
Copy link
Contributor

agerlach commented Jul 24, 2020

using OrdinaryDiffEq, Distributions, DiffEqUncertainty,
        ForwardDiff, Zygote, FiniteDiff, DiffEqSensitivity

function simplependulum(du,u,p,t)
    g, L = p
    du[1] = u[2]
    du[2] = -(g/L)*sin(u[1])
end

u0 =/2, 0.0]
p = [9.807, 1.0]
tspan = (0.0,5.0)
prob = ODEProblem(simplependulum, u0, tspan, p)

u0_dist = [Uniform/2.1, π/1.9), 0.0]
p_dist = [9.807, truncated(Normal(1.0,.1), 0.6, 1.4)]

g(sol) = sol[1,end]

# ∂𝔼/∂u0
test_u0(q) = expectation(g, prob, q, p_dist, Koopman(), Tsit5())[1]
@time df1 = ForwardDiff.gradient(test_u0,u0) #Float64[]
@time df2 = FiniteDiff.finite_difference_gradient(test_u0,u0) #Float64[]
@time df3 = Zygote.gradient(test_u0,u0)    #any[]

# ∂𝔼/∂p
test_p(q) = expectation(g, prob, u0_dist, q, Koopman(), Tsit5())[1]
@time df1 = ForwardDiff.gradient(test_p,p) #Float64[]
@time df2 = FiniteDiff.finite_difference_gradient(test_p,p) #Float64[]
@time df3 = Zygote.gradient(test_p,p) @any[]

However, the following properly returns Float64[] for some reason

# mixed u0/p
function test_mixed(q) 
    _u = [u0_dist[1], q[1]]
    _p = [q[2], p_dist[1]]
    expectation(g, prob, _u, _p, Koopman(), Tsit5())[1]
end

x0 = [u0[2], p[1]]
@time df1 = ForwardDiff.gradient(test_mixed,x0) #Float64[]
@time df2 = FiniteDiff.finite_difference_gradient(test_mixed,x0) #Float64[]
@time df3 = Zygote.gradient(test_mixed,x0) #Float64[]
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