Hi, I have been trying for a long time to get Flux working for a basic time series.
I think if I can get a really simple example working, I would be able to go from there, but when I try to do the ‘obvious’ thing, it falls over.
In the example below x is a matrix of (34) lagged returns by 7300 rows and y is a vector of 7300 to be forecast via MSE.
Can anyone please help or direct me to any useful relevant documentation?
After loading Flux and the data, here is what I tried:
julia> N=length(x[1,:]) # 34
34
julia> m = Chain(
LSTM(N, 10),
Dense(10, 1))
Chain(Recur(LSTMCell(34, 10)), Dense(10, 1))
julia> function loss(xs, ys)
println(size(xs))
println(size(ys))
l = sum((m(xs)-ys).^2)
return l
end
loss (generic function with 1 method)
julia> opt = ADAM(0.01)
ADAM(0.01, (0.9, 0.999), IdDict{Any,Any}())
julia> evalcb = () → @show loss(x, y)
#18 (generic function with 1 method)
julia> loss(x’,y’)
(34, 7354)
(1, 7354)
167.1342563133403
julia> Flux.train!(loss, params(m), (x’, y’), opt)
ERROR: MethodError: no method matching loss(::Adjoint{Float64,Array{Float64,2}})
Closest candidates are:
loss(::Any, ::Any) at none:2
Stacktrace:
[1] macro expansion at /Users/davide/.julia/packages/Zygote/ApBXe/src/compiler/interface2.jl:0 [inlined]
[2] _pullback(::Zygote.Context, ::typeof(loss), ::Adjoint{Float64,Array{Float64,2}}) at /Users/davide/.julia/packages/Zygote/ApBXe/src/compiler/interface2.jl:7
[3] #14 at /Users/davide/.julia/packages/Flux/CjjeX/src/optimise/train.jl:84 [inlined]
[4] _pullback(::Zygote.Context, ::getfield(Flux.Optimise, Symbol(“##14#22”)){typeof(loss),Adjoint{Float64,Array{Float64,2}}}) at /Users/davide/.julia/packages/Zygote/ApBXe/src/compiler/interface2.jl:0
[5] pullback(::Function, ::Zygote.Params) at /Users/davide/.julia/packages/Zygote/ApBXe/src/compiler/interface.jl:103
[6] gradient(::Function, ::Zygote.Params) at /Users/davide/.julia/packages/Zygote/ApBXe/src/compiler/interface.jl:44
[7] macro expansion at /Users/davide/.julia/packages/Flux/CjjeX/src/optimise/train.jl:83 [inlined]
[8] #train!#12(::getfield(Flux.Optimise, Symbol(“##18#26”)), ::typeof(Flux.Optimise.train!), ::typeof(loss), ::Zygote.Params, ::Tuple{Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}}}, ::ADAM) at /Users/davide/.julia/packages/Flux/CjjeX/src/optimise/train.jl:80
[9] train!(::Function, ::Zygote.Params, ::Tuple{Adjoint{Float64,Array{Float64,2}},Adjoint{Float64,Array{Float64,2}}}, ::ADAM) at /Users/davide/.julia/packages/Flux/CjjeX/src/optimise/train.jl:78
[10] top-level scope at none:0
It doesn’t seem to like evaluating ‘loss’ during training, even though ‘loss’ worked when I just tried evaluating it on the same data outside training. ???
Can anyone help please [apologies for my ignorance… I can’t seem to find any proper documentation (other than a few terse examples) anywhere!]