Skip to content

False to pass parameters #529

Description

@ZeyuanLee

When tring to pass the parameters and realize a regression,

using DataDrivenDiffEq
using ModelingToolkit
using LinearAlgebra
using DataDrivenSparse

f(u) = cos.(u) .+ 4sin.(3 .* u .^2)

X = randn(1, 200)
Y = reduce(hcat, map(f, eachcol(X)))

problem = DirectDataDrivenProblem(X, Y, name = :Test)

@variables u
@parameters w[1:4]
w = collect(w)
h = Num[cos.(w[1] .* [u]); sin.(w[2] .* [u]);  cos.(w[3] .*[u].^2); sin.(w[4] .*[u].^2);]
basis = Basis(h, [u],parameters = w)

res = solve(problem, basis, STLSQ())
println(res) # hide

Error

julia> res = solve(problem, basis, STLSQ())
ERROR: UndefVarError: `w` not defined in `Symbolics`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/SymbolicUtils/sQye2/src/code.jl:490 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Symbolics/8VseH/src/build_function.jl:346 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:163 [inlined]
  [4] macro expansion
    @ ./none:0 [inlined]
  [5] generated_callfunc
    @ ./none:0 [inlined]
  [6] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{…})(::SubArray{…}, ::SubArray{…}, ::SubArray{…}, ::SubArray{…}, ::Matrix{…})
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:150
  [7] _apply_function(f::DataDrivenDiffEq.DataDrivenFunction{…}, du::SubArray{…}, u::SubArray{…}, p::SubArray{…}, t::SubArray{…}, c::Matrix{…})
    @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/efgcJ/src/basis/build_function.jl:33
  [8] (::DataDrivenDiffEq.var"#1#2"{})(i::Int64)
    @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/efgcJ/src/basis/build_function.jl:150
  [9] iterate
    @ ./generator.jl:48 [inlined]
 [10] _collect(c::Base.OneTo{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base ./array.jl:811
 [11] collect_similar
    @ ./array.jl:720 [inlined]
 [12] map
    @ ./abstractarray.jl:3371 [inlined]
 [13] _apply_vec_function(f::DataDrivenDiffEq.DataDrivenFunction{…}, du::Matrix{…}, u::Matrix{…}, p::Vector{…}, t::Vector{…}, c::Matrix{…})
    @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/efgcJ/src/basis/build_function.jl:148
 [14] (::Basis{false, false})(p::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Direct})
    @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/efgcJ/src/problem/type.jl:338
 [15] DataDrivenSolution(b::Basis{…}, p::DataDrivenProblem{…}, alg::STLSQ{…}, result::Vector{…}, internal_problem::DataDrivenDiffEq.InternalDataDrivenProblem{…}, retcode::DDReturnCode)
    @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/efgcJ/src/solution.jl:37
 [16] solve!(ps::DataDrivenDiffEq.InternalDataDrivenProblem{…})
    @ DataDrivenSparse ~/.julia/packages/DataDrivenSparse/0c4Fb/src/commonsolve.jl:21
 [17] solve(::DataDrivenProblem{Float64, false, DataDrivenDiffEq.Direct}, ::Vararg{Any}; kwargs::@Kwargs{})
    @ CommonSolve ~/.julia/packages/CommonSolve/JfpfI/src/CommonSolve.jl:23
 [18] top-level scope
    @ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
(@v1.11) pkg> st
Status `~/.julia/environments/v1.11/Project.toml`
  [093aae92] BSplineKit v0.18.2
  [2445eb08] DataDrivenDiffEq v1.6.0
  [5b588203] DataDrivenSparse v0.1.2
  [0c46a032] DifferentialEquations v7.16.0
  [31c24e10] Distributions v0.25.117
  [f6369f11] ForwardDiff v0.10.38
  [dcce2d33] GeometricIntegrators v0.14.4
  [18cb22b4] GeometricProblems v0.6.7
  [add582a8] MLJ v0.20.7
  [961ee093] ModelingToolkit v9.65.0
  [c030b06c] ODE v2.15.0
  [1dea7af3] OrdinaryDiffEq v6.92.0
  [91a5bcdd] Plots v1.40.9
  [9a34ec7f] SparseIdentification v0.1.0 `~/SparseIdentification.jl`
  [860ef19b] StableRNGs v1.0.2
  [8254be44] SymbolicRegression v1.9.0
  [d1185830] SymbolicUtils v3.16.0
  [0c5d862f] Symbolics v6.29.2
  [37e2e46d] LinearAlgebra v1.11.0
  [9a3f8284] Random v1.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions