From ba264f2c8fdf2735f10f011d4cf9f54f92d02b22 Mon Sep 17 00:00:00 2001 From: JuliusMartensen Date: Mon, 8 Nov 2021 14:39:28 +0100 Subject: [PATCH 1/3] Fix docs mwe --- docs/src/getting_started.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md index 5ff84928b..f4ac81e1e 100644 --- a/docs/src/getting_started.md +++ b/docs/src/getting_started.md @@ -13,24 +13,21 @@ Here is an outline of the required elements and choices: ## Basic usage ```julia -using DataDrivenDiffEq, ModelingToolkit +using DataDrivenDiffEq, ModelingToolkit, LinearAlgebra # The function we are trying to find f(u) = u^2 + 4u + 4 -X = f.(1:100) # Generate data -X = reshape(X, length(X), 1) # Reshape into a matrix - +# +X = reduce(hcat, map(f, 1.0:1.0:100.0)) # Create a problem from the data problem = DiscreteDataDrivenProblem(X) # Choose a basis -@variables u[1:1] -using Symbolics: scalarize -u = scalarize(u) -basis = Basis(monomial_basis(u, 2), u) +@variables u +basis = Basis(monomial_basis([u], 2), [u]) # Solve the problem, using the solver of your choosing -res = solve(problem, basis, STLSQ()) +res = solve(problem, basis, STLSQ(1e-3)) ``` ## Defining a Problem From 57a531fff508cf51c0e82705586aba9a9c46ec0b Mon Sep 17 00:00:00 2001 From: JuliusMartensen Date: Mon, 8 Nov 2021 14:51:11 +0100 Subject: [PATCH 2/3] Fixed wrong getting started / useage in build solu --- docs/src/getting_started.md | 17 ++++++++++++----- src/solution.jl | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md index f4ac81e1e..049da2284 100644 --- a/docs/src/getting_started.md +++ b/docs/src/getting_started.md @@ -16,18 +16,25 @@ Here is an outline of the required elements and choices: using DataDrivenDiffEq, ModelingToolkit, LinearAlgebra # The function we are trying to find -f(u) = u^2 + 4u + 4 -# -X = reduce(hcat, map(f, 1.0:1.0:100.0)) +f(u) = u.^2 .+ 2.0u .- 1.0 +# +X = randn(1, 100) +Y = reduce(hcat, map(f, eachcol(X))) # Create a problem from the data -problem = DiscreteDataDrivenProblem(X) +problem = DirectDataDrivenProblem(X, Y) # Choose a basis @variables u basis = Basis(monomial_basis([u], 2), [u]) +println(basis) + + + # Solve the problem, using the solver of your choosing -res = solve(problem, basis, STLSQ(1e-3)) +res = solve(problem, basis, STLSQ()) +println(res) +println(result(res)) ``` ## Defining a Problem diff --git a/src/solution.jl b/src/solution.jl index 2d557e27f..0b287066e 100644 --- a/src/solution.jl +++ b/src/solution.jl @@ -189,7 +189,7 @@ function build_solution(prob::DataDrivenProblem, Ξ::AbstractMatrix, opt::Optimi retcode = size(Ξ, 2) == size(prob.DX, 1) ? :success : :incomplete pnew = !isempty(parameters(b)) ? [prob.p; ps] : ps X = get_target(prob) - Y = res_(prob.X, pnew, prob.t, prob.U) + Y = res_(get_oop_args(prob)...) # Build the metrics sparsity = norm(Ξ, 0) From 8dcb46558504c9519d9f076a5f75bc595cc465b8 Mon Sep 17 00:00:00 2001 From: JuliusMartensen Date: Mon, 8 Nov 2021 15:14:11 +0100 Subject: [PATCH 3/3] Fix parameter useage --- src/solution.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/solution.jl b/src/solution.jl index 0b287066e..df3846032 100644 --- a/src/solution.jl +++ b/src/solution.jl @@ -189,7 +189,8 @@ function build_solution(prob::DataDrivenProblem, Ξ::AbstractMatrix, opt::Optimi retcode = size(Ξ, 2) == size(prob.DX, 1) ? :success : :incomplete pnew = !isempty(parameters(b)) ? [prob.p; ps] : ps X = get_target(prob) - Y = res_(get_oop_args(prob)...) + x, _, t, c = get_oop_args(prob) + Y = res_(x, pnew, t, c) # Build the metrics sparsity = norm(Ξ, 0)