SciML / DiffEqFlux.jl

Pre-built implicit layer architectures with O(1) backprop, GPUs, and stiff+non-stiff DE solvers, demonstrating scientific machine learning (SciML) and physics-informed machine learning methods
https://docs.sciml.ai/DiffEqFlux/stable
MIT License
874 stars 157 forks source link

`Using Flux Chain neural networks with Flux.train!` not working #472

Closed Antomek closed 3 years ago

Antomek commented 3 years ago

The example code given in Using Flux Chain neural networks with Flux.train! is not working. The parameter vector p is not defined. The error:

LoadError: UndefVarError: p not defined
Stacktrace:
 [1] predict_n_ode() at ./Untitled-1:22
 [2] loss_n_ode() at ./Untitled-1:26

The fix must be an easy one but because I am trying to get the hang of DiffEqFlux I'm not spotting it! Thanks for the help.

Antomek commented 3 years ago
dudt2 = Chain(x -> x.^3,
             Dense(2,50,tanh),
             Dense(50,2))
p,re = Flux.destructure(dudt2)
dudt(u,p,t) = re(p)(u)
prob = ODEProblem(dudt,u0,tspan)

solves it.

ChrisRackauckas commented 3 years ago

That looks like a copy paste from https://diffeqflux.sciml.ai/dev/examples/neural_ode_flux/ ? Is there anything in the tutorial that needs a fix?