From 593905c96e5868ee5cbe1525830af64c47ba6396 Mon Sep 17 00:00:00 2001 From: thorek1 Date: Tue, 29 Oct 2024 10:26:18 +0100 Subject: [PATCH] float32 training and matmul --- test/neural_net_solution.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/neural_net_solution.jl b/test/neural_net_solution.jl index 13f729f5..6cb24f10 100644 --- a/test/neural_net_solution.jl +++ b/test/neural_net_solution.jl @@ -9,7 +9,7 @@ n_shocks = length(get_shocks(Smets_Wouters_2007)) n_vars = length(get_variables(Smets_Wouters_2007)) -n_hidden = 128 +n_hidden = 64 neural_net = Chain( Dense(n_vars + n_shocks, n_hidden, asinh), Dense(n_hidden, n_hidden, asinh), @@ -17,6 +17,8 @@ neural_net = Chain( Dense(n_vars + n_shocks, n_hidden, asinh), Dense(n_hidden, n_hidden, celu), Dense(n_hidden, n_hidden, celu), Dense(n_hidden, n_hidden, celu), + Dense(n_hidden, n_hidden, celu), + Dense(n_hidden, n_hidden, celu), Dense(n_hidden, n_vars)) # neural_net = Chain( Dense(n_vars + n_shocks, n_hidden, celu), @@ -36,9 +38,9 @@ neural_net = Chain( Dense(n_vars + n_shocks, n_hidden, asinh), sims = get_irf(Smets_Wouters_2007, shocks = shcks, periods = 0, levels = true) - sim_slices = vcat(collect(sims[:,n_burnin:n_burnin + n_simul - 1, 1]), shcks[:,n_burnin + 1:n_burnin + n_simul]) + sim_slices = Float32.(vcat(collect(sims[:,n_burnin:n_burnin + n_simul - 1, 1]), shcks[:,n_burnin + 1:n_burnin + n_simul])) - out_slices = collect(sims[:,n_burnin + 1:n_burnin + n_simul,1]) + out_slices = Float32.(collect(sims[:,n_burnin + 1:n_burnin + n_simul,1])) loss() = sqrt(sum(abs2, out_slices - neural_net(sim_slices))) @@ -46,13 +48,13 @@ neural_net = Chain( Dense(n_vars + n_shocks, n_hidden, asinh), pars = Flux.params(neural_net) lossfun, gradfun, fg!, p0 = optfuns(loss, pars) - res = Optim.optimize(Optim.only_fg!(fg!), p0, Optim.Options(iterations=1000, show_trace=true)) + res = Optim.optimize(Optim.only_fg!(fg!), p0, Optim.Options(iterations=10000, show_trace=true)) # end out_slices[:,1] - neural_net(sim_slices[:,1]) -minimum(neural_net(sim_slices[:,1])) -minimum(out_slices[:,1]) +maximum(neural_net(sim_slices[:,1])) +maximum(out_slices[:,1]) norm(out_slices[:,1] - neural_net(sim_slices[:,1])) / norm(out_slices[:,1]) \ No newline at end of file