-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from JuliaDiffEq/reverse_mode
Reverse-Mode Neural ODE
- Loading branch information
Showing
7 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
OrdinaryDiffEq | ||
StochasticDiffEq | ||
DelayDiffEq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Flux, DiffEqFlux, DelayDiffEq, Plots | ||
|
||
## Setup DDE to optimize | ||
function delay_lotka_volterra(du,u,h,p,t) | ||
x, y = u | ||
α, β, δ, γ = p | ||
du[1] = dx = (α - β*y)*h(p,t-0.1)[1] | ||
du[2] = dy = (δ*x - γ)*y | ||
end | ||
h(p,t) = ones(eltype(p),2) | ||
prob = DDEProblem(delay_lotka_volterra,[1.0,1.0],h,(0.0,10.0),constant_lags=[0.1]) | ||
p = param([2.2, 1.0, 2.0, 0.4]) | ||
function predict_fd_dde() | ||
diffeq_fd(p,sol->sol[1,:],101,prob,MethodOfSteps(Tsit5()),saveat=0.1) | ||
end | ||
loss_fd_dde() = sum(abs2,x-1 for x in predict_fd_dde()) | ||
@test_broken loss_fd_dde() | ||
@test_broken Flux.back!(loss_fd_dde()) | ||
|
||
function predict_rd_dde() | ||
diffeq_rd(p,prob,MethodOfSteps(Tsit5()),saveat=0.1)[1,:] | ||
end | ||
loss_rd_dde() = sum(abs2,x-1 for x in predict_rd_dde()) | ||
loss_rd_dde() | ||
Flux.back!(loss_rd_dde()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Flux, DiffEqFlux, StochasticDiffEq, Plots | ||
|
||
function lotka_volterra(du,u,p,t) | ||
x, y = u | ||
α, β, δ, γ = p | ||
du[1] = dx = α*x - β*x*y | ||
du[2] = dy = -δ*y + γ*x*y | ||
end | ||
function lotka_volterra_noise(du,u,p,t) | ||
du[1] = 0.1u[1] | ||
du[2] = 0.1u[2] | ||
end | ||
prob = SDEProblem(lotka_volterra,lotka_volterra_noise,[1.0,1.0],(0.0,10.0)) | ||
p = param([2.2, 1.0, 2.0, 0.4]) | ||
function predict_fd_sde() | ||
diffeq_fd(p,sol->sol[1,:],101,prob,SOSRI(),saveat=0.1) | ||
end | ||
loss_fd_sde() = sum(abs2,x-1 for x in predict_fd_sde()) | ||
loss_fd_sde() | ||
Flux.back!(loss_fd_sde()) | ||
|
||
function predict_rd_sde() | ||
Array(diffeq_rd(p,prob,SOSRI(),saveat=0.1)) | ||
end | ||
loss_rd_sde() = sum(abs2,x-1 for x in predict_rd_sde()) | ||
loss_rd_sde() | ||
@test_broken Flux.back!(loss_rd_sde()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters