Skip to content

Commit

Permalink
Merge branch 'master' into docs_update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Oct 6, 2023
2 parents c9ab921 + 75ebbc3 commit 3560a97
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 220 deletions.
20 changes: 20 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,23 @@ steps:
timeout_in_minutes: 680
# Don't run Buildkite if the commit message includes the text [skip tests]
if: build.message !~ /\[skip tests\]/

steps:
- label: "Documentation"
plugins:
- JuliaCI/julia#v1:
version: "1"
command: |
julia --project=docs -e '
println("--- :julia: Instantiating project")
using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()
println("+++ :julia: Building documentation")
include("docs/make.jl")'
agents:
queue: "juliagpu"
cuda: "*"
if: build.message !~ /\[skip docs\]/ && !build.pull_request.draft
timeout_in_minutes: 1000

env:
SECRET_DOCUMENTER_KEY: "yBJHrf5zUPu3VFotb0W4TRdauMTGgNUei3ax0xrVTmcrrP3EX8zSGaj9MNZji9H6JqyNEhCqZMGcHhxR5XK0f97YjhAp5rDNpwV6FbIXY8FXgFyIOLAenYUklta1W6fNM7KTz3Dq3UnKBAprKhQBwUw3SldTuvtm+IhiVT2rFmADqxMSQcv+5LivYEgAFrrd6LX+PHhonj38VN46z5Bi3TOIGAnByVlZssX7cOwaRg/8TloLPsWAUlQiPr89Vdlow9k6SQV8W9mf00/Rq4LFd1Eq1EYTCSmReVawMxVpXh1mj7MSabf9ppVWYOmjP5Rzatk8YFWlJf80HVvzY7tXRQ==;U2FsdGVkX1/UmKrEQkyqoZY6GckLGmpV5SsPa2byZhZbomiJKIrLntTIHK9GclgfCJ1MDCKhuo3hMVxq+NKVm0QmnMZk0Hlzszx8Up5pbcuSb2BA0Wm7IJzZ5/2uXfdBOXIejwk+GUabJtSpiDlYJUW/8bOWYZUwl9rmrOM44tPesEcs5yMZPShIowZnJqrvQUcWXZ/+aZjftX+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30wMdk1pdKbjgiGdq2wF1nPb4fOGBSoFtk8USmDSno1/FnYRKCH4gcyV3x/vHflFUHlSbh5Aw43YT1wxASJt7lvPq/uSTVw8wVe0bavIW4Gzyk7Fds5fjEi0eyZRtCfAbPlsCQ6aybuZQD870vdT8bxc1sRTdjDRbtFy8PGQqRwR91MhqITLOT7FpptcwltMV9jsGAEXBS6EX754sT3hYLB9OK6INME0rAbHUmq9tvCknIAiH3LIwuJJHHBLEFVeYveTk/00iBHjvn4Yb9MYEPaiTgMcQwRz8khf1aWj/Vz16c2aOjdiZOBEDpxH5h5tJLAMmc8bHfVAhWqdC6hDaulAgHEuo5gcKbkIbWEX/jvuOJq0fO9EYz6eDwwPy6hGGB5pzasJIKUDvXRCh40f5Iy8DOcLJRh+KCxjD9zDqhQQZ8WC+9l1/brckKPw59n0F3Sh3c+nHfyYBBlmsONTmjUZTgRwqg92z+2YQWyUf7g5jmNtBEjLyXtNvn9HkZGXd9YVp7Ps10GklGQiKYZmWUl73KGtsfsRF+/SQ4kRumd4YnlC7b04w6tFRk3HMog+38OVZDwMj40unK4XJWYABJX0t2XySGlXrL8ZNW8xR/iCVsW6+4glxFvTeH5ujPUjQKFb/0bvbZeExeYnRECdDz6u3z/gQYZiUMA8NUNKJuQTzWV9nXyubOWEG9NuJZ4X7oaGE/DtWO3j57r8bcE9KdtV+DpGvKyS+lBrdxL5vlOJ3rX+PqWeIOkxKc85lKT/us8H054bVubQebl0Tc+rvyqZVM7MToHgDj9VwlEbfV6o02Em/J5JUh0GMCoJw6CX5rfHgAIPlhlh/wXRVj8FQcUiTSzDb8lpwXxGO9rNWNfgE9ZRduiXT5LnUYhf6BC5eomyvZ6DcqDABJyWIV7kejbT0TlspicebTzP/kMyTPrGM9TchZjMdv6bPp8jRf4lUGWBjD4i1Diris5aM="
30 changes: 0 additions & 30 deletions .github/workflows/Documentation.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pages = ["index.md",
"ODE PINN Tutorials" => Any["Introduction to NeuralPDE for ODEs" => "tutorials/ode.md",
"Baysian PINNs - Lotka-Volterra" => "examples/Lotka_Volterra_BPINNs.md"
"Bayesian PINNs for Coupled ODEs - Lotka-Volterra" => "examples/Lotka_Volterra_BPINNs.md"
#"examples/nnrode_example.md", # currently incorrect
],
"PDE PINN Tutorials" => Any["Introduction to NeuralPDE for PDEs" => "tutorials/pdesystem.md",
Expand Down
83 changes: 34 additions & 49 deletions docs/src/examples/Lotka_Volterra_BPINNs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ The Lotka–Volterra equations, also known as the predator–prey equations, are
These differential equations are frequently used to describe the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
The populations change through time according to the pair of equations

$$
```math
\begin{aligned}
\frac{\mathrm{d}x}{\mathrm{d}t} &= (\alpha - \beta y(t))x(t), \\
\frac{\mathrm{d}y}{\mathrm{d}t} &= (\delta x(t) - \gamma)y(t)
\end{aligned}
$$
```

where $x(t)$ and $y(t)$ denote the populations of prey and predator at time $t$, respectively, and $\alpha, \beta, \gamma, \delta$ are positive parameters.

Expand All @@ -23,7 +23,9 @@ We then solve the equations and estimate the parameters of the model with priors

And also solve the equations for the constructed ODEProblem's provided ideal `p` values using a Lux.jl Neural Network, chain_lux.

```julia
```julia
using NeuralPDE, Flux, Lux, Plots, StatsPlots, OrdinaryDiffEq, Distributions

function lotka_volterra(u, p, t)
# Model parameters.
α, β, γ, δ = p
Expand All @@ -43,11 +45,11 @@ p = [1.5, 1.0, 3.0, 1.0]
tspan = (0.0, 6.0)
prob = ODEProblem(lotka_volterra, u0, tspan, p)

# Plot simulation.
```
With the [`saveat` argument](https://docs.sciml.ai/latest/basics/common_solver_opts/) we can specify that the solution is stored only at `saveat` time units(default saveat=1 / 50.0).

```julia
# Plot solution got by Standard DifferentialEquations.jl ODE solver
solution = solve(prob, Tsit5(); saveat = 0.05)
plot(solve(prob, Tsit5()))

Expand All @@ -58,67 +60,49 @@ To make the example more realistic we add random normally distributed noise to t


```julia
# Dataset creation for parameter estimation
# Dataset creation for parameter estimation (30% noise)
time = solution.t
u = hcat(solution.u...)
x = u[1, :] + 0.5 * randn(length(u[1, :]))
y = u[2, :] + 0.5 * randn(length(u[1, :]))
u = hcat(solution.u...)
x = u[1, :] + (0.3 .*u[1, :]).*randn(length(u[1, :]))
y = u[2, :] + (0.3 .*u[2, :]).*randn(length(u[2, :]))
dataset = [x, y, time]

# Neural Networks must have 2 outputs as u -> [dx,dy] in function lotka_volterra()
chainflux = Flux.Chain(Flux.Dense(1, 6, tanh), Flux.Dense(6, 6, tanh), Flux.Dense(6, 2)) |> Flux.f64
chainflux = Flux.Chain(Flux.Dense(1, 6, tanh), Flux.Dense(6, 6, tanh),
Flux.Dense(6, 2)) |> Flux.f64
chainlux = Lux.Chain(Lux.Dense(1, 7, Lux.tanh), Lux.Dense(7, 7, Lux.tanh),
Lux.Dense(7, 2))

chainlux = Lux.Chain(Lux.Dense(1, 6, Lux.tanh), Lux.Dense(6, 6, Lux.tanh), Lux.Dense(6, 2))
```
A Dataset is required as parameter estimation is being done using provided priors in `param` keyword argument for BNNODE.

```julia
alg1 = NeuralPDE.BNNODE(chainflux,
dataset = dataset,
draw_samples = 1000,
l2std = [
0.05,
0.05,
],
phystd = [
0.05,
0.05,
],
priorsNNw = (0.0,
3.0),
l2std = [0.1, 0.1],
phystd = [0.1, 0.1],
priorsNNw = (0.0, 3.0),
param = [
Normal(1,
2),
Normal(2,
2),
Normal(2,
2),
Normal(0,
2),
],
n_leapfrog = 30, progress = true)
Normal(1, 2),
Normal(2, 2),
Normal(2, 2),
Normal(0, 2),
], progress = true)

sol_flux_pestim = solve(prob, alg1)

# Dataset not needed as we are solving the equation with ideal parameters
alg2 = NeuralPDE.BNNODE(chainlux,
draw_samples = 1000,
l2std = [
0.05,
0.05,
],
phystd = [
0.05,
0.05,
],
priorsNNw = (0.0,
3.0),
n_leapfrog = 30, progress = true)
phystd = [0.05, 0.05],
priorsNNw = (0.0, 10.0),
progress = true)

sol_lux = solve(prob, alg2)

#testing timepoints must match keyword arg `saveat`` timepoints of solve() call
t=collect(Float64,prob.tspan[1]:1/50.0:prob.tspan[2])
t = collect(Float64, prob.tspan[1]:(1 / 50.0):prob.tspan[2])

```

Expand All @@ -133,13 +117,14 @@ plot(t,sol_flux_pestim.ensemblesol[1])
plot!(t,sol_flux_pestim.ensemblesol[2])

# estimated ODE parameters by .estimated_ode_params, weights and biases by .estimated_nn_params
println(sol_flux_pestim.estimated_ode_params)
sol_flux_pestim.estimated_nn_params
sol_flux_pestim.estimated_ode_params


# plotting solution for x,y for chain_lux
plot(t,sol_lux_pestim.ensemblesol[1])
plot!(t,sol_lux_pestim.ensemblesol[2])
plot(t,sol_lux.ensemblesol[1])
plot!(t,sol_lux.ensemblesol[2])

# estimated weights and biases by .estimated_nn_params for chain_lux
sol_lux_pestim.estimated_nn_params
```
# estimated weights and biases by .estimated_nn_params for chain_lux
sol_lux.estimated_nn_params

```
4 changes: 2 additions & 2 deletions docs/src/examples/ks.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Let's consider the Kuramoto–Sivashinsky equation, which contains a 4th-order d
∂_t u(x, t) + u(x, t) ∂_x u(x, t) + \alpha ∂^2_x u(x, t) + \beta ∂^3_x u(x, t) + \gamma ∂^4_x u(x, t) = 0 \, ,
```

where `\alpha = \gamma = 1` and `\beta = 4`. The exact solution is:
where $\alpha = \gamma = 1$ and $\beta = 4$. The exact solution is:

```math
u_e(x, t) = 11 + 15 \tanh \theta - 15 \tanh^2 \theta - 15 \tanh^3 \theta \, ,
```

where `\theta = t - x/2` and with initial and boundary conditions:
where $\theta = t - x/2$ and with initial and boundary conditions:

```math
\begin{align*}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/param_estim.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Consider a Lorenz System,
\end{align*}
```

with Physics-Informed Neural Networks. Now we would consider the case where we want to optimize the parameters `\sigma`, `\beta`, and `\rho`.
with Physics-Informed Neural Networks. Now we would consider the case where we want to optimize the parameters $\sigma$, $\beta$, and $\rho$.

We start by defining the problem,

Expand Down
Loading

0 comments on commit 3560a97

Please sign in to comment.