Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in using input_nonlinearity with newpem #156

Closed
anchal-physics opened this issue Aug 16, 2024 · 2 comments
Closed

Errors in using input_nonlinearity with newpem #156

anchal-physics opened this issue Aug 16, 2024 · 2 comments

Comments

@anchal-physics
Copy link

Hi

I have simple SISO system which is slighlty non-linear and I wanted to see if I can fit a Hammerstein-Wiener form non-linear system to it using newpem method. Unfortunately, it is giving me intractable errors. I think the error originates in functions of other libraries but maybe you can shed some light on how to properly define input_nonlinearity function?

I can't show the data here but it is a failry simple SISO and following runs without errors:

newpem(id_data, 2)
Output (Click to expand): Iter Function value Gradient norm 0 1.303796e-01 1.252132e+01 * time: 9.584426879882812e-5 (sys = ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}} A = 0.952510834582067 -0.37171223660279223 0.0012212299487706242 0.9884628684643999 B = -0.03076361699634558 -0.0029576156945034823 C = 0.10795214583161879 -1.4966601166648088 D = 0.0

Sample Time: 0.001 (seconds)
Discrete-time state-space model, x0 = [0.11360903072925647, 0.009137177133436751], res = * Status: success

  • Candidate solution
    Final objective value: 9.228208e-02

  • Found with
    Algorithm: BFGS

  • Convergence measures
    |x - x'| = 1.56e-09 ≰ 0.0e+00
    |x - x'|/|x'| = 1.65e-10 ≰ 0.0e+00
    |f(x) - f(x')| = 0.00e+00 ≤ 1.0e-16
    |f(x) - f(x')|/|f(x')| = 0.00e+00 ≤ 0.0e+00
    |g(x)| = 5.81e-09 ≰ 1.0e-12

  • Work counters
    Seconds run: 0 (vs limit 100)
    Iterations: 45
    f(x) calls: 79
    ∇f(x) calls: 46
    , nlp = Float64[])

Then, if I try to give it a simple quadratic non-linearity, first I got this

function inp_nl(u::AbstractArray{T}, p::AbstractArray{U}) where {T,U}
    u .= u .+ p[1] .* u .^ 2
end
newpem(id_data, 2; input_nonlinearity=inp_nl, nlp=Float64[0.00001])

Output (Click to expand):

MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{... ┌ Error: Optimization failed, call `newpem(...; safe=true) to exit gracefully returning the initial estimate. └ @ ControlSystemIdentification /Users/gupta/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:267 { "name": "MethodError", "message": "MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var\"#predloss#43\"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var\"#42#46\", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12})

Closest candidates are:
(::Type{T})(::Real, !Matched::RoundingMode) where T<:AbstractFloat
@ Base rounding.jl:207
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
Float64(!Matched::IrrationalConstants.Logtwo)
@ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
...
",
"stack": "MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12})

Closest candidates are:
(::Type{T})(::Real, !Matched::RoundingMode) where T<:AbstractFloat
@ Base rounding.jl:207
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
Float64(!Matched::IrrationalConstants.Logtwo)
@ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
...

Stacktrace:
[1] convert(::Type{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12})
@ Base ./number.jl:7
[2] setindex!(A::Vector{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12}, i1::Int64)
@ Base ./array.jl:1021
[3] setindex!
@ ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/adjtrans.jl:330 [inlined]
[4] _setindex!
@ ./abstractarray.jl:1419 [inlined]
[5] setindex!
@ ./abstractarray.jl:1396 [inlined]
[6] macro expansion
@ ./broadcast.jl:1004 [inlined]
[7] macro expansion
@ ./simdloop.jl:77 [inlined]
[8] copyto!
@ ./broadcast.jl:1003 [inlined]
[9] copyto!
@ ./broadcast.jl:956 [inlined]
[10] materialize!
@ ./broadcast.jl:914 [inlined]
[11] materialize!
@ ./broadcast.jl:911 [inlined]
[12] inp_nl(u::LinearAlgebra.Transpose{Float64, Vector{Float64}}, p::Vector{ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12}})
@ Main ~/Git/ProjectTorreyPines/Controllers/Julia/density_control/jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_Y226sZmlsZQ==.jl:2
[13] (::ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64})(p::Vector{ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12}})
@ ControlSystemIdentification ~/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:219
[14] vector_mode_dual_eval!
@ ~/.julia/packages/ForwardDiff/PcZ48/src/apiutils.jl:24 [inlined]
[15] vector_mode_gradient!(result::DiffResults.MutableDiffResult{1, Float64, Tuple{Vector{Float64}}}, f::ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, x::Vector{Float64}, cfg::ForwardDiff.GradientConfig{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12}}})
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:96
[16] gradient!
@ ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:37 [inlined]
[17] gradient!
@ ~/.julia/packages/ForwardDiff/PcZ48/src/gradient.jl:35 [inlined]
[18] (::NLSolversBase.var"#14#18"{Float64, ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, ForwardDiff.GradientConfig{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64}, Float64}, Float64, 12}}}})(out::Vector{Float64}, x::Vector{Float64})
@ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/objective_types/oncedifferentiable.jl:70
[19] value_gradient!!(obj::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, x::Vector{Float64})
@ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/interface.jl:82
[20] initial_state(method::Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Nothing, Optim.Flat}, options::Optim.Options{Float64, Nothing}, d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, initial_x::Vector{Float64})
@ Optim ~/.julia/packages/Optim/ZhuZN/src/multivariate/solvers/first_order/bfgs.jl:94
[21] optimize
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/optimize.jl:36 [inlined]
[22] #optimize#91
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/interface.jl:143 [inlined]
[23] optimize
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/interface.jl:139 [inlined]
[24] newpem(d::ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, nx::Int64; zeroD::Bool, focus::Symbol, h::Int64, stable::Bool, output_nonlinearity::Nothing, input_nonlinearity::typeof(inp_nl), nlp::Vector{Float64}, sys0::ControlSystemIdentification.N4SIDStateSpace{StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}, LinearAlgebra.SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}, Float64}, metric::typeof(abs2), regularizer::ControlSystemIdentification.var"#42#46", optimizer::Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Nothing, Optim.Flat}, store_trace::Bool, show_trace::Bool, show_every::Int64, iterations::Int64, allow_f_increases::Bool, time_limit::Int64, x_tol::Int64, f_abstol::Float64, g_tol::Float64, f_calls_limit::Int64, g_calls_limit::Int64, safe::Bool)
@ ControlSystemIdentification ~/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:253
[25] top-level scope
@ ~/Git/ProjectTorreyPines/Controllers/Julia/density_control/jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_Y226sZmlsZQ==.jl:4"
}

I read in your documentation that optimizer = Optim.NelderMead() can give better results, so I tried it. It gives another kind of error which is weird. Somewhere inside when lsim is called, state vector is reduced in length by 1.

newpem(id_data, 2; input_nonlinearity=inp_nl, nlp=Float64[0.00001], optimizer = Optim.NelderMead())

Output (Click to expand):

x0 must have length 2: got length 1 ┌ Error: Optimization failed, call `newpem(...; safe=true) to exit gracefully returning the initial estimate. └ @ ControlSystemIdentification /Users/gupta/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:267

{
"name": "ErrorException",
"message": "x0 must have length 2: got length 1",
"stack": "x0 must have length 2: got length 1

Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] lsim(sys::StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, u::Matrix{Float64}, t::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}; x0::Vector{Float64}, method::Symbol)
@ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/kvrre/src/timeresp.jl:182
[3] lsim
@ ~/.julia/packages/ControlSystemsBase/kvrre/src/timeresp.jl:176 [inlined]
[4] #lsim#238
@ ~/.julia/packages/ControlSystemsBase/kvrre/src/timeresp.jl:235 [inlined]
[5] lsim
@ ~/.julia/packages/ControlSystemsBase/kvrre/src/timeresp.jl:223 [inlined]
[6] lsim(sys::StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, d::ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}; x0::Vector{Float64})
@ ControlSystemIdentification ~/.julia/packages/ControlSystemIdentification/La3Ei/src/ControlSystemIdentification.jl:238
[7] (::ControlSystemIdentification.var"#predloss#43"{Bool, Int64, Nothing, typeof(inp_nl), ControlSystemIdentification.PredictionStateSpace{ControlSystemsBase.Discrete{Float64}, StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, Matrix{Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Nothing}, typeof(abs2), ControlSystemIdentification.var"#42#46", ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, Int64, Matrix{Float64}, ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, Matrix{Float64}, Float64}, Bool, Matrix{Float64}, Int64, Int64, Int64})(p::Vector{Float64})
@ ControlSystemIdentification ~/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:223
[8] value!!(obj::NLSolversBase.NonDifferentiable{Float64, Vector{Float64}}, x::Vector{Float64})
@ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/interface.jl:9
[9] initial_state(method::Optim.NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}, options::Optim.Options{Float64, Nothing}, d::NLSolversBase.NonDifferentiable{Float64, Vector{Float64}}, initial_x::Vector{Float64})
@ Optim ~/.julia/packages/Optim/ZhuZN/src/multivariate/solvers/zeroth_order/nelder_mead.jl:171
[10] optimize
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/optimize.jl:36 [inlined]
[11] #optimize#91
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/interface.jl:143 [inlined]
[12] optimize
@ ~/.julia/packages/Optim/ZhuZN/src/multivariate/optimize/interface.jl:139 [inlined]
[13] newpem(d::ControlSystemIdentification.InputOutputData{LinearAlgebra.Transpose{Float64, Vector{Float64}}, LinearAlgebra.Transpose{Float64, Vector{Float64}}, Float64}, nx::Int64; zeroD::Bool, focus::Symbol, h::Int64, stable::Bool, output_nonlinearity::Nothing, input_nonlinearity::typeof(inp_nl), nlp::Vector{Float64}, sys0::ControlSystemIdentification.N4SIDStateSpace{StateSpace{ControlSystemsBase.Discrete{Float64}, Float64}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, LinearAlgebra.Hermitian{Float64, Matrix{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}, Vector{Float64}, LinearAlgebra.SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}, Float64}, metric::typeof(abs2), regularizer::ControlSystemIdentification.var"#42#46", optimizer::Optim.NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}, store_trace::Bool, show_trace::Bool, show_every::Int64, iterations::Int64, allow_f_increases::Bool, time_limit::Int64, x_tol::Int64, f_abstol::Float64, g_tol::Float64, f_calls_limit::Int64, g_calls_limit::Int64, safe::Bool)
@ ControlSystemIdentification ~/.julia/packages/ControlSystemIdentification/La3Ei/src/pem.jl:253
[14] top-level scope
@ ~/Git/ProjectTorreyPines/Controllers/Julia/density_control/jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_Y245sZmlsZQ==.jl:1"
}

Please let me know if you know why this is happening?

@baggepinnen
Copy link
Owner

baggepinnen commented Aug 16, 2024

Hello 👋

The first error looks like u have been of type Float64 and p of type Dual, causing an error while writing into u. That's an issue I need to fix in the package.

This PR should fix this issue

The second issue is harder for me to figure out without being able to reproduce the error.

@baggepinnen
Copy link
Owner

I think I found the second issue as well, #157 should solve that too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants