1
votes

I'm new with Julia trying to run the example proposed at https://diffeqflux.sciml.ai/stable/examples/normalizing_flows/ to define and train a continuous normalizing flow using sciml_train.

I just copy/pasted the written code and gets the following error:

ERROR: MethodError: no method matching (::var"#5#7")(::Array{Float32,1}, ::Float32)

Does someone know why I get this error? Here is the code:

nn = Chain(Dense(1, 3, tanh), Dense(3, 1, tanh))
tspan = (0.0f0,10.0f0)
ffjord_test = FFJORD(nn,tspan, Tsit5())
data_train = Float32.(rand(Normal(6.0,0.7), 1, 100))

function loss_adjoint(θ)
    logpx = ffjord_test(data_train,θ)[1]
    loss = -mean(logpx)
end

res1 = DiffEqFlux.sciml_train(loss_adjoint, ffjord_test.p, ADAM(0.1), cb = cb, maxiters = 100)

res2 = DiffEqFlux.sciml_train(loss_adjoint, res1.minimizer, LBFGS(), allow_f_increases = false)

Thank you

2

2 Answers

1
votes

Given, the error message seems a little bit cryptic, due to issuing "#5#7" instead of a proper function name for the method which is seemingly not callable for the two input arguments of types ::Array{Float32,1}, ::Float32.

This is presumably due to some not properly defined variable/symbol, which is assumed by a caller to be callable like a function. The caller probably seems to be stemming from within the code you are using.

The thing which seems like the most probable source of this error seems to me to be the cb in res1 = DiffEqFlux.sciml_train(loss_adjoint, ffjord_test.p, ADAM(0.1), cb = cb, maxiters = 100) . It is meant to be shorthand for "callback" and assumed to be a function defined by the user, and is called from within sciml_train. Comparing with the linked document where you took the example from, I can verify that your snippet matches the code over there. I haven't tested it out myself by now, but could you check that the error is gone as soon as you either define a cb function or remove it from the function call? If that'd be the case, there'd be an error within the official documentation.

0
votes

You have to note the callback function as

cb = function(p,l)
println("parameters p = $p \n loss l = $l")
return false
end

See also this issue #433: Plug - Post on Neural ODEs