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

Fixed NeuralDSDE #724

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/neural_de.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct NeuralDSDE{M,P,RE,M2,RE2,T,A,K} <: NeuralDELayer
re2 = nothing
new{typeof(model1),typeof(p),typeof(re1),typeof(model2),typeof(re2),
typeof(tspan),typeof(args),typeof(kwargs)}(p,
length(p1),model1,re1,model2,re2,tspan,args,kwargs)
Int(1),model1,re1,model2,re2,tspan,args,kwargs)
end
end

Expand All @@ -179,13 +179,13 @@ function (n::NeuralDSDE{M})(x,p=n.p) where {M<:FastChain}
solve(prob,n.args...;sensealg=TrackerAdjoint(),n.kwargs...)
end

function (n::NeuralDSDE{M})(x,p1,p2,st1,st2) where {M<:Lux.AbstractExplicitLayer}
function (n::NeuralDSDE{M})(x,p,st1,st2) where {M<:Lux.AbstractExplicitLayer}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia can unpack it

Suggested change
function (n::NeuralDSDE{M})(x,p,st1,st2) where {M<:Lux.AbstractExplicitLayer}
function (n::NeuralDSDE{M})(x,(p1, p2),st1,st2) where {M<:Lux.AbstractExplicitLayer}

Copy link
Contributor Author

@ba2tro ba2tro Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we need them to be packed in one p so that we can pass it to the SDEProblem
https://github.com/Abhishek-1Bhatt/DiffEqFlux.jl/blob/b3b7ae7208f03918bdaaf67b39b6775515dcc6e0/src/neural_de.jl#L193

which will then call our functions with p where we will dereference individual p1 and p2 from p

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I added parentheses it works with one p and Julia will unpack it like

p1, p2 = p

Copy link
Contributor Author

@ba2tro ba2tro Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but that is not the point where we want to break it apart(unpack it). If you check the line I referenced above, we want to have one p till there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. Now, I understand!

function dudt_(u,p,t)
u_, st1 = n.model1(u,p1,st1)
u_, st1 = n.model1(u,p[1],st1)
return u_
end
function g(u,p,t)
u_, st2 = n.model2(u,p2,st2)
u_, st2 = n.model2(u,p[2],st2)
return u_
end

Expand Down