-
-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Description
With v0.6.14
julia> using Flux
julia> NN = NeuralNetworkApproximator(; model = Dense(2, 3), optimizer = Descent())
q_values = NN(rand(2))
NeuralNetworkApproximator{Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}, Descent}(Dense(2, 3), Descent(0.1))
julia> q_values = NN(rand(2))
3-element Vector{Float64}:
-0.15430465457121337
0.541149992714865
-0.4218130908450073
julia> gs = gradient(params(NN)) do
sum(NN(rand(2, 5)))
end
Grads(...)
julia> gs.
grads params
julia> gs.grads
IdDict{Any, Any} with 2 entries:
Float32[-0.281172 -0.247735; 0.566611 1.06104; -0.810727 -0.657922] => [2.89303 2.38353; 2.89303 2.38353; 2.89303 2.38353]
Float32[0.0, 0.0, 0.0] => [5.0, 5.0, 5.0]With the newest v0.6.16:
julia> using Flux
julia> NN = NeuralNetworkApproximator(; model = Dense(2, 3), optimizer = Descent())
NeuralNetworkApproximator{Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}, Descent}(Dense(2, 3), Descent(0.1))
julia> q_values = NN(rand(2))
3-element Vector{Float64}:
-0.27442976982279155
0.046217641920877364
-0.16964400716726158
julia> gs = gradient(params(NN)) do
sum(NN(rand(2, 5)))
end
Grads(...)
julia> gs.grads
IdDict{Any, Any} with 2 entries:
Float32[-0.629986 -0.928219; 0.000942579 0.324789; -0.164906 -0.933509] => [3.37767 2.48145; 3.37767 2.48145; 3.37767 2.48145]
Float32[0.0, 0.0, 0.0] => Fill(5.0, 3)Note the second grads returned a FilledArray instead of a vector.
JuliaReinforcementLearning/ReinforcementLearning.jl#370
cc @pilgrimygy
Metadata
Metadata
Assignees
Labels
No labels