Skip to content

Commit

Permalink
cleanup DSGE with SNM example
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Creel committed Jan 5, 2024
1 parent 86c4602 commit dccfd0c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
12 changes: 6 additions & 6 deletions Examples/DSGE/SimulatedNeuralMoments/Estimate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
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
=#
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
Expand Down Expand Up @@ -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.

Expand All @@ -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"])
Expand Down
14 changes: 0 additions & 14 deletions Examples/DSGE/SimulatedNeuralMoments/Project.toml

This file was deleted.

2 changes: 1 addition & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dccfd0c

Please sign in to comment.