Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Creel committed Mar 20, 2024
1 parent f706849 commit 9859d34
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
43 changes: 26 additions & 17 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ version = "0.1.2"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "c53fc348ca4d40d7b371e71fd52251839080cbc9"
git-tree-sha1 = "260fd2400ed2dab602a7c15cf10c1933c59930a2"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.5.4"
version = "1.5.5"
weakdeps = ["IntervalSets", "StaticArrays"]

[deps.ConstructionBase.extensions]
Expand Down Expand Up @@ -724,9 +724,9 @@ version = "0.8.4"

[[deps.Flux]]
deps = ["Adapt", "ChainRulesCore", "Compat", "Functors", "LinearAlgebra", "MLUtils", "MacroTools", "NNlib", "OneHotArrays", "Optimisers", "Preferences", "ProgressLogging", "Random", "Reexport", "SparseArrays", "SpecialFunctions", "Statistics", "Zygote"]
git-tree-sha1 = "5a626d6ef24ae0a8590c22dc12096fb65eb66325"
git-tree-sha1 = "502d0232ec6430d40b6e5b57637333f32192592e"
uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c"
version = "0.14.13"
version = "0.14.14"

[deps.Flux.extensions]
FluxAMDGPUExt = "AMDGPU"
Expand Down Expand Up @@ -973,9 +973,13 @@ weakdeps = ["Random", "RecipesBase", "Statistics"]

[[deps.InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "68772f49f54b479fa88ace904f6127f0a3bb2e46"
git-tree-sha1 = "896385798a8d49a255c398bd49162062e4a4c435"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.12"
version = "0.1.13"
weakdeps = ["Dates"]

[deps.InverseFunctions.extensions]
DatesExt = "Dates"

[[deps.InvertedIndices]]
git-tree-sha1 = "0dc7b50b8d436461be01300fd8cd45aa0274b038"
Expand Down Expand Up @@ -1071,9 +1075,9 @@ version = "3.0.0+1"

[[deps.LLVM]]
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Preferences", "Printf", "Requires", "Unicode"]
git-tree-sha1 = "ddab4d40513bce53c8e3157825e245224f74fae7"
git-tree-sha1 = "7c6650580b4c3169d9905858160db895bff6d2e2"
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
version = "6.6.0"
version = "6.6.1"

[deps.LLVM.extensions]
BFloat16sExt = "BFloat16s"
Expand Down Expand Up @@ -1868,9 +1872,9 @@ version = "0.4.0+0"

[[deps.Roots]]
deps = ["Accessors", "ChainRulesCore", "CommonSolve", "Printf"]
git-tree-sha1 = "b7e530ab28c9e19bf1742de77badbd3c943541e5"
git-tree-sha1 = "1ab580704784260ee5f45bffac810b152922747b"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "2.1.3"
version = "2.1.5"

[deps.Roots.extensions]
RootsForwardDiffExt = "ForwardDiff"
Expand All @@ -1895,10 +1899,10 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.SciMLBase]]
deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"]
git-tree-sha1 = "3a281a9fce9cd62b849d7f16e412933a5fe755cb"
deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "SciMLStructures", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"]
git-tree-sha1 = "dce2d07e3519cb7817f2d89a7978c13fef30be87"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
version = "2.29.0"
version = "2.30.0"

[deps.SciMLBase.extensions]
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
Expand All @@ -1925,6 +1929,11 @@ git-tree-sha1 = "10499f619ef6e890f3f4a38914481cc868689cd5"
uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
version = "0.3.8"

[[deps.SciMLStructures]]
git-tree-sha1 = "5833c10ce83d690c124beedfe5f621b50b02ba4d"
uuid = "53ae85a6-f571-4167-b2af-e1d143709226"
version = "1.1.0"

[[deps.ScientificTypesBase]]
git-tree-sha1 = "a8e18eb383b5ecf1b5e6fc237eb39255044fd92b"
uuid = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
Expand Down Expand Up @@ -2217,9 +2226,9 @@ weakdeps = ["PDMats"]
TrackerPDMatsExt = "PDMats"

[[deps.TranscodingStreams]]
git-tree-sha1 = "3caa21522e7efac1ba21834a03734c57b4611c7e"
git-tree-sha1 = "a09c933bebed12501890d8e92946bbab6a1690f1"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.4"
version = "0.10.5"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
Expand Down Expand Up @@ -2247,9 +2256,9 @@ version = "0.4.80"

[[deps.Turing]]
deps = ["ADTypes", "AbstractMCMC", "AdvancedHMC", "AdvancedMH", "AdvancedPS", "AdvancedVI", "BangBang", "Bijectors", "DataStructures", "Distributions", "DistributionsAD", "DocStringExtensions", "DynamicPPL", "EllipticalSliceSampling", "ForwardDiff", "Libtask", "LinearAlgebra", "LogDensityProblems", "LogDensityProblemsAD", "MCMCChains", "NamedArrays", "Printf", "Random", "Reexport", "Requires", "SciMLBase", "Setfield", "SpecialFunctions", "Statistics", "StatsAPI", "StatsBase", "StatsFuns"]
git-tree-sha1 = "afb5bb484e67bb4179507baff464da9c4d18b307"
git-tree-sha1 = "0e61d150c55162770c9dd904aa24a271921689e7"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.30.5"
version = "0.30.7"

[deps.Turing.extensions]
TuringDynamicHMCExt = "DynamicHMC"
Expand Down
6 changes: 3 additions & 3 deletions PracticalSummaries/18-SimulationBased.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ println(@yellow "(Remember that the true parameters are $θ₀)")
# This works even without controlling chatter
using Turing, AdvancedMH, Term, Econometrics
k_data = k(x,y) # stats from the real data
# Define the prior and asymptotic Gaussian likelihood of the moments
# Define the prior and approximate Gaussian likelihood of the moments
@model function MSM(k_data, S, x)
θ ~ arraydist([Normal() for _=1:2]) # the prior (note: it's biased)
# sample from the model, at the trial parameter value, and compute statistics
ks = simulated_moments(θ, x, S, false) # NOTE: no control of chatter
kbar = mean(ks) # mean of simulated statistics, over S replications
Σ = cov(ks) # estimated covariance of statistics
Σ = cov(ks) # estimated covariance of statistic
k_data ~ MvNormal(kbar, Σ) # this corresponds to CUE GMM, but adding the determinant from the MVN
end

## do MCMC sampling
# look at acceptance rate, below, and adjust
# the tuning to make acceptance around 0.25
S = 100 # make this as large as possible, given computation time, when doing real research
S = 500 # make this as large as possible, given computation time, when doing real research
tuning = 0.05
length = 10000
burnin = 1000
Expand Down
43 changes: 38 additions & 5 deletions econometrics.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -49964,7 +49964,7 @@ To compute the posterior mean,
\begin{align*}
E(\theta|y) & =\int_{\Theta}\theta f(\theta|y)d\theta\\
& =\int_{\Theta}\theta\frac{f(y|\theta)\pi(\theta)}{f(y)}d\theta\\
= & \frac{1}{f(y)}\int{}_{\Theta}\theta f(y|\theta)\pi(\theta)d\theta
= & \frac{1}{f(y)}{\color{blue}\int{}_{\Theta}\theta f(y|\theta)\pi(\theta)d\theta}
\end{align*}

\end_inset
Expand All @@ -49976,7 +49976,7 @@ where the marginal density of the data
is obtained from
\begin_inset Formula
\[
f(y)=\int_{\Theta}f(y,\theta)d\theta
f(y)={\color{blue}\int_{\Theta}f(y,\theta)d\theta}
\]

\end_inset
Expand All @@ -49985,7 +49985,7 @@ f(y)=\int_{\Theta}f(y,\theta)d\theta
\end_layout

\begin_layout Itemize
Note that both of the integrals are multiple integrals,
Note that both of the integrals in blue are multiple integrals,
with the dimension given by that of the parameter,

\begin_inset Formula $\theta.$
Expand All @@ -50004,7 +50004,8 @@ conjugate priors),
the integrals may have analytic solutions:
e.g.,
Gaussian likelihood with a Gaussian prior leads to a Gaussian posterior.

In principle,
one shouldn't be adjusting priors for simple computational convenience....
\end_layout

\begin_layout Itemize
Expand Down Expand Up @@ -50550,7 +50551,11 @@ Once the chain is considered to have stabilized,
\end_layout

\begin_layout Itemize
the art of applying these methods consists of providing a good proposal density so that the acceptance rate is reasonably high,
the art of applying these methods consists of providing a
\color blue
good proposal density
\color inherit
so that the acceptance rate is reasonably high,
but not too high.

\color blue
Expand Down Expand Up @@ -51250,6 +51255,34 @@ Here is a summary of the chain,
\end_inset


\end_layout

\begin_layout Section
Practical summary
\end_layout

\begin_layout Standard
I am not providing additional code,
I recommend just working through the examples in the chapter.
There are a lot of other resources available,
with code.
For examples using Julia,
I highly recommend looking at
\begin_inset CommandInset href
LatexCommand href
name "https://storopoli.io/Bayesian-Julia/"
target "https://storopoli.io/Bayesian-Julia/"
literal "false"

\end_inset

by José Eduardo Storopoli,
especially the chapter on MCMC,
which is very nice.
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Section
Expand Down
Binary file modified econometrics.pdf
Binary file not shown.

0 comments on commit 9859d34

Please sign in to comment.