From dccfd0cf3dfd8570c9fec95f95b0bf8f8d1d3808 Mon Sep 17 00:00:00 2001 From: Michael Creel Date: Fri, 5 Jan 2024 12:23:18 +0100 Subject: [PATCH] cleanup DSGE with SNM example --- Examples/DSGE/SimulatedNeuralMoments/Estimate.jl | 12 ++++++------ Examples/DSGE/SimulatedNeuralMoments/Project.toml | 14 -------------- Manifest.toml | 2 +- Project.toml | 1 + 4 files changed, 8 insertions(+), 21 deletions(-) delete mode 100644 Examples/DSGE/SimulatedNeuralMoments/Project.toml diff --git a/Examples/DSGE/SimulatedNeuralMoments/Estimate.jl b/Examples/DSGE/SimulatedNeuralMoments/Estimate.jl index ac3ac5b..69c4d60 100644 --- a/Examples/DSGE/SimulatedNeuralMoments/Estimate.jl +++ b/Examples/DSGE/SimulatedNeuralMoments/Estimate.jl @@ -2,7 +2,7 @@ This is written to be used interactively, with VScode, to explain the methods, step by step. For good performance, it is better to wrap -everything into a function. See the example in the JD directory of +everything into a function. See the example in the DSGE directory of https://github.com/mcreel/SNM for how to do that. Start julia as "julia --proj -t auto" to use threads @@ -10,8 +10,8 @@ Start julia as "julia --proj -t auto" to use threads =# using Pkg cd(@__DIR__) -Pkg.activate(".") -using SimulatedNeuralMoments, Flux, SolveDSGE, MCMCChains +#Pkg.activate(".") +using Econometrics, SimulatedNeuralMoments, Flux, SolveDSGE, MCMCChains using Distributions, StatsPlots, DelimitedFiles, PrettyTables using BSON:@save using BSON:@load @@ -87,7 +87,7 @@ lnL = θ -> snmobj(θ, θnn, S, model, nnmodel, nninfo) ## run a short chain to improve proposal # tuning the chain and creating a good proposal may # need care - this is just an example! -chain = mcmc(θnn, tuninglength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) +chain = SimulatedNeuralMoments.mcmc(θnn, tuninglength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) acceptance = mean(chain[:,end]) start = 0. @@ -98,13 +98,13 @@ while acceptance < 0.2 || acceptance > 0.3 acceptance > 0.3 ? tuning *= 1.5 : nothing proposal(θ) = rand(MvNormal(θ, tuning*Σp)) start = mean(chain[:,1:end-2], dims=1)[:] - chain = mcmc(start, tuninglength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) + chain = SimulatedNeuralMoments.mcmc(start, tuninglength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) acceptance = mean(chain[:,end]) end ## final long chain start = mean(chain[:,1:end-2], dims=1)[:] -chain = mcmc(start, finallength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) +chain = SimulatedNeuralMoments.mcmc(start, finallength, lnL, model, nnmodel, nninfo, proposal, burnin, verbosity) ## visualize results chn = Chains(chain[:,1:end-2], ["β", "γ", "ρ₁", "σ₁", "ρ₂", "σ₂", "nss"]) diff --git a/Examples/DSGE/SimulatedNeuralMoments/Project.toml b/Examples/DSGE/SimulatedNeuralMoments/Project.toml deleted file mode 100644 index 796726f..0000000 --- a/Examples/DSGE/SimulatedNeuralMoments/Project.toml +++ /dev/null @@ -1,14 +0,0 @@ -[deps] -BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" -DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" -Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" -Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" -MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d" -MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" -OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03" -Optim = "429524aa-4258-5aef-a3af-852621145aeb" -PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" -SimulatedNeuralMoments = "43b7c8c0-5622-45b8-90a3-338fc50d2232" -SolveDSGE = "00bf1f32-23ad-54cc-bf6e-3216db8a43a2" -StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" diff --git a/Manifest.toml b/Manifest.toml index 99ad43d..4bb226b 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.0" manifest_format = "2.0" -project_hash = "3ab1017fb3045fd22a82c1f9b060b3dad9f601ec" +project_hash = "150b3fc4e28bf6bf93002dcaa0fe70333e69579e" [[deps.ADTypes]] git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245" diff --git a/Project.toml b/Project.toml index 058d0a2..29dbace 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "1.0.0" [deps] AdvancedMH = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"