Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions .JuliaFormatter.toml

This file was deleted.

14 changes: 10 additions & 4 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: "Format Check"
name: format-check

on:
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:

jobs:
format-check:
name: "Format Check"
uses: "SciML/.github/.github/workflows/format-check.yml@v1"
runic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fredrikekre/runic-action@v1
with:
version: '1'
46 changes: 30 additions & 16 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Pkg

function dev_subpkg(subpkg)
subpkg_path = abspath(joinpath(dirname(@__FILE__), "..", "lib", subpkg))
Pkg.develop(PackageSpec(path = subpkg_path))
return Pkg.develop(PackageSpec(path = subpkg_path))
end

dev_subpkg("DataDrivenDMD")
Expand Down Expand Up @@ -50,25 +50,34 @@ function create_tutorials(dirname, targetdir, excludes = [])
mdpost(str) = replace(str, "@__CODE__" => code)
Literate.markdown(ipath, targetdir)
Literate.markdown(ipath, targetdir, execute = false, postprocess = mdpost)
push!(tutorials,
relpath(joinpath(targetdir, fname * ".md"), joinpath(@__DIR__, "src")))
push!(
tutorials,
relpath(joinpath(targetdir, fname * ".md"), joinpath(@__DIR__, "src"))
)
end
end
return tutorials
end

koopman_tutorial = create_tutorials(joinpath(@__DIR__, "src/libs/datadrivendmd/"),
joinpath(@__DIR__, "src/libs/datadrivendmd/examples"))
sparse_tutorial = create_tutorials(joinpath(@__DIR__, "src/libs/datadrivensparse/"),
joinpath(@__DIR__, "src/libs/datadrivensparse/examples"))
sr_tutorial = create_tutorials(joinpath(@__DIR__, "src/libs/datadrivensr/"),
joinpath(@__DIR__, "src/libs/datadrivensr/examples"))
koopman_tutorial = create_tutorials(
joinpath(@__DIR__, "src/libs/datadrivendmd/"),
joinpath(@__DIR__, "src/libs/datadrivendmd/examples")
)
sparse_tutorial = create_tutorials(
joinpath(@__DIR__, "src/libs/datadrivensparse/"),
joinpath(@__DIR__, "src/libs/datadrivensparse/examples")
)
sr_tutorial = create_tutorials(
joinpath(@__DIR__, "src/libs/datadrivensr/"),
joinpath(@__DIR__, "src/libs/datadrivensr/examples")
)

# Must be after tutorials is created
include("pages.jl")

# Create the docs
makedocs(sitename = "DataDrivenDiffEq.jl",
makedocs(
sitename = "DataDrivenDiffEq.jl",
authors = "Julius Martensen, Christopher Rackauckas, et al.",
modules = [DataDrivenDiffEq, DataDrivenDMD, DataDrivenSparse, DataDrivenSR],
clean = true, doctest = false, linkcheck = true,
Expand All @@ -77,11 +86,16 @@ makedocs(sitename = "DataDrivenDiffEq.jl",
"http://cwrowley.princeton.edu/papers/Hemati-2017a.pdf",
"https://royalsocietypublishing.org/doi/10.1098/rspa.2020.0279",
"https://www.pnas.org/doi/10.1073/pnas.1517384113",
"https://link.springer.com/article/10.1007/s00332-015-9258-5"
"https://link.springer.com/article/10.1007/s00332-015-9258-5",
],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/DataDrivenDiffEq/stable/"),
pages = pages)
format = Documenter.HTML(
assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/DataDrivenDiffEq/stable/"
),
pages = pages
)

