Closed mkalia94 closed 4 years ago
I have a scrappy solution, which is to replace the loss by:
function loss_adjoint(θ)
p = predict_adjoint(θ)
l = 0
for i=1:length(p[1,:])
l = l + sum(abs2,ann(p[:,i],θ[2:end]))
end
l = l+ sum(abs2,predict_adjoint(θ)[2,:].-1)
return l
end
Is there a better way to do this?
This is a duplicate of https://github.com/JuliaDiffEq/DiffEqFlux.jl/issues/192 . Essentially, FastChain
can act on a Vector but it doesn't work so well on a Matrix, even though neural networks generally "can" work on a matrix. This definition of the backpass https://github.com/JuliaDiffEq/DiffEqFlux.jl/blob/master/src/fast_layers.jl#L43-L54 hasn't been matrix-proofed, but if someone has like 30 minutes to dig through it then it shouldn't be too difficult: I believe it just needs a sum(?,dims=2)
on one of the pullback terms.
Thanks, also the quick fix above doesn't work if ann
maps to a higher dimension. Say
ann = FastChain(FastDense(2,16,tanh), FastDense(16,16,tanh), FastDense(16,2))
Then looping in the new loss with initialization l = [0;0]
results in a 'mutating arrays not supported error'. Is there a way around it?
The above issue can be fixed with
sum(abs2,hcat([ann(p[:,i],θ[2:end]) for i in 1:length(p[1,:])]...))
I don't have much experience with Julia so I won't be able to resolve the Fast Chain action on a Matrix, but this is a quick fix for now.
Hi,
I was following the "Universal Differential Equations for Neural Optimal Control" example and wanted to include the neural network
ann
as an extra term in loss as follows:However, this results in the following error:
which I do not understand..any help would be really appreciated! Thanks for the great package :)
The packages currently in my module are: