SciML / DataDrivenDiffEq.jl

Data driven modeling and automated discovery of dynamical systems for the SciML Scientific Machine Learning organization
https://docs.sciml.ai/DataDrivenDiffEq/stable/
MIT License
405 stars 57 forks source link

Basic usage example in the documentation failing #291

Closed hurak closed 2 years ago

hurak commented 2 years ago

The Basic usage example in dev Getting Started manual fails (on Julia 1.6.3):

julia> using DataDrivenDiffEq, ModelingToolkit

julia> # The function we are trying to find
       f(u) = u^2 + 4u + 4
f (generic function with 1 method)

julia> X = f.(1:100) # Generate data
100-element Vector{Int64}:
     9
    16
    25
     ⋮
 10000
 10201
 10404

julia> X = reshape(X, length(X), 1) # Reshape into a matrix
100×1 Matrix{Int64}:
     9
    16
    25
     ⋮
 10000
 10201
 10404

julia> # Create a problem from the data
       problem = DiscreteDataDrivenProblem(X)
Discrete DataDrivenProblem{Int64}

julia> # Choose a basis
       @variables u[1:1]
1-element Vector{Symbolics.Arr{Num, 1}}:
 u[1:1]

julia> using Symbolics: scalarize

julia> u = scalarize(u)
1-element Vector{Num}:
 u[1]

julia> basis = Basis(monomial_basis(u, 2), u)

Model ##Basis#257 with 3 equations
States (1):
  u[1]
Parameters (0):

julia> # Solve the problem, using the solver of your choosing
       res = solve(problem, basis, STLSQ())
ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:105
  zero(::Union{Type{P}, P}) where P<:Dates.Period at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Dates/src/periods.jl:53
  zero(::FillArrays.Fill{T, N, Axes} where Axes) where {T, N} at /home/hurak/.julia/packages/FillArrays/Vzxer/src/FillArrays.jl:540
  ...
Stacktrace:
 [1] zero(#unused#::Type{Any})
   @ Base ./missing.jl:106
 [2] _qreltype(#unused#::Type{Any})
   @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/qr.jl:333
 [3] qr(A::LinearAlgebra.Adjoint{Any, Vector{Any}}, arg::Val{true}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/qr.jl:415
 [4] qr(A::LinearAlgebra.Adjoint{Any, Vector{Any}}, arg::Val{true})
   @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/qr.jl:414
 [5] \(A::LinearAlgebra.Adjoint{Any, Vector{Any}}, B::LinearAlgebra.Adjoint{Int64, Matrix{Int64}})
   @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:1138
 [6] init(o::STLSQ{Float64}, A::LinearAlgebra.Adjoint{Any, Vector{Any}}, Y::LinearAlgebra.Adjoint{Int64, Matrix{Int64}})
   @ DataDrivenDiffEq.Optimize ~/.julia/packages/DataDrivenDiffEq/AGBrC/src/optimizers/Optimize.jl:63
 [7] solve(p::DataDrivenProblem{Int64, true, DataDrivenDiffEq.Discrete}, b::Basis, opt::STLSQ{Float64}; normalize::Bool, denoise::Bool, maxiter::Int64, round::Bool, eval_expression::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/AGBrC/src/solve/sindy.jl:46
 [8] solve(p::DataDrivenProblem{Int64, true, DataDrivenDiffEq.Discrete}, b::Basis, opt::STLSQ{Float64})
   @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/AGBrC/src/solve/sindy.jl:28
 [9] top-level scope
   @ REPL[10]:2