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

n_buffer has wrong dimensions #212

Closed
pascalschulthess opened this issue Mar 23, 2022 · 2 comments
Closed

n_buffer has wrong dimensions #212

pascalschulthess opened this issue Mar 23, 2022 · 2 comments

Comments

@pascalschulthess
Copy link

When I ran a fit of a ODE model with 2 equations and 3 parameters against data with 19 data points, I encountered the following error:

ERROR: LoadError: MethodError: no method matching mul!(::Vector{Float64}, ::LinearAlgebra.Transpose{Float64, Matrix{Float64}}, ::Matrix{Float64}, ::Bool, ::Bool)

This hinted at a dimension mismatch in the mul! method. After some debugging, I found that in levenberg_marquardt.jl , there’s line 80 creating a buffer:

n_buffer = Vector{T}(undef, n)

Checking size(n_buffer) = (3,)

Line 123, where my code fails with the aforementioned error, is:

mul!(n_buffer, transpose(J), value(df))

with size(transpose(J))=(3,19) and size(value(df)) = (19,1). Multiplying these should result in a size (3,1) and not (3,).
Thus, it’s also not possible to save the product to n_buffer.

I believe that this would be fixed by changing:

n_buffer = Matrix{T}(undef, n, 1)
@JakobAsslaender
Copy link
Contributor

Without a minimal working example it is hard to tell, but my guess is that your model function returns a 3x1 matrix instead of a vector. Can you check if that is the case? An easy fix would in that case be to change

function mymodel(t,p)
     ...
     return x
end

to

function mymodel(t,p)
     ...
     return vec(x)
end

@pkofod
Copy link
Member

pkofod commented Sep 3, 2022

Without a minimal working example it is hard to tell, but my guess is that your model function returns a 3x1 matrix instead of a vector. Can you check if that is the case? An easy fix would in that case be to change

I agree, it appears that you return a matrix, not a vector.

julia> size(rand(19))
(19,)

julia> size(rand(19,1))
(19, 1)

@pkofod pkofod closed this as completed Sep 3, 2022
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

3 participants