|
5 | 5 | [](https://coveralls.io/github/JuliaDiffEq/DataDrivenDiffEq.jl?branch=master) |
6 | 6 | [](http://codecov.io/github/JuliaDiffEq/DataDrivenDiffEq.jl?branch=master) |
7 | 7 |
|
8 | | -DataDrivenDiffEq.jl is a component package in the DifferentialEquations ecosystem. |
9 | | -It holds the tools for data-driven differential equation structural estimation and identification. |
10 | | -Users interested in using this functionality should check out |
11 | | -[DifferentialEquations.jl](https://github.com/JuliaDiffEq/DifferentialEquations.jl). |
| 8 | +DataDrivenDiffEq.jl is a package in the SciML ecosystem for data-driven differential equation |
| 9 | +structural estimation and identification. These tools include automatically discovering equations |
| 10 | +from data and using this to simulate perturbed dynamics. |
12 | 11 |
|
13 | | -## Documentation |
| 12 | +For information on using the package, |
| 13 | +[see the stable documentation](https://datadriven.sciml.ai/stable/). Use the |
| 14 | +[in-development documentation](https://datadriven.sciml.ai/dev/) for the version of |
| 15 | +the documentation which contains the un-released features. |
14 | 16 |
|
15 | | -Extensive documentation of this functionality is on the [Structural Estimation page](http://docs.juliadiffeq.org/dev/analysis/structural_estimation.html). |
| 17 | +## Quick Demonstration |
| 18 | + |
| 19 | +```julia |
| 20 | +## Generate some data by solving a differential equation |
| 21 | +######################################################## |
| 22 | + |
| 23 | +using DataDrivenDiffEq |
| 24 | +using ModelingToolkit |
| 25 | +using OrdinaryDiffEq |
| 26 | + |
| 27 | +using LinearAlgebra |
| 28 | +using Plots |
| 29 | +gr() |
| 30 | + |
| 31 | +# Create a test problem |
| 32 | +function lorenz(u,p,t) |
| 33 | + x, y, z = u |
| 34 | + ẋ = 10.0*(y - x) |
| 35 | + ẏ = x*(28.0-z) - y |
| 36 | + ż = x*y - (8/3)*z |
| 37 | + return [ẋ, ẏ, ż] |
| 38 | +end |
| 39 | + |
| 40 | +u0 = [-8.0; 7.0; 27.0] |
| 41 | +p = [10.0; -10.0; 28.0; -1.0; -1.0; 1.0; -8/3] |
| 42 | +tspan = (0.0,100.0) |
| 43 | +dt = 0.001 |
| 44 | +problem = ODEProblem(lorenz,u0,tspan) |
| 45 | +solution = solve(problem, Tsit5(), saveat = dt, atol = 1e-7, rtol = 1e-8) |
| 46 | + |
| 47 | +X = Array(solution) |
| 48 | +DX = similar(X) |
| 49 | +for (i, xi) in enumerate(eachcol(X)) |
| 50 | + DX[:,i] = lorenz(xi, [], 0.0) |
| 51 | +end |
| 52 | + |
| 53 | +## Now automatically discover the system that generated the data |
| 54 | +################################################################ |
| 55 | + |
| 56 | +@variables x y z |
| 57 | +u = Operation[x; y; z] |
| 58 | +polys = Operation[] |
| 59 | +for i ∈ 0:4 |
| 60 | + for j ∈ 0:i |
| 61 | + for k ∈ 0:j |
| 62 | + push!(polys, u[1]^i*u[2]^j*u[3]^k) |
| 63 | + push!(polys, u[2]^i*u[3]^j*u[1]^k) |
| 64 | + push!(polys, u[3]^i*u[1]^j*u[2]^k) |
| 65 | + end |
| 66 | + end |
| 67 | +end |
| 68 | + |
| 69 | +basis = Basis(polys, u) |
| 70 | + |
| 71 | +opt = STRRidge(0.1) |
| 72 | +Ψ = SInDy(X, DX, basis, maxiter = 100, opt = opt, normalize = true) |
| 73 | +print_equations(Ψ) |
| 74 | +get_error(Ψ) |
| 75 | +``` |
| 76 | + |
| 77 | +``` |
| 78 | +3 dimensional basis in ["x", "y", "z"] |
| 79 | +dx = p₁ * x + p₂ * y |
| 80 | +dy = p₃ * x + p₄ * y + z * x * p₅ |
| 81 | +dz = p₆ * z + x * y * p₇ |
| 82 | +
|
| 83 | +# Error |
| 84 | +3-element Array{Float64,1}: |
| 85 | + 6.7202639134663155e-12 |
| 86 | + 3.505423292198665e-11 |
| 87 | + 1.2876598297504605e-11 |
| 88 | +``` |
0 commit comments