A bit of help with objects and arrays

Hi Everyone

I am yet another new Julia language user and I come from a C/Fortran background. So I am pretty weak with some of the object concepts and advanced array syntax. (I will figure it out). I am primarily interested in Julia to migrate more modern scientific computing platform for research purposes. It has been great but I have a long way to go.

I have a small project to perform differential parameter estimation and I am using this example that fits well.
Great Starting Example

I have my own version and I am getting daunting and lengthy error messages but they seem to be related to my modified ā€˜lossā€™ function:

function loss(p)
  sol = solve(prob, Tsit5(), p=p, saveat = tsteps)
  loss = 0.0
  for i in eachindex(tsteps)
      loss += (sol(tsteps[i],idxs=1)-1.0)^2
  end
  #loss = sum(abs2, sol.-1)
  return loss, sol
end

That change to the original example generates the same error message. The top portion of that error is listed here:

ERROR: LoadError: MethodError: no method matching size(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,NamedTuple{(:t, :u),Tuple{Nothing,Array{Array{Float64,1},1}}},Nothing,Nothing,Nothing,Nothing}})

I must be messing up in some way that I donā€™t understand. I am trying to rewrite the loss function in a way that allows me to customize its value but the above rewrite of the example loss function was my attempt to change it in a way that would give the same result.

Is there anything really obvious that is incorrect with my modified function?

1 Like

Hm, thatā€™s interesting. I can reproduce the issue, but itā€™s not at all obvious what youā€™ve done wrong. My first guess would be some issue or strange interaction with Zygote.jl, the tool that provides automatic differentiation of the loss function. If that is indeed the case, then you might want to post to the #autodiff channel on Slack if you canā€™t find any answers here.

1 Like

OK. I will wait for some more responses. But at least your response makes me feel like I am less of an ā€œold timerā€ trying to learn something new!

I guess I have to learn what ā€œslackā€ is!

Thanks

One additional update. Comparing the two loss function, they give very different values for ā€˜lossā€™.

OK. When I change the line to compute the loss function using the array interface:

      loss += (sol[1,i]-1.0)^2

There is no error and the solution of the optimization proceeds. It is not quite what I wanted, in general, but it works. I still donā€™t understand why the value for the ā€˜lossā€™ is a different value than the example. But, for now, this is solved.