deploydocs(repo = "github.com/SciML/DataDrivenDiffEq.jl.git";
push_preview = true)
deploydocs(
repo = "github.com/SciML/DataDrivenDiffEq.jl.git";
push_preview = true
)
17 changes: 10 additions & 7 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ pages = [
"Basis" => "basis.md",
"Solutions" => "solutions.md",
"Utilities" => "utils.md",
"DataDrivenDMD" => ["Background" => "libs/datadrivendmd/koopman.md",
"Examples" => koopman_tutorial
"DataDrivenDMD" => [
"Background" => "libs/datadrivendmd/koopman.md",
"Examples" => koopman_tutorial,
],
"DataDrivenSparse" => ["Background" => "libs/datadrivensparse/sparse_regression.md",
"Examples" => sparse_tutorial
"DataDrivenSparse" => [
"Background" => "libs/datadrivensparse/sparse_regression.md",
"Examples" => sparse_tutorial,
],
"DataDrivenSR" => ["Background" => "libs/datadrivensr/symbolic_regression.md",
"Examples" => sr_tutorial
"DataDrivenSR" => [
"Background" => "libs/datadrivensr/symbolic_regression.md",
"Examples" => sr_tutorial,
],
"Citing" => "citations.md"
"Citing" => "citations.md",
]
2 changes: 1 addition & 1 deletion docs/src/libs/datadrivendmd/example_01.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ get_basis(res)
#md # ```

## Test the result #src
@test rss(res) <= 1e-3 #src
@test rss(res) <= 1.0e-3 #src
@test r2(res) >= 0.99 #src
@test dof(res) == 3 #src
2 changes: 1 addition & 1 deletion docs/src/libs/datadrivendmd/example_04.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using DataDrivenDMD

function slow_manifold(du, u, p, t)
du[1] = p[1] * u[1]
du[2] = p[2] * (u[2] - u[1]^2)
return du[2] = p[2] * (u[2] - u[1]^2)
end

u0 = [3.0; -2.0]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/libs/datadrivendmd/example_05.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
# System dynamics
function controlled_system!(du, u, p, t)
ctrl = control_signal(t)
du .= A_true * u .+ B_true .* ctrl
return du .= A_true * u .+ B_true .* ctrl
end

# Generate "experimental" data
Expand Down
4 changes: 2 additions & 2 deletions docs/src/libs/datadrivensparse/example_01.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# # [Getting Started](@id getting_started)
#
# The workflow for [DataDrivenDiffEq.jl](https://github.com/SciML/DataDrivenDiffEq.jl) is similar to other [SciML](https://sciml.ai/) packages.
# The workflow for [DataDrivenDiffEq.jl](https://github.com/SciML/DataDrivenDiffEq.jl) is similar to other [SciML](https://sciml.ai/) packages.
# You start by defining a [`DataDrivenProblem`](@ref) and then dispatch on the [`solve`](@ref solve) command to return a [`DataDrivenSolution`](@ref).

# Here is an outline of the required elements and choices:
Expand All @@ -13,7 +13,7 @@ using ModelingToolkit
using LinearAlgebra
using DataDrivenSparse

# Generate a test problem
# Generate a test problem

f(u) = u .^ 2 .+ 2.0u .- 1.0
X = randn(1, 100);
Expand Down
12 changes: 8 additions & 4 deletions docs/src/libs/datadrivensparse/example_02.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ ts = sol.t;
# Using a [collocation method](@ref collocation), it automatically provides the derivative and smoothes the trajectory. Control signals can be passed
# in as a function `(u,p,t)->control` or an array of measurements.

prob = ContinuousDataDrivenProblem(X, ts, GaussianKernel(),
prob = ContinuousDataDrivenProblem(
X, ts, GaussianKernel(),
U = (u, p, t) -> [exp(-((t - 5.0) / 5.0)^2)],
p = ones(2))
p = ones(2)
)

#md plot(prob, size = (600,600))

Expand All @@ -65,8 +67,10 @@ println(basis) # hide
sampler = DataProcessing(split = 0.8, shuffle = true, batchsize = 30, rng = rng)
λs = exp10.(-10:0.1:0)
opt = STLSQ(λs)
res = solve(prob, basis, opt,
options = DataDrivenCommonOptions(data_processing = sampler, digits = 1))
res = solve(
prob, basis, opt,
options = DataDrivenCommonOptions(data_processing = sampler, digits = 1)
)
#src println(res) #hide

# !!! info
Expand Down
16 changes: 10 additions & 6 deletions docs/src/libs/datadrivensparse/example_03.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using DataDrivenSparse
using Test #src

function michaelis_menten(u, p, t)
[0.6 - 1.5u[1] / (0.3 + u[1])]
return [0.6 - 1.5u[1] / (0.3 + u[1])]
end

u0 = [0.5]
Expand All @@ -23,10 +23,14 @@ ode_problem = ODEProblem(michaelis_menten, u0, (0.0, 4.0));
# Since we have multiple trajectories at hand, we define a [`DataDrivenDataset`](@ref), which collects multiple problems but handles them as a unit
# for the processing.

prob = DataDrivenDataset(map(1:2) do i
solve(remake(ode_problem, u0 = i * u0),
Tsit5(), saveat = 0.1, tspan = (0.0, 4.0))
end...)
prob = DataDrivenDataset(
map(1:2) do i
solve(
remake(ode_problem, u0 = i * u0),
Tsit5(), saveat = 0.1, tspan = (0.0, 4.0)
)
end...
)

#md plot(prob)

Expand All @@ -44,7 +48,7 @@ basis = Basis([h; h .* (D(u[1]))], u, implicits = D.(u), iv = t)
# Next, we define the [`ImplicitOptimizer`](@ref) and `solve` the problem. It wraps a standard optimizer, by default [`STLSQ`](@ref), and performs
# implicit sparse regression upon the selected basis.

opt = ImplicitOptimizer(1e-1:1e-1:5e-1)
opt = ImplicitOptimizer(1.0e-1:1.0e-1:5.0e-1)
res = solve(prob, basis, opt)
#md println(res) #hide

Expand Down
6 changes: 4 additions & 2 deletions docs/src/libs/datadrivensparse/example_04.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ basis = Basis(eqs, x, independent_variable = t, implicits = D.(x))
# Next to varying over different sparsity penalties, we also want to batch our data using [`DataProcessing`](@ref).

sampler = DataProcessing(split = 0.8, shuffle = true, batchsize = 30)
res = solve(dd_prob, basis, ImplicitOptimizer(STLSQ(1e-2:1e-2:1.0)),
options = DataDrivenCommonOptions(data_processing = sampler, digits = 2))
res = solve(
dd_prob, basis, ImplicitOptimizer(STLSQ(1.0e-2:1.0e-2:1.0)),
options = DataDrivenCommonOptions(data_processing = sampler, digits = 2)
)
#md println(res) #hide

# And have a look at the resulting plot
Expand Down
24 changes: 14 additions & 10 deletions docs/src/libs/datadrivensparse/example_05.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function cart_pole(u, p, t)
du[1] = u[3]
du[2] = u[4]
du[3] = -(19.62 * sin(u[1]) + sin(u[1]) * cos(u[1]) * u[3]^2 + F * cos(u[1])) /
(2 - cos(u[1])^2)
(2 - cos(u[1])^2)
du[4] = -(sin(u[1]) * u[3]^2 + 9.81 * sin(u[1]) * cos(u[1]) + F) / (2 - cos(u[1])^2)
return du
end
Expand All @@ -35,15 +35,17 @@ for (i, xi) in enumerate(eachcol(X))
end
t = solution.t

ddprob = ContinuousDataDrivenProblem(X, t, DX = DX[3:4, :],
U = (u, p, t) -> [-0.2 + 0.5 * sin(6 * t)])
ddprob = ContinuousDataDrivenProblem(
X, t, DX = DX[3:4, :],
U = (u, p, t) -> [-0.2 + 0.5 * sin(6 * t)]
)

#md plot(ddprob)

# Note that we just included the third and forth time derivative, assuming that we already know that the velocity `x[3:4]` is equal to the time
# Note that we just included the third and forth time derivative, assuming that we already know that the velocity `x[3:4]` is equal to the time
# derivative of the position `x[1:2]`.
# Next, we define a sufficient [`Basis`](@ref). Again, we need to include `implicits` in the definition of
# our candidate functions and inform the [`Basis`](@ref) of it.
# Next, we define a sufficient [`Basis`](@ref). Again, we need to include `implicits` in the definition of
# our candidate functions and inform the [`Basis`](@ref) of it.

@parameters t
@variables u[1:4] du[1:2] x[1:1]
Expand All @@ -70,8 +72,10 @@ basis = Basis(implicits, u, implicits = du, controls = x, iv = t);

# We solve the problem by varying over a sufficient set of thresholds for the associated optimizer.

λ = [1e-4; 5e-4; 1e-3; 2e-3; 3e-3; 4e-3; 5e-3; 6e-3; 7e-3; 8e-3; 9e-3; 1e-2; 2e-2; 3e-2;
4e-2; 5e-2]
λ = [
1.0e-4; 5.0e-4; 1.0e-3; 2.0e-3; 3.0e-3; 4.0e-3; 5.0e-3; 6.0e-3; 7.0e-3; 8.0e-3; 9.0e-3; 1.0e-2; 2.0e-2; 3.0e-2;
4.0e-2; 5.0e-2
]

opt = ImplicitOptimizer(λ)
res = solve(ddprob, basis, opt)
Expand All @@ -81,8 +85,8 @@ res = solve(ddprob, basis, opt)
system = get_basis(res)
#md println(system) # hide

# We have recovered the correct equations of motion!
# Another visual check using the problem and the result yields
# We have recovered the correct equations of motion!
# Another visual check using the problem and the result yields

#md plot(
#md plot(ddprob), plot(res), layout = (1,2)
Expand Down
8 changes: 5 additions & 3 deletions docs/src/libs/datadrivensr/example_01.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ prob = ContinuousDataDrivenProblem(X, t, U = U)
# To solve our problem, we will use [`EQSearch`](@ref), which provides a wrapper for the [symbolic regression interface](https://ai.damtp.cam.ac.uk/symbolicregression/stable/api/#Options).
# We will stick to simple operations, use a `L1DistLoss`, and limit the verbosity of the algorithm.

eqsearch_options = SymbolicRegression.Options(binary_operators = [+, *],
eqsearch_options = SymbolicRegression.Options(
binary_operators = [+, *],
loss = L1DistLoss(),
verbosity = -1, progress = false, npop = 30,
timeout_in_seconds = 60.0)
timeout_in_seconds = 60.0
)

alg = EQSearch(eq_options = eqsearch_options)

Expand Down Expand Up @@ -68,5 +70,5 @@ system = get_basis(res)
#md # ```

## Test #src
@test rss(res) .<= 5e-1 #src
@test rss(res) .<= 5.0e-1 #src
@test r2(res) >= 0.95 #src
10 changes: 6 additions & 4 deletions docs/src/libs/datadrivensr/example_02.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using DataDrivenSR

function pendulum!(du, u, p, t)
du[1] = u[2]
du[2] = -9.81 * sin(u[1])
return du[2] = -9.81 * sin(u[1])
end

u0 = [0.1, π / 2]
Expand All @@ -35,10 +35,12 @@ u = collect(u)

basis = Basis([polynomial_basis(u, 2); sin.(u)], u)

eqsearch_options = SymbolicRegression.Options(binary_operators = [+, *],
eqsearch_options = SymbolicRegression.Options(
binary_operators = [+, *],
loss = L1DistLoss(),
verbosity = -1, progress = false, npop = 30,
timeout_in_seconds = 60.0)
timeout_in_seconds = 60.0
)

alg = EQSearch(eq_options = eqsearch_options)

Expand All @@ -63,5 +65,5 @@ system = get_basis(res)
#md # ```

## Test #src
@test rss(res) .<= 5e-2 #src
@test rss(res) .<= 5.0e-2 #src
@test r2(res) >= 0.95 #src
2 changes: 1 addition & 1 deletion lib/DataDrivenDMD/src/DataDrivenDMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using LinearAlgebra

abstract type AbstractKoopmanAlgorithm <: AbstractDataDrivenAlgorithm end

# Results
# Results
include("./result.jl")
export KoopmanResult
export get_operator, get_inputmap, get_outputmap, get_trainerror, get_testerror
Expand Down
Loading
Loading