From cc327206c9c7231eb93aaa0c18b13a850da76809 Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Fri, 24 Nov 2023 01:06:22 +0000 Subject: [PATCH 1/7] CompatHelper: add new compat entry for Statistics at version 1, (keep existing compat) --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 36d18e2..5859067 100644 --- a/Project.toml +++ b/Project.toml @@ -30,6 +30,7 @@ MacroTools = "0.5" NLsolve = "4" OrderedCollections = "1" Pipe = "1" +Statistics = "1" julia = "1" [extras] From 4ecd9bbd65b46eca1bfe90a0426f2577ab6bb096 Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Fri, 24 Nov 2023 01:06:27 +0000 Subject: [PATCH 2/7] CompatHelper: add new compat entry for Zygote at version 0.6, (keep existing compat) --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 36d18e2..833231a 100644 --- a/Project.toml +++ b/Project.toml @@ -30,6 +30,7 @@ MacroTools = "0.5" NLsolve = "4" OrderedCollections = "1" Pipe = "1" +Zygote = "0.6" julia = "1" [extras] From 5ba0c13444a3f2499433c5318078559c9a31c16a Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Fri, 24 Nov 2023 01:06:29 +0000 Subject: [PATCH 3/7] CompatHelper: add new compat entry for OptimizationOptimJL at version 0.1, (keep existing compat) --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 36d18e2..59d0b51 100644 --- a/Project.toml +++ b/Project.toml @@ -28,6 +28,7 @@ Distributions = "0.25" ForwardDiff = "0.10" MacroTools = "0.5" NLsolve = "4" +OptimizationOptimJL = "0.1" OrderedCollections = "1" Pipe = "1" julia = "1" From eea2f8cd5b363783bb47eb5b161e1f3cdd3e775a Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Sat, 9 Dec 2023 01:07:08 +0000 Subject: [PATCH 4/7] CompatHelper: add new compat entry for NonlinearSolve at version 3, (keep existing compat) --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index b254dcd..8079cde 100644 --- a/Project.toml +++ b/Project.toml @@ -28,6 +28,7 @@ Distributions = "0.25" ForwardDiff = "0.10" MacroTools = "0.5" NLsolve = "4" +NonlinearSolve = "3" OptimizationOptimJL = "0.1" OrderedCollections = "1" Pipe = "1" From 42c75bf998c7449c71c9a6ce0e4060a5eea9678c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20N=C3=A4gele?= Date: Mon, 6 May 2024 16:24:47 +0200 Subject: [PATCH 5/7] foo --- examples/bayesian.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/bayesian.jl b/examples/bayesian.jl index 25c2013..e72b9ae 100644 --- a/examples/bayesian.jl +++ b/examples/bayesian.jl @@ -25,6 +25,7 @@ priors_dict = @parameters begin α_1 = Uniform() α_2 = Uniform() end +unobserved = @variables Y, T, YD, C # let's say we know that some kind of variables is prone to measurement error # if it is just a constant, we can introduce some bias variable @@ -72,4 +73,8 @@ df[!, :period] = 1:nrow(df) y=:value, color=:variable, Geom.line - ) \ No newline at end of file + ) + +function loglikelihood(results, model, exos, params_dict, unobserved, particles=10000) + # return log(sum(...)) +end \ No newline at end of file From cb3831aa4e747b4c15976a435a82ac03255fe9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20N=C3=A4gele?= Date: Mon, 6 May 2024 18:23:05 +0200 Subject: [PATCH 6/7] Use anonymous function --- src/ConstructResiduals.jl | 19 ++++++++++++++++++- src/Macros.jl | 13 ++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/ConstructResiduals.jl b/src/ConstructResiduals.jl index b85e83d..d40bb8a 100644 --- a/src/ConstructResiduals.jl +++ b/src/ConstructResiduals.jl @@ -1,4 +1,4 @@ -function construct_residuals(name, function_body, args) +function construct_residuals_for_print(name, function_body) f! = quote function f!($(name[1]), $(name[2]), $(name[3]), $(name[4]), $(name[5])) nothing @@ -10,6 +10,23 @@ function construct_residuals(name, function_body, args) function_body[i] = :($(name[1])[$i] = $(function_body[i])) end + # add function body to function + f!.args[2].args[end] = Expr(:block, function_body...) + return f! +end + +function construct_residuals(name, function_body) + f! = quote + ($(name[1]), $(name[2]), $(name[3]), $(name[4]), $(name[5])) -> begin + nothing + end + end + + # construct function body + for i in eachindex(function_body) + function_body[i] = :($(name[1])[$i] = $(function_body[i])) + end + # add function body to function f!.args[2].args[end] = Expr(:block, function_body...) return f! diff --git a/src/Macros.jl b/src/Macros.jl index a99c3f3..e6c2b51 100644 --- a/src/Macros.jl +++ b/src/Macros.jl @@ -1,4 +1,4 @@ -function build_f!(endos, exos, params, args) +function build_f!(endos, exos, params, args, verbose=false) endos = endos.variables exos = exos.variables params = params.variables @@ -26,7 +26,11 @@ function build_f!(endos, exos, params, args) end # construct function for residuals of model variables - return MacroTools.striplines(:(Consistent.f! = $(construct_residuals(name, function_body, args)))) + if verbose + return construct_residuals_for_print(name, function_body) + else + return construct_residuals(name, function_body) + end end """ @@ -80,16 +84,15 @@ function model(; end if verbose - println(build_f!(endos, exos, parameters, eqs.exprs)) + println(MacroTools.striplines(build_f!(endos, exos, parameters, eqs.exprs, true).args[2])) end - eval(build_f!(endos, exos, parameters, eqs.exprs)) return Model( endos, exos, parameters, eqs, - deepcopy(Consistent.f!) + eval(build_f!(endos, exos, parameters, eqs.exprs)) ) end From 474ed175ad8d9780bb2d42bbf4987f17ed59fcae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20N=C3=A4gele?= Date: Mon, 6 May 2024 22:07:02 +0200 Subject: [PATCH 7/7] Fixed runtest for 1.6 --- test/runtests.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f5c9a8d..7997acb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,10 +20,13 @@ using Test z = y * (y[-1] + 0.5 * z) * θ + x[-1] y = z[-2] * x * b end - @test Consistent.replace_vars(test_eqs.args[[2, 4]], [:z, :y], Symbol[:x], [:θ]) == [ - :(endos[1] = endos[2] * (lags[2, end - 0] + 0.5 * endos[1]) * params[1] + exos[1, end + -1]), - :(endos[2] = lags[1, end - -1] * exos[1, end + 0] * b) - ] + replace_worked = @test_warn "Symbols [:b] are not in variables or parameters" Consistent.replace_vars( + test_eqs.args[[2, 4]], [:z, :y], Symbol[:x], [:θ] + ) == [ + :(endos[1] = endos[2] * (lags[2, end - 0] + 0.5 * endos[1]) * params[1] + exos[1, end + -1]), + :(endos[2] = lags[1, end - -1] * exos[1, end + 0] * b) + ] + @test replace_worked # test non-equation let eqs = @equations begin