diff --git a/docs/src/assets/us.csv b/docs/src/assets/us.csv deleted file mode 100644 index f96f39c2..00000000 --- a/docs/src/assets/us.csv +++ /dev/null @@ -1,80 +0,0 @@ -0.996219,0.27220144,8.6533333 -1.9871645,4.5993067,8.8033333 -1.7135544,3.8815764,9.46 -1.7873392,3.9761759,9.43 -1.706049,5.6311292,9.6866667 -1.4702848,3.7534655,10.556667 -0.7318919,3.4632251,11.39 -0.58340721,3.4334975,9.2666667 -0.69288335,3.6552956,8.4766667 -0.61313503,3.6221949,7.9233333 -1.3124225,2.4790907,7.9 -0.52293452,4.057204,8.1033333 -0.70073514,2.0741239,7.8266667 -0.15289176,-1.9518185,6.92 -0.71051201,2.4382886,6.2066667 -0.26062387,2.7857796,6.2666667 -0.394615,4.7990978,6.22 -0.86077046,4.5064218,6.65 -0.67919479,4.2229131,6.8433333 -1.5151159,3.7166353,6.9166667 -0.27564144,3.1092714,6.6633333 -1.0661438,4.5623534,7.1566667 -0.34407705,4.8471778,7.9833333 -1.1340883,4.3460519,8.47 -0.88065851,4.5185768,9.4433333 -0.48041228,6.4140524,9.7266667 -0.53232665,3.1153642,9.0833333 -0.069165999,4.0458157,8.6133333 -0.99418756,6.8270004,8.25 -0.046254271,3.9378556,8.2433333 --0.22121931,6.8500077,8.16 --1.0059852,6.7346735,7.7433333 --0.82618933,2.9791597,6.4266667 -0.38084382,2.3674545,5.8633333 -0.21770641,3.0373692,5.6433333 -0.20385677,3.3050006,4.8166667 -0.78189158,2.7014092,4.0233333 -0.69177854,3.0651491,3.77 -0.70313023,3.0418398,3.2566667 -0.81814394,3.4885312,3.0366667 --0.17043963,2.8995801,3.04 -0.22221029,2.8787124,3 -0.22781192,1.8462991,3.06 -1.0516122,3.3020137,2.99 -0.72996673,2.00456,3.2133333 -1.0070986,2.2657815,3.94 -0.26724988,3.6883203,4.4866667 -0.87204111,2.3214351,5.1666667 --0.0020987643,2.9271668,5.81 --0.12771629,3.2567019,6.02 -0.49609578,2.011153,5.7966667 -0.40412811,2.1746275,5.72 -0.36264185,3.5409926,5.3633333 -1.2856896,3.4246785,5.2433333 -0.48831544,2.2951928,5.3066667 -0.80947489,3.4603022,5.28 -0.39919707,2.4295812,5.2766667 -1.1487125,0.91771862,5.5233333 -0.87575002,1.9950166,5.5333333 -0.37178218,2.1500982,5.5066667 -0.73069627,0.82389319,5.52 -0.29584929,1.3147095,5.5 -0.78232589,2.0456217,5.5333333 -1.1460726,1.872777,4.86 -0.46577486,1.4595597,4.7333333 -0.47152203,2.983584,4.7466667 -0.81669806,2.9614943,5.0933333 -1.4255869,2.9397292,5.3066667 --0.050205261,3.8601974,5.6766667 -1.229021,3.2015788,6.2733333 --0.4453449,3.6388522,6.52 -0.18651993,2.841521,6.4733333 --0.46415573,3.6564719,5.5933333 --0.025224449,3.1722221,4.3266667 --0.68281419,0.97680146,3.4966667 -0.065220213,-0.52567359,2.1333333 -0.50718605,1.2754395,1.7333333 -0.26544415,3.4309366,1.75 -0.32039959,2.2218165,1.74 --0.13384788,1.9156419,1.4433333 diff --git a/docs/src/tutorials/estimation.jl b/docs/src/tutorials/estimation.jl deleted file mode 100644 index fd778df9..00000000 --- a/docs/src/tutorials/estimation.jl +++ /dev/null @@ -1,289 +0,0 @@ -using MacroModelling -using Random -Random.seed!(30) -@model FS2000 begin - dA[0] = exp(gam + z_e_a * e_a[x]) - - log(m[0]) = (1 - rho) * log(mst) + rho * log(m[-1]) + z_e_m * e_m[x] - - - P[0] / (c[1] * P[1] * m[0]) + bet * P[1] * (alp * exp( - alp * (gam + log(e[1]))) * k[0] ^ (alp - 1) * n[1] ^ (1 - alp) + (1 - del) * exp( - (gam + log(e[1])))) / (c[2] * P[2] * m[1])=0 - - W[0] = l[0] / n[0] - - - (psi / (1 - psi)) * (c[0] * P[0] / (1 - n[0])) + l[0] / n[0] = 0 - - R[0] = P[0] * (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ ( - alp) / W[0] - - 1 / (c[0] * P[0]) - bet * P[0] * (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ (1 - alp) / (m[0] * l[0] * c[1] * P[1]) = 0 - - c[0] + k[0] = exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ (1 - alp) + (1 - del) * exp( - (gam + z_e_a * e_a[x])) * k[-1] - - P[0] * c[0] = m[0] - - m[0] - 1 + d[0] = l[0] - - e[0] = exp(z_e_a * e_a[x]) - - y[0] = k[-1] ^ alp * n[0] ^ (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) - - gy_obs[0] = dA[0] * y[0] / y[-1] - - gp_obs[0] = (P[0] / P[-1]) * m[-1] / dA[0] - - log_gy_obs[0] = log(gy_obs[0]) - - log_gp_obs[0] = log(gp_obs[0]) -end - -@parameters FS2000 begin - alp = 0.356 - bet = 0.993 - gam = 0.0085 - mst = 1.0002 - rho = 0.129 - psi = 0.65 - del = 0.01 - z_e_a = 0.035449 - z_e_m = 0.008862 -end - -using CSV, DataFrames, AxisKeys - -# load data -dat = CSV.read("./test/FS2000_data.csv", DataFrame) -data = KeyedArray(Array(dat)',Variable = Symbol.("log_".*names(dat)),Time = 1:size(dat)[1]) -data = log.(data) - -# declare observables -observables = sort(Symbol.("log_".*names(dat)))#[:dinve, :dc] - -data = data(observables,:) - - -# functions to map mean and standard deviations to distribution parameters -function beta_map(μ, σ) - α = ((1 - μ) / σ ^ 2 - 1 / μ) * μ ^ 2 - β = α * (1 / μ - 1) - return α, β -end - -function inv_gamma_map(μ, σ) - α = (μ / σ) ^ 2 + 2 - β = μ * ((μ / σ) ^ 2 + 1) - return α, β -end - -function gamma_map(μ, σ) - k = μ^2/σ^2 - θ = σ^2 / μ - return k, θ -end - -import Turing -import Turing: Normal, Beta, InverseGamma, Uniform, NUTS, sample, logpdf - -Turing.@model function kalman(data, m, observables) - - # if DynamicPPL.leafcontext(__context__) === DefaultContext() - alp ~ Beta(beta_map(0.356, 0.02)...) - bet ~ Beta(beta_map(0.993, 0.002)...) - gam ~ Normal(0.0085, 0.003)#, eps(), .1) - mst ~ Normal(1.0002, 0.007) - rho ~ Beta(beta_map(0.129, 0.223)...) - psi ~ Beta(beta_map(0.65, 0.05)...) - del ~ Beta(beta_map(0.01, 0.005)...) - z_e_a ~ InverseGamma(inv_gamma_map(0.035449, Inf)...) - z_e_m ~ InverseGamma(inv_gamma_map(0.008862, Inf)...) - # end - # alp ~ Uniform(0, 1) - # bet ~ Uniform(0, 1) - # gam ~ Uniform(-1, 1) - # mst ~ Uniform(0, 2) - # rho ~ Uniform(0, 1) - # psi ~ Uniform(0, 1) - # del ~ Uniform(0, 1) - # z_e_a ~ Uniform(0, 1) - # z_e_m ~ Uniform(0, 1) - - # if DynamicPPL.leafcontext(__context__) === LikelihoodContext() - Turing.@addlogprob! calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = [alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m]) - # end - # Turing.@addlogprob! logpdf(Beta(beta_map(0.356, 0.02)...),alp) - # Turing.@addlogprob! logpdf(Beta(beta_map(0.993, 0.002)...),bet) - # Turing.@addlogprob! logpdf(Beta(beta_map(0.129, 0.223)...),rho) - # Turing.@addlogprob! logpdf(Beta(beta_map(0.65, 0.05)...),psi) - # Turing.@addlogprob! logpdf(Beta(beta_map(0.01, 0.005)...),del) - # Turing.@addlogprob! logpdf(Normal(0.0085, 0.003),gam) - # Turing.@addlogprob! logpdf(Normal(1.0002, 0.007),mst) - # Turing.@addlogprob! logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...),z_e_a) - # Turing.@addlogprob! logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...),z_e_m) -end - -using DynamicPPL -model = kalman(data, FS2000, observables) | (alp = parameters[1], - bet = parameters[2], - gam = parameters[3], - mst = parameters[4], - rho = parameters[5], - psi = parameters[6], - del = parameters[7], - z_e_a = parameters[8], - z_e_m = parameters[9]) -logjoint(model,[]) -logprior(model,[]) -loglikelihood(model,[]) -x = string(:alp) -@varname(var"string(:alp)") -using ComponentArrays -get_log_probability_all(ComponentArray(FS2000.parameter_values,Axis(FS2000.parameters)), FS2000, data, observables) -# pars = [0.2275748664844605, 0.9979002291586807, -2130.4765345983997, 306.64891752510715, 0.8040205104339292, 0.7531446779265871, 0.1023822401672587, 0.5046824367348219, 2.854558196537693] -# pars = [0.16567032505797824, 0.2542259201085809, -0.9339496397117015, 1.2051479057232557, 0.7840464832066878, 0.5852821752759191, 0.5992002161458438, 2.831618660156801, 1.1469946639099047] -# pars = [0.4123085111118648, 0.9999921989053889, 1046.4705369500402, -40.5722449868309, 0.7741402851964618, 0.5860029149568086, 0.13639983741497175, 1.2892130991770796, 0.4039048831341653] -# ForwardDiff.gradient(x-> calculate_kalman_filter_loglikelihood(FS2000, data(observables), observables; parameters = x), pars) -# calculate_kalman_filter_loglikelihood(FS2000, data(observables), observables; parameters = pars) -# FS2000.NSSS_solver_cache -turing_model = kalman(data, FS2000, observables) -n_samples = 1000 -chain_NUTS = sample(turing_model, NUTS(), n_samples; progress = true) - - -parameters = FS2000.parameter_values - -logjoint(turing_model,(alp = parameters[1], - bet = parameters[2], - gam = parameters[3], - mst = parameters[4], - rho = parameters[5], - psi = parameters[6], - del = parameters[7], - z_e_a = parameters[8], - z_e_m = parameters[9])) - -logprior(turing_model,(alp = parameters[1], - bet = parameters[2], - gam = parameters[3], - mst = parameters[4], - rho = parameters[5], - psi = parameters[6], - del = parameters[7], - z_e_a = parameters[8], - z_e_m = parameters[9])) - loglikelihood(turing_model,pars) -loglikelihood(turing_model,(alp = parameters[1], - bet = parameters[2], - gam = parameters[3], - mst = parameters[4], - rho = parameters[5], - psi = parameters[6], - del = parameters[7], - z_e_a = parameters[8], - z_e_m = parameters[9])) - -chain_subset = get(chain_NUTS,FS2000.parameters) -chain_subset[FS2000.parameters] - -lll = [logjoint(turing_model, ComponentArray(reduce(hcat, get(chain_NUTS, FS2000.parameters)[FS2000.parameters])[s,:], Axis(FS2000.parameters))) for s in 1:length(chain_NUTS)] - - -lll = [logjoint(turing_model,(alp = parameters[1], - bet = parameters[2], - gam = parameters[3], - mst = parameters[4], - rho = parameters[5], - psi = parameters[6], - del = parameters[7], - z_e_a = parameters[8], - z_e_m = parameters[9])) - for parameters in [reduce(hcat,get(chain_NUTS,FS2000.parameters)[FS2000.parameters])[s,:] - for s in 1:length(chain_NUTS)]] - -sum(lll)/1000 -maximum(lll) -minimum(lll) -get(chain_NUTS,:lp) -chain_NUTS -lll = pointwise_loglikelihoods(turing_model, get(chain_NUTS,FS2000.parameters)) -pointwise_loglikelihoods -# chain_NUTS - -using StatsPlots -StatsPlots.plot(chain_NUTS) -savefig("FS2000_chain_NUTS.png") - -using ComponentArrays -using MCMCChains -parameter_mean = mean(chain_NUTS) -pars = ComponentArray(parameter_mean.nt[2],Axis(parameter_mean.nt[1])) - -function get_log_probability(par1, par2, pars_syms, orig_pars, m, data, observables) - orig_pars[pars_syms] = [par1, par2] - (; alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m) = orig_pars - - logprob = 0 - logprob += calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = collect(orig_pars)) - logprob += logpdf(Beta(beta_map(0.356, 0.02)...), alp) - logprob += logpdf(Beta(beta_map(0.993, 0.002)...), bet) - logprob += logpdf(Normal(0.0085, 0.003), gam) - logprob += logpdf(Normal(1.0002, 0.007), mst) - logprob += logpdf(Beta(beta_map(0.129, 0.223)...), rho) - logprob += logpdf(Beta(beta_map(0.65, 0.05)...), psi) - logprob += logpdf(Beta(beta_map(0.01, 0.005)...), del) - logprob += logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...), z_e_a) - logprob += logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...), z_e_m) -end - - - -function get_log_probability_all(orig_pars, m, data, observables) - (; alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m) = orig_pars - - logprob = 0 - logprob += calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = collect(orig_pars)) - logprob += logpdf(Beta(beta_map(0.356, 0.02)...), alp) - logprob += logpdf(Beta(beta_map(0.993, 0.002)...), bet) - logprob += logpdf(Normal(0.0085, 0.003), gam) - logprob += logpdf(Normal(1.0002, 0.007), mst) - logprob += logpdf(Beta(beta_map(0.129, 0.223)...), rho) - logprob += logpdf(Beta(beta_map(0.65, 0.05)...), psi) - logprob += logpdf(Beta(beta_map(0.01, 0.005)...), del) - logprob += logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...), z_e_a) - logprob += logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...), z_e_m) -end - - -par_samples = reduce(hcat,[chain_NUTS[s] for s in parameter_mean.nt[1]]) -ll = [get_log_probability_all(ComponentArray(par_samples[s,:],Axis(parameter_mean.nt[1])),FS2000,data,observables) for s in 1:n_samples] - -get_log_probability_all(ComponentArray(parameter_mean.nt[2],Axis(parameter_mean.nt[1])),FS2000,data,observables) - -using Plots -granularity = 32 - -par1 = :gam -par2 = :psi -par_range1 = collect(range(minimum(chain_NUTS[par1]), stop = maximum(chain_NUTS[par1]), length = granularity)) -par_range2 = collect(range(minimum(chain_NUTS[par2]), stop = maximum(chain_NUTS[par2]), length = granularity)) - -p = surface(par_range1, par_range2, - (x,y) -> get_log_probability(x,y, [par1,par2], pars, FS2000, data, observables), - camera=(30, 65), - colorbar=false, - color=:inferno) - - -scatter3d!(vec(collect(chain_NUTS[par1])), - vec(collect(chain_NUTS[par2])), - ll, - # vec(collect(chain_NUTS[:lp])), - mc =:viridis, - marker_z=collect(1:length(chain_NUTS)), - msw=0, - legend=false, - colorbar=false, - xlabel = string(par1), - ylabel = string(par2), - zlabel = "Log probability", - alpha=0.5) - -p -savefig("FS2000_posterior_surface.png") \ No newline at end of file diff --git a/docs/src/unfinished_docs/todo.md b/docs/src/unfinished_docs/todo.md index 356fe8b6..f7d3a3ae 100644 --- a/docs/src/unfinished_docs/todo.md +++ b/docs/src/unfinished_docs/todo.md @@ -1,5 +1,6 @@ # Todo list: ## High priority: + - [ ] add balanced growth path handling - [ ] write tests and documentation for solution, estimation... making sure results are consistent - [ ] have conditional parameters at end of entry as well (... | alpha instead of alpha | ...) @@ -28,6 +29,7 @@ - [ ] Find any SS by optimising over both SS guesses and parameter inputs - [ ] have Flux solve SS field - [ ] check control flow in SS solver + - [x] Get functions: get_output, get_moments - [x] get rid of init_guess - [x] an and schorfheide estimation @@ -45,6 +47,7 @@ - [x] have bounds on alpha (failed previously due to naming conflict) - works now ## Not high priority: + - [ ] estimation codes with missing values (adopt kalman filter) - [ ] whats a good error measure for higher order solutions (taking whole dist of future shock into account)? use mean error for n number of future shocks - [ ] implement global solution methods diff --git a/test/FS2000_data.csv b/test/FS2000_data.csv deleted file mode 100644 index 32ebeced..00000000 --- a/test/FS2000_data.csv +++ /dev/null @@ -1,193 +0,0 @@ -gy_obs,gp_obs -1.038361848800944,0.995560488346282 -1.026698201177688,1.003901895206243 -1.03351854312335,1.022765130483065 -1.016303778703926,1.016829533116178 -1.004690447705582,1.038974906567005 -1.014280758630115,1.004624871531346 -1.014563701618431,1.000511508951407 -0.9968543791203329,1.011758691206544 -1.006677793409589,0.998989388580091 -0.9959446236114557,1.002529084471421 -1.002321972240406,1.010595358224016 -1.026199965931845,1.004493260109835 -1.01596854382674,0.9990059642147118 -1.004010077477582,1.001990049751244 -0.9898081484214409,1.003972194637537 -0.9802404297875824,1.002472799208704 -0.9912156332552973,1.003453379378392 -0.9955423015858715,1.002458210422812 -1.006067739365007,1.001471309465424 -1.01465121868034,1.002448579823702 -1.023956300372084,1.004396678065462 -1.014055541093212,1.002918287937743 -1.00799586458257,1.007759456838021 -1.000318718798002,1.010587102983638 -0.9924294461613504,1.009523809523809 -1.002769582182186,1.006132075471698 -0.9931576388514558,1.013595874355368 -1.011334721942962,1.004162812210916 -1.001333675550785,1.013818516812529 -0.9932195307774583,1.006360745115856 -1.005957550014093,1.005417607223476 -0.9843344268648867,1.000898069151325 -0.9685261332871797,1.012113055181696 -1.001960291132494,1.00354609929078 -1.01940388635877,1.005742049469965 -1.018637464995793,1.004830917874396 -1.016616993288192,1.001748251748252 -1.022965428691695,0.9995636998254799 -0.9949007029695747,1.001309471846355 -0.9998654100009913,1.003923278116827 -1.013529108391532,1.004342162396874 -0.9904385539158941,1.003891050583658 -0.9970439631521301,1.004306632213609 -0.9824436544490449,1.003430531732418 -1.001896526095982,1.002136752136752 -1.014012346737039,1.002558635394456 -1.013474871957377,1.002126754572522 -1.016382394402008,1.002971137521222 -1.013849610195207,1.005078290308929 -1.006965459667453,1.002526315789474 -1.005837083657404,1.002519949601008 -0.997920608909262,1.002932551319648 -1.009602848949622,1.00250626566416 -1.008448455557101,1.002916666666667 -1.015099061529582,1.002077274615704 -1.003231741383318,1.007048092868988 -1.020656627871674,1.00247015232606 -1.008368551670767,1.002464065708419 -1.008232785016771,1.004506349856616 -1.000159542700529,1.00489396411093 -1.022428919871923,1.005275974025974 -1.010583468470827,1.004440855874041 -1.015010562846799,1.005225080385852 -1.02141457403402,1.006397441023591 -1.021662547090243,1.00595947556615 -1.001702084553776,1.008293838862559 -1.003797725687984,1.010184097140619 -1.005318157074836,1.008918185343156 -1.00551611956057,1.004611837048424 -0.9983002091537666,1.006503442999235 -1.005058897145481,1.011022424933485 -1.004715179715106,1.011278195488722 -1.016159732969592,1.011524163568773 -1.014951140633097,1.010290334435869 -1.004571112783157,1.009457984721717 -1.00185995497747,1.013333333333333 -1.013105432827478,1.009601706970128 -1.000177021150565,1.011976047904192 -1.002918928211014,1.014270797076227 -0.9920768126061278,1.012697323266987 -0.9957437039904706,1.014571331751948 -0.9984054179125594,1.014028056112224 -1.005811117793546,1.008234519104084 -0.9867713959478989,1.013394315583143 -1.024010956881811,1.015473887814313 -1.002710667353171,1.013650793650794 -1.003439472472856,1.010648293141247 -0.9997492431712409,1.008366904245429 -1.017636050598246,1.014751075599263 -1.020656759459709,1.005451241671714 -1.007764779920605,1.008734939759036 -1.01456168408515,1.013735443415945 -1.024639475791595,1.012076583210604 -1.004642409787667,1.016880093131548 -0.9944751144525267,1.019175729822553 -1.007790038619182,1.019095759618085 -0.9881041124843981,1.019840176357123 -1.001537639221991,1.021075385031073 -0.9866249743042985,1.030960571579783 -0.990779067789768,1.030030800821355 -0.984202549476256,1.022925492150511 -1.006599842813945,1.014859926918392 -1.01572359900605,1.018002880460874 -1.009027629472424,1.018391888705494 -1.021110020223576,1.011576753878213 -1.004688007749569,1.01052872510872 -1.00141846633279,1.014043035107588 -1.006600570610075,1.0178691087782 -1.009738134835758,1.016458196181699 -1.017612419396922,1.01619170984456 -1.013443262875076,1.012534523050775 -0.9969006916317731,1.020352496852707 -1.001623634551754,1.016245116183426 -1.035396393139562,1.020032375556455 -1.006228837491197,1.017060107121603 -1.008375462741865,1.021064950263312 -0.9978948790424976,1.022158548233047 -0.9995603860782909,1.021304429078677 -1.003305590259482,1.021408966148216 -0.9993339196000433,1.019706198495163 -1.002058706424327,1.022136331693605 -0.973264868251988,1.023547610862839 -0.9960599879042776,1.024517212426532 -1.016881726847253,1.025897393869857 -1.016694965654013,1.024924109282633 -0.9888263911862731,1.019017926734217 -1.009210442165513,1.019580847483555 -0.9849574877314445,1.018304576144036 -0.9813189289769133,1.014586709886548 -1.001901505294092,1.012489108335754 -0.9925470459365847,1.013482501434309 -0.9988653298228214,1.011038777243136 -1.007640554466466,1.008958566629339 -1.019470216202808,1.010405105438402 -1.015439124030103,1.008924893587807 -1.016225535437388,1.009662493195427 -1.021184460100726,1.011187491575684 -1.013641693419474,1.007464676086377 -1.004852596178069,1.008864779042075 -1.004008901639205,1.007344262295082 -1.008421963662744,1.010675693269105 -1.0029124252951,1.007986603117352 -1.011755192647018,1.006517571884984 -1.003824279447769,1.008760792280345 -1.010469616735678,1.004531151667716 -0.9990090790916321,1.005137200852023 -1.002888446244,1.007728745948641 -1.003143463237344,1.007545769421079 -1.004383855078334,1.007857581338244 -1.007976308750686,1.007187233524181 -1.006301771347702,1.007861635220126 -1.012174823255131,1.009120364814593 -1.004031420373003,1.006897371863479 -1.008059834262916,1.010511397189087 -1.00331336535076,1.012856474988312 -1.010090406614768,1.009000692360951 -1.007741148272969,1.011550777676121 -1.005156442815526,1.010627473148672 -1.002578150838212,1.008278330909498 -0.9981874522752823,1.00832131365805 -1.007448440324269,1.012323943661972 -1.000528573569216,1.012826086956522 -0.9923024120764135,1.010302640051513 -0.9868341296177798,1.010303802846824 -0.9923760959851408,1.0121964041636 -1.001924756076015,1.007582839929365 -0.9996242427645722,1.007216494845361 -0.9996760105334512,1.006243602865916 -1.009171213292365,1.008340962262232 -1.003500774145286,1.006657923938263 -1.004402337150935,1.003807996793266 -1.007734762348467,1.007087950484177 -0.9977633480714073,1.009516256938938 -1.002580365749726,1.005007855459544 -1.002440485047191,1.004689789936492 -1.010400029938129,1.006612856170378 -1.005233957455249,1.005989759443532 -1.009237409699927,1.00556996062614 -1.001766871088229,1.006494126635469 -1.006407069007927,1.006641996394345 -1.002229887684774,1.006221133000283 -0.9986764768699558,1.004590163934426 -1.005626874756858,1.004755688176054 -1.004378108010232,1.005011600928074 -1.006283136230948,1.005725367069905 -1.012600743193794,1.003030024791112 -1.002789700947353,1.004577077993409 -1.008125853675339,1.004465099325679 -1.008493578098231,1.006985394175814 -1.007636358148353,1.003873873873874 -1.007969756444389,1.002961500493583 -1.004889260717112,1.00286327845383 diff --git a/test/SW07_data.csv b/test/SW07_data.csv deleted file mode 100644 index 5c83aa37..00000000 --- a/test/SW07_data.csv +++ /dev/null @@ -1,231 +0,0 @@ -dc,dinve,dy,labobs,pinfobs,dw,robs -0.125190343495092,3.74590245809472,-0.346646871942539,2.40599138364354,1.73321288857178,-0.390910855357731,0.209166666666667 --0.311350549973952,7.8632665246694,1.15161239527572,3.12008510042125,2.48223977335953,0.149491058377834,0.251666666666667 -0.429219445192359,3.03630734680101,1.16038522796237,3.72278058296871,0.760128270556626,1.80411479077715,0.2725 -1.10204814758356,1.05355467484111,1.53376234618327,3.70532905517229,0.883676382216336,0.374201838469659,0.275 --0.514535875011632,-0.054366832738566,0.247688219858674,3.71684726813908,1.8409541555473,0.628307103489846,0.2875 -0.0960511445626366,-0.410564067900935,0.0739084412649618,2.97850194689238,0.247338225209548,0.964797828024913,0.31 --0.382119840181304,-5.98467636772344,-1.66438273365395,2.09049185540141,-0.398455006770648,0.398455006770689,0.3175 -1.7562547965365,-2.40616152192817,-0.539529184386311,0.365709158814639,-1.10095087276125,1.10095087276125,0.3175 --0.0381809032957676,-1.24411612082761,0.83676666115764,-0.440932473002363,-0.576582594719133,1.77420169939067,0.285833333333333 -0.952915189957594,2.92601419881703,-1.31267961165202,-0.0888388694548326,0.0983767910132549,-0.0983767910132656,0.294166666666667 -1.50105472828255,5.8565465387299,3.72752944647471,0.0559662336831934,-0.307749365805066,2.66079910682451,0.300833333333333 -1.44021227274669,9.86864732111715,2.66242880952962,1.8613449412685,0.39374973967865,0.762332500428933,0.313333333333333 -4.76315338667251,7.80250117903879,3.62979390543319,3.26170775836761,2.09024501598964,0.182580091765963,0.33 --2.9568287628029,-1.84539139398265,2.058564265717,3.91358887387815,1.9059540621623,0.316359616308709,0.359166666666667 -2.16327190545343,-3.77026343348561,1.47994349966473,4.70659391993809,3.6607817602528,-0.417254184937363,0.366666666666667 --2.50974652162233,-3.57856052816862,1.86293638822508,4.88353991762739,0.61238567427071,0.445825258782982,0.3975 -1.21688658652727,-1.09397220814569,1.94214491685773,4.32712691767745,0.0565131408089226,2.02689554947523,0.425833333333333 -0.610431493283898,-1.29620395693397,-0.023129631364327,4.39869574064284,1.10125846080451,-0.0756084440855744,0.4275 -0.595631179795532,1.78197084111221,0.923349585105143,4.90854911753718,-0.0950384418145323,2.11530917356649,0.416666666666667 -1.62515565444977,1.43990445664903,-0.0666815494147386,3.96348327702958,0.189986646328189,-0.189986646328215,0.436666666666667 --0.318993889670651,-7.68357054064359,0.327554218218211,3.79748637530838,1.14344052210056,-0.148407436783714,0.470833333333333 -2.9853311740012,6.555164697121,2.88999951632206,4.6646951106124,0.29208364431863,2.63495458569266,0.498333333333333 -0.654750608618315,3.05398252039646,0.952820153383414,5.74498734691275,0,0.956945101615069,0.52 -0.369727760692172,0.700180829241106,0.538329847851514,4.41089669055464,0.186926218594019,1.69992221184427,0.563333333333333 --0.303738495757159,0.308251212012095,-0.825008405488461,3.14346091194261,0.383751361792806,0.546487904438564,0.514166666666667 --0.771388492760025,-1.83604089758222,-1.9284216912896,1.52694793053138,0.218627109382386,0.703038401110007,0.393333333333333 -0.184604161746449,-2.33652946899923,-0.84055180936241,0.685806016455445,0.321605030405125,0.591643325922114,0.29 -0.811455305093318,1.66473112516078,-0.186697025815988,-0.0510200591484704,0.0924742361980258,-0.092474236198008,0.2225 -0.576932144730677,3.52508037392226,0.852539362231937,-0.534355056351558,0.179265061451961,0.725718490539784,0.256666666666667 -1.37724385989509,1.66561742841617,1.64573708766568,0.218354868806387,0.281827729761597,0.615039268514487,0.246666666666667 -1.73727018612993,3.08579685685316,2.5216388894263,1.28093757713066,0.480523560472479,0.408371181252143,0.335833333333333 -1.21702814101496,4.2169299862436,1.25665977356471,2.35358463136157,0.41924275327534,0.461820214940111,0.375 -0.559847440552005,2.34409224081927,1.00393866449497,3.81921870729673,0.742782692078903,0.130585304796583,0.485 -0.239131064013975,0.0793325106021996,0.260082683213227,4.69263825896616,1.00647104507132,-0.140664770759884,0.589166666666667 --0.674629817078255,-1.27636160637712,-0.738394948457312,4.46514247724218,1.00687829505217,0.702565040877836,0.620833333333333 -0.154695641712237,0.933174102883356,0.512520496195066,4.15766958538524,0.577509994556813,1.93308211855084,0.673333333333333 --0.391066896167047,0.0375058825424048,-0.415640990585189,4.15437407907569,1.27836792468146,-0.455318011029931,0.7025 -1.29266641096888,-0.523860374086951,1.33329583247587,3.95707268877595,0.383406650182216,1.24264543699585,0.731666666666667 --0.0924196744412598,-0.796952592974748,0.344246290951674,3.66254592573938,1.40344292133512,0.196591213308992,0.733333333333333 --0.161245780470836,-1.40436076141302,-0.538321163619685,2.71575407190414,0.681911988588446,0.892923708225467,0.75 -0.666621175366686,0.638635102370841,0.627411213239952,2.30817559335992,0.592882189073274,0.185331855132233,0.808333333333334 -0.189812524157333,-1.82673255990676,-1.45102220801482,0.511900531323704,0.00993443275203454,1.52855745119588,0.813333333333333 --1.59647721231283,-8.74667249546337,-3.08040127876234,-1.37178920220987,1.09663221107303,-1.09663221107304,0.465833333333333 -0.418637603338539,-2.9277410793724,0.327354028454693,-1.86791845273086,0.313925798595571,1.20125470346468,0.235 -0.792714101415072,0.487870888233203,2.00772025516142,-1.32138142370786,0.654107574797402,0.0949595981183506,0.330833333333333 -0.381989134703531,5.33582661868968,1.89195027747485,-0.3466837297197,0.499891841541489,0.981616736972576,0.540833333333333 -1.90670765404735,5.52311048353062,1.51622364168611,0.237782659215213,0.232108421420341,0.500495587786944,0.6425 -1.54748019781727,3.16346472289075,2.22625843468643,1.5174915893445,0,0.727275932907986,0.770833333333333 -1.03888601836798,0.996146604245098,-0.432872323177094,1.05269801260982,0.236389622103284,0.485635175245399,0.894166666666667 --0.0840638060431616,-1.92543746310577,0.0340328845528575,0.548440562406256,0.418340234564329,1.01025549018335,0.9975 --0.00726558060227944,2.41284371161083,1.52111080911084,0.0408303535523942,0.435709674004281,1.66963124577892,0.983333333333333 -1.12902437794247,-2.44318375590541,-0.781887187950019,1.14077712442491,0.348158215040373,-0.348158215040364,0.924166666666667 --0.699488697061895,-3.48296859640629,-0.162716021786991,0.853816226596052,0.380156321734759,0.311887962722629,0.734166666666667 --0.0755912706160871,-1.31936321193436,-1.65512195343695,-0.134784709974667,0.293630331737438,0.393657597038754,0.574166666666667 --0.432264100951159,-2.08127199515684,0.236514944153782,-0.833138594130219,0.21729896594338,0.465297541096604,0.500833333333333 -0.94671961854948,1.10056369171392,1.54005165302362,-1.447272343728,0.212119149039314,1.13925276763298,0.433333333333333 -0.231867722777849,1.65409893142217,1.30079325301347,-1.57034377485627,0.310296440790436,0.358602374289205,0.420833333333333 -1.60984095839706,2.75304136543315,1.86469060745196,-0.825505406655282,0.337410695475793,0.327043576391091,0.6 -0.755469055327865,1.52951042395864,1.6234953082627,-0.628525516737966,0.587743085706771,1.37953347416369,0.614166666666667 -1.04535825810768,2.55999233447503,0.717578585387628,-0.253213252728301,0.148719644457929,0.498531806103827,0.651666666666667 -0.375881615681806,0.0265757558824191,0.45957431767215,-0.34332975746679,0.241198688296995,0.401890344732053,0.711666666666667 -0.807952050495317,-1.47945733509604,-0.317507694048118,-1.1308607689603,0.314538397071162,0.324441412805932,0.730833333333333 -0.249057539344847,0.487545239834049,0.812986170892373,-1.26308989288128,0.226040921986348,1.03979876520602,0.741666666666667 -0.457708763954201,3.70071490538822,0.808603271257084,-0.794425988626529,0.197942385158578,0.42901891620096,0.740833333333333 -1.22167778456702,1.65666385001623,1.45426983614084,-0.942665406043204,0.197551347182623,0.425503627880985,0.8325 -0.0427345745158618,2.13673667753181,0.352997846141534,-0.711096838440881,0.745333704857432,0.489249877372476,0.863333333333333 -1.71106043802899,2.69184464206651,1.79635920943849,0.367014179673788,0.29567651809308,-0.295676518093046,0.865833333333333 -1.32088780240753,-0.0315985813364534,0.755169413167096,1.3749607673825,0.258568040814167,0.960959268567663,0.8725 -1.33209022442065,0.929263850764329,0.92484937690881,0.791506900215836,0.3933719720008,0.811461879616605,0.864166666666667 --0.313577723902199,0.888912605084414,-0.170734634880091,0.85977586885673,0.495161939019351,0.101854759631074,0.894166666666667 -1.59260985030284,3.4946993052146,2.00832398881482,1.653126511908,0.506126088821057,0.0873474631603699,0.993333333333333 -0.752581486153531,2.1901704502383,0.937676503611556,2.0780228722125,0.432428286800324,0.157543925918496,1.01916666666667 -1.38079781930566,2.1474231236009,1.67625647933926,2.14471268615733,0.368537148688564,0.801066827630592,1.01833333333333 -2.11624597668481,2.41369751652351,2.05601746978596,2.44969671196424,0.636185048276428,0.519897191831156,1.04166666666667 -1.31457239966488,2.27031276882315,2.1474273608826,2.8386658124877,0.649666478856759,1.62315862889886,1.13916666666667 --0.0437709789341056,-0.697561706681654,0.0659646860557359,2.87508445051509,0.840908599851975,0.27642145996057,1.22833333333333 -0.580089313263045,-1.4183398543631,0.371337432584937,2.82516728917369,1.04880220750427,0.604127987616746,1.3525 --0.0250503382756619,-3.09029022972808,0.502367855014768,2.85668743017135,0.914614461882346,0.172352761808039,1.39083333333333 -0.0863998645534707,-2.69847636152343,0.551218405046939,1.8738144201244,0.454189290234908,1.15442448492753,1.20583333333333 -0.901536358215196,2.02269260500407,-0.368192671766451,1.45204148644029,0.544845391508808,1.03830113015928,0.9975 --0.036067005149107,0.134124498830403,0.298466667745288,1.8278754141499,0.980810947597099,0.577662154072698,0.973333333333333 --0.102115650942437,2.79339776395042,0.299893663714784,1.95451900972893,1.10337937060963,-0.077729353890696,1.04333333333333 -1.93120469907205,1.91922978717085,1.64934919063955,1.05194292835472,1.08725710516566,1.92804671190308,1.19666666666667 -1.17216692000295,-0.994498065708484,1.34488852824461,2.01649944497791,1.04326181158747,0.430966362132903,1.495 -1.50478134434434,0.674764757670005,0.270479643860426,1.80729714443765,0.984517003599139,0.947910279041118,1.48583333333333 --0.32447756323478,2.78147043841241,-0.0542259746338232,1.39975906987803,1.40562171335872,0.490169661102719,1.47916666666667 -0.611787689018058,2.69452948126065,1.11695102400597,1.73019909795039,1.03554702746766,0.363077170006328,1.64166666666667 -0.224381844552795,-0.180085283682587,-0.122044369887135,1.79895787589788,1.28723861781825,0.092093595415303,2.08166666666667 --0.15600244017736,0.637531508690898,0.191441724216816,1.80089475239208,1.4305082340063,0.379495930355482,2.24583333333333 -0.170294231183732,-2.98363593646593,-0.958862076727655,1.49053185376613,1.29418675821871,0.483637843909705,2.235 --0.168378339814012,-1.60005692018828,-0.685406487299474,0.77287256205625,1.41819949684074,0.760535921649991,2.14333333333333 --0.332198226277285,-1.89889171573429,-0.345503029077122,-0.684320091944414,1.36555972658932,-0.0807454788044471,1.97 -0.484330725396717,0.103805404140388,0.316114907955239,-1.65000920913775,0.79528335639325,1.31005756339001,1.67583333333333 --0.849223977248585,-0.616037354395132,-1.66119100858316,-2.29236260503996,1.2830134128901,-0.453133131420584,1.39166666666667 -0.779733908318917,1.86206781559005,2.17739087173163,-2.66242004628498,1.49216825216483,0.552892794964215,0.964166666666667 -0.176429525146773,3.57352431578028,-0.00678783990133525,-3.01581366648901,1.3036900649479,0.302770185432797,1.14083333333333 -0.209813641807273,1.54946590519603,0.237171000973945,-3.06138510933738,1.00541555559084,0.182717233084411,1.36833333333333 -0.913289518364309,2.20836253713924,-0.281339920395794,-2.35635843635703,0.797799167408586,-0.0134814213059684,1.1875 --0.305452079379961,2.95125058145442,0.633677505326887,-2.17117576262876,1.55325187596214,1.14440689385804,0.885 -1.35715302497158,1.27213291476562,1.80947746532547,-1.88515430844944,0.59591739791558,0.538310262477884,1.075 -0.909001870907844,0.589379404983248,0.417873406567765,-1.80802009619111,0.966640422200049,0.525924599467532,1.185 -1.33864117535325,4.21105623981151,1.14615638245868,-1.80545672040722,1.32017286313073,0.514741003688906,1.28583333333333 -1.30903892701593,3.42121529607758,1.99276526081144,-1.40693395554325,1.19342446402348,1.67415553364315,1.63416666666667 --0.184482837171174,0.527384407984556,0.633280441308216,-0.789678028067613,1.53553880831945,-0.132006996681117,1.95416666666667 --0.27616034250417,-0.61927413729552,-1.04914735496129,-0.678841283001987,1.93045262959055,0.138586696154078,2.64 --0.729801808639763,-2.20848852717162,0.443845509961648,-0.50293707599144,1.96108899537681,0.0660074419850947,2.49916666666667 --0.351031405737444,-2.8793163707233,-1.38211344352715,-1.2200151871827,1.89341167371011,0.420741182459347,2.33083333333333 -0.308690238022223,-1.37849792028706,-0.219386958255768,-1.86923117574833,2.32768363975069,0.253104755836544,2.8125 --0.326784574154658,-1.29083309630565,-1.47382392011093,-2.37207402093583,2.89657915064785,-0.0706454192074997,3.0225 --2.41406047980945,-5.34166374771797,-0.893328100636609,-4.00898429626125,2.94765260968033,-0.19938804029715,2.33666666666667 --0.0695735326093541,-5.64304653359247,-1.68865167773401,-6.78927742669629,2.27121189229451,0.40353894440832,1.57583333333333 -0.887962743600269,-1.11291399288302,0.256553071540225,-7.38777956287987,1.51079697777905,0.521203271316676,1.355 -0.867452325660111,1.2079239960249,1.10952390863008,-6.82627387472877,1.84129426623487,-0.131850930304821,1.54 -0.476061147341795,1.09440483473068,0.811257139643089,-6.32375179062433,1.7438993046174,0.21420521529325,1.35333333333333 -1.50419576014883,3.46950232002848,1.74769124489217,-5.14967657995794,1.09943075418935,1.09243781657525,1.20666666666667 -0.23875222685723,1.88749290105028,0.294544003978899,-5.24198281363874,1.06488679460952,0.814363140327244,1.29916666666667 -0.71908078234145,0.581883379886449,-0.00470312037339227,-5.2731452961163,1.35869961778621,1.00671947200276,1.32083333333333 -0.612876752062505,4.31088098112642,0.270216055867877,-5.35688015089181,1.808482920215,0.248144837932677,1.21833333333333 -0.868170999086999,3.67945337223046,0.763368041001854,-5.01331602639664,1.62573830754549,0.139755216326615,1.165 -0.332954624047943,5.39069350396372,1.4760179570178,-3.8583717615582,1.43713056935884,0.543132160259107,1.28916666666667 -0.754423906505394,1.84550053259423,1.28588887145258,-3.82412742007023,1.20960709704114,0.732201488669051,1.455 -0.30714957448123,1.32228341677089,-0.454753001423455,-3.04264136987695,2.15523099764292,-0.486539119141474,1.62833333333333 -0.331021454651477,0.795258492486283,-0.107518363730037,-3.27706176248711,1.47812145986013,1.31926374438048,1.68916666666667 -1.90648611188021,6.83302678941104,3.43265404542467,-1.48912755945565,1.81689588188028,0.00547801376488222,1.82083333333333 -0.0695540932417771,2.65422108930164,0.523474875747638,-1.55508752517517,1.64348889746737,0.146268048286905,2.025 -0.109078744927274,1.55137972534553,0.841241746722517,-1.08373816696428,2.09417118387707,0.315583974028982,2.39583333333333 -0.176087142252925,0.689026637387912,-0.253478971104869,-1.04830252575186,1.74672329679821,1.02826799849204,2.51833333333333 --0.223523184600538,-1.06104500560622,-0.32557479823106,-1.83556889548561,2.43889365797672,-0.355484967692531,2.545 -0.823953212108108,1.63806465616742,0.260984201530164,-1.32123030858776,2.13170928859383,0.1109942901506,2.73666666666667 -0.162148154893941,-1.41059880655629,-0.223439342796382,-1.33456540178685,1.97967584243823,0.410876242917207,3.39416666666667 -0.270271440997817,-1.64026638258838,-0.106994466072706,-2.02244659556521,2.08695819590496,0.823043452739099,3.76166666666667 --2.45506627646796,-9.38633690596544,-2.42908482403868,-4.11450889974486,2.18685285693714,0.454810187457052,3.17166666666667 -0.725263246697011,0.447779718695159,-0.581364138675895,-4.68247253795119,2.24457801055737,0.329093453847617,2.45916666666667 -0.691670179703237,2.95860941237575,1.49165889587266,-4.12815215303152,2.73177312906308,-0.0458462240362348,3.96333333333333 -0.087455199362239,0.481814242284287,1.66010977796418,-3.63474885475694,2.5461811454889,0.0694867193839652,4.1425 --0.52597979805546,0.684579276839344,-1.11288008264535,-3.7997506886847,1.8620010026976,-0.155474947278978,4.445 --0.0667060690821018,-0.430387424250085,0.864404597089902,-4.8506100805584,1.76426907185547,0.411548981016281,4.39416666666667 --1.39589608119115,-0.591312594467013,-1.59321072461853,-5.39500658255463,1.80780864212924,-0.328734841989656,3.39666666666667 -0.259209384759004,-3.36588162067889,-1.94892637881469,-6.95436036740711,1.35097406520286,1.22565801122008,3.55666666666667 --0.210999330841787,-3.89334609373518,0.230702569312029,-6.52555811781468,1.20624439072801,-0.414474617049413,3.62833333333333 -0.626937882375614,-3.98145114804964,-0.669146054121939,-7.01915334588534,1.40259224532642,0.162384921386284,2.75166666666667 -1.53523562744346,-1.39465955897978,-0.214518230372732,-7.7491341974519,1.07207134869514,0.162512233534833,2.32166666666667 -0.751643602632271,0.604436005531454,0.960855168582953,-7.69331559088613,0.818711639690939,0.249185617894485,2.16333333333333 -1.89965651466298,2.38574920515879,1.96989927447646,-6.95037293727017,0.719588994986875,0.03627250240578,2.20083333333333 -1.76884245259595,4.35513998183211,1.6718675180424,-4.89131331890343,1.0186480656893,-0.418045659668098,2.365 -1.19846576693806,4.78515398288937,1.73896193449923,-4.22084608942475,0.752689273057605,0.289762460530745,2.3575 -0.268183757919189,1.51790444212506,1.52187217481821,-3.20150733150422,1.24202757351757,0.0824951014845881,2.42166666666667 -1.27573604704384,3.35555519757702,1.45204840654662,-2.0391951131727,0.859589206549405,0.0137787903259654,2.63916666666667 -0.47772181971709,1.35583713264253,0.700693609718428,-2.29209347146798,0.796357825094951,0.642515920115007,2.8475 -1.00027454935952,1.12308782650445,0.514695395169497,-2.14306919626875,0.633721260057385,0.0780255168290123,2.31666666666667 -1.39618449179193,-0.268256022415699,0.700584498751027,-1.73164730309628,1.11968597431575,0.148829978415919,2.11916666666667 -0.856154666288148,0.58873406885516,0.611478709925677,-1.70767925156122,0.569555629278007,0.267269337773583,1.98083333333333 -1.84278816989831,-1.06842379727604,1.28957416743367,-1.79615064295803,0.413235586754457,0.966096626479142,1.975 -0.0710181743050953,1.58907598146845,0.46937498887371,-1.50970393605189,0.643704007482615,0.986766895011768,2.02583333333333 -0.544178039350697,-0.406613186032558,0.458668530616592,-1.54319272944753,0.515110298137511,0.823597780108453,1.95666666666667 -0.326252498049257,-0.27081756372661,0.121088067991423,-1.97833929505293,0.512470503989349,0.414074840589595,1.73 -1.60527893903395,-0.564336170392977,0.667996503001859,-1.76428598214096,0.577082638577231,0.340956595918969,1.55166666666667 -0.400089733961863,0.399036824619316,0.210244767069867,-1.48404825929714,0.651695382770434,1.03119223024523,1.56666666666667 --0.00923405229406171,-2.85473580948485,0.306036045002315,-0.597099427250385,0.822833289121228,-0.69454590783228,1.555 -1.38103238669055,1.06341789817995,0.805451617581753,-0.230139524927495,0.543445950840926,0.349986922535658,1.6625 -1.12296850240637,1.28016825044145,0.635879761713795,0.131989467962512,0.742278213849446,0.269108409843377,1.71083333333333 -0.119619758239367,-0.165882686162661,1.48497022417826,0.666162470989661,0.723288742447625,0.526727533975484,1.72916666666667 -1.39303192354464,-0.360525847763881,0.215328369000986,0.298843173317209,0.846886478045672,0.755119440372768,1.66583333333333 -0.632957496726931,1.36183262460486,1.03450145610054,0.82976579991896,0.951390551623099,0.14284529047128,1.78916666666667 -0.662890954428349,-0.509296492154334,0.287225645453646,0.918128346660069,1.11067497633348,0.0912625702449841,1.99583333333333 -1.16974375155604,0.991736088407464,1.08835575485762,1.70847815663251,0.747126528219777,-0.151532152934678,2.1175 -0.147636796945449,0.0894480675246427,0.729802796951617,2.38852503459816,1.12515121604408,-0.887903180681059,2.36083333333333 -0.594718841406348,-0.433412546841907,0.435507733355053,2.58456751489877,0.954440742925922,-0.599620737316234,2.43166666666667 -0.648556418838609,1.21610746067717,0.483145824664803,2.70146258453212,0.706096328815242,-0.000211044852767017,2.27083333333333 -0.371275472319951,-2.05768557449272,0.0307172983364126,2.32402517783675,0.68981474263472,0.707181201385354,2.15333333333333 -0.290621071858197,-0.18308572342292,0.348174213848893,2.3591491406425,1.18900024022039,0.643811660209636,2.0625 -0.0386311423858956,-3.38568166104113,0.0448378415075013,1.55321811579159,1.15781261965919,0.975901119153892,2.06083333333333 -0.543259065299651,-1.57282272332907,-0.223814218084158,0.585872361659085,0.881591584793018,0.661989228190922,2.04 --0.449797987498187,-3.29228562756691,-1.02958944171655,0.0188529915169511,0.746920163935716,0.124545046308658,1.93583333333333 --1.0721999274744,-4.15415888591548,-0.72366653829647,-0.984652080396813,1.17880502817185,-0.422453502447395,1.60666666666667 -0.578987771466473,-1.00602481436127,0.444640987769049,-1.43187566420426,0.642468134766361,1.17091488903764,1.46583333333333 -0.186237784950322,-0.66442724341087,0.23835810529124,-1.53413035516479,0.706817128653725,0.449265111453899,1.41083333333333 --0.094296526365099,-0.948322466532744,0.191069270167077,-1.79484578907977,0.522452473334845,0.517057926699119,1.20416666666667 -1.58045440035426,0.0194601258561136,0.809697596112301,-1.77846641300687,0.602598253534037,1.3431876614001,1.00583333333333 -0.443792178140484,3.12803429844956,0.73500852743723,-1.42356888960887,0.545632523303663,0.262452682090203,0.9425 -0.963756808801122,0.940311070772509,0.707295462775505,-1.40004855556901,0.451468035452685,0.947156162021317,0.814166666666667 -0.961834289805324,2.50744001254387,0.789754758182312,-1.43822664437084,0.517255443086917,-0.121215321477269,0.759166666666667 --0.152850242722309,0.105435071694586,-0.131793817732842,-1.20198472812643,0.776031730804494,-0.578598300432672,0.76 -0.746927848495943,1.73406107146735,0.274167588954583,-0.481535473952988,0.549186414734049,-0.155485118800142,0.75 -0.735887916916227,1.3123355567017,0.248790458001281,-0.290398853713782,0.429962192140199,-0.0378048268220361,0.765 -0.60315452962783,3.67777137658223,1.05361121647752,-0.0387475382106004,0.527004507861317,-0.136379011154791,0.7475 -0.655235582864236,0.988726763679892,0.774516204829638,0.0187502639078616,0.604650921766581,0.558152877745318,0.803333333333333 -0.619042543161527,2.05768034625504,1.07337788332063,1.08300213465463,0.418867443957627,-0.611731534598141,0.985 -0.692356232170312,0.478613456701055,0.290319051559095,1.34267496415367,0.638285893000212,-0.734857604996176,1.12166666666667 -0.695674209158938,2.18513192502132,0.886988356788493,2.03632003648897,0.465060733945677,0.112975557604306,1.29166666666667 --0.13629675445776,1.8974539165884,0.135120406197188,2.11518436914457,0.633489256988273,0.132064721144578,1.4525 -0.81057930107437,-0.612951072213264,-0.0302963924410733,1.53247355200392,0.358800531063608,0.211543220323367,1.505 -0.566764029506203,0.729755735170983,0.553798381808406,1.81584340460392,0.4670165101337,0.100092760247856,1.44916666666667 -0.345964234547694,1.30582943777858,0.455169317397576,1.47506426342147,0.479943846980646,0.458149336395959,1.43 -0.644676222993383,1.32063508322921,0.490597779543691,0.821486302600363,0.639577373281419,0.382261522586397,1.34083333333333 -1.11375907158339,2.29193665008899,1.37403448233181,1.25566766650866,0.354035677060871,0.565934012781487,1.31083333333333 -0.438904497893077,1.99307181315166,0.550585560601576,1.81153070016018,0.311284298049053,0.418645950112129,1.32666666666667 -0.664410644718487,0.766504390071532,0.859941188172456,2.39501585510294,0.529722418513767,-0.0762069019746487,1.32 -0.427418927173278,0.676124457374442,0.305518305326473,2.73927007830616,0.637455721560087,-0.00596963569262421,1.31916666666667 -0.277934657334754,1.63262818446404,1.291772942134,3.07773452723876,0.159781385827884,0.557067562033314,1.38083333333333 -1.2943997932079,3.19248604750266,0.97569626721122,3.4851745817619,0.343924004727647,0.633427177970351,1.38333333333333 -0.755759478875461,0.090134152423957,0.455419838506032,3.43281837706047,0.326053167946228,1.42684009263006,1.37666666666667 -0.697280372351372,1.96876920633719,0.875217173331294,3.52019982304159,0.253210857669828,1.55484528383764,1.38 -1.32709997507044,2.26035807575244,0.409786835756336,3.33742357921142,0.16637381786957,1.27371883751282,1.375 -0.88531202752381,0.704141207032023,0.863268913179809,2.99267688766003,0.364015771494142,1.1385166691809,1.38333333333333 -1.06308963239957,2.19016256015749,1.20885323014136,4.13603268696932,0.345159332822398,0.233115719368804,1.215 -0.462499468709495,0.942232527584793,0.468627159773291,3.9523792259597,0.40563830316529,1.3903283366539,1.18333333333333 -1.5732869366758,1.79686529253036,0.555612238267941,3.98699031238579,0.354868527607799,-0.0317664694631681,1.18666666666667 -0.949492130996873,1.11565401095891,0.86610968398179,4.05813225128964,0.346472007972931,0.536713178809926,1.27333333333333 -1.09910107519522,-0.0724456805704108,1.46539379241449,4.0902605206652,0.426583150896764,1.63045140566613,1.32666666666667 -0.122946014964555,0.944866024986311,-1.18051725516216,4.18893530278592,0.895080034395157,2.4924648145834,1.42 -0.417638062299034,1.88643854344883,1.29022726704488,3.76265129151977,0.430017441329778,-0.127674051530086,1.56833333333333 -0.589930840077784,-0.524245043384156,-0.433010731732338,3.06124307383124,0.51399085178172,1.42926910220591,1.63 -0.578441118484307,-0.298732183236552,0.217694988508697,2.8317993364584,0.405126845008397,0.111670170835929,1.61833333333333 -0.161646627345931,-1.78347312066506,-0.376035971588294,2.4519507805187,0.80339200516848,0.876092523896539,1.39833333333333 --0.172709114345992,-2.88228040821491,0.0107063410557657,1.19438147970055,0.759832841385943,-0.110245569841389,1.08166666666667 --0.149230347689411,-1.33187658020631,-0.671393919933962,0.206238608853937,0.412830520880281,0.0178951988777101,0.874166666666667 -1.00251695438243,-3.60760800779718,0.0742633694899268,-0.688298432615568,0.501298009956219,0.283579369250905,0.533333333333333 -0.166504093667356,-1.90349573045552,0.583238395877856,-0.832836684820563,0.250676424936813,1.02052713389944,0.433333333333333 -0.711646999732977,-1.61049328681082,0.340853686381706,-0.680085923833474,0.444635933952409,0.463508623871704,0.4375 -0.57708492580656,-0.675429124646257,0.33625691610996,-0.751883550010632,0.318994861044786,0.0281071882430552,0.435 -0.16804908125664,-0.33038731334284,-0.125306365705796,-1.39752979495165,0.487093955721107,-0.210277169959817,0.360833333333333 --0.0205252293212652,-0.42810961574645,-0.285066330985046,-1.79949697620765,0.711530121738591,0.661175029411204,0.3125 -0.593974742483908,1.97908039708489,0.752780433887438,-1.98259646486827,0.283011466756822,1.07110536496052,0.311666666666667 -0.963100368463358,3.77434088854915,1.45254639128268,-2.47480348336313,0.329327912571209,1.07303229820342,0.254166666666667 -0.477770530240775,2.48717621866388,0.681041328242827,-2.09159392019234,0.352657756486163,0.637122676239891,0.251666666666667 -1.06272365803494,0.843084076624677,1.01716103905153,-1.88739671956142,0.676433680105237,-0.152529403853073,0.250833333333333 -0.134490769038962,3.27115245186013,0.579110626934039,-2.28738981395816,0.786670661654654,0.640072087445695,0.2525 -0.890420982568628,2.16798602005923,0.664565005542386,-1.87907140900137,0.359229290844265,0.983931292021872,0.358333333333333 -0.788226274207716,2.18192499178394,0.614386847994297,-1.76049362247306,0.568063223871995,0.254465931034027,0.4875 diff --git a/test/estimation.jl b/test/estimation.jl deleted file mode 100644 index 1421dd30..00000000 --- a/test/estimation.jl +++ /dev/null @@ -1,179 +0,0 @@ -import Turing -import Turing: Normal, Beta, Gamma, InverseGamma, truncated, NUTS, sample, mean, var, MCMCDistributed -using MacroModelling -using CSV, DataFrames, AxisKeys - -# load and solve model once -include("models/SW07.jl") -get_solution(m) -parameters = deepcopy(m.parameter_values) - -# load data -dat = CSV.read("test/SW07_data.csv",DataFrame) -data = KeyedArray(Array(dat)',Variable = Symbol.(names(dat)),Time = 1:size(dat)[1]) - -# functions to map mean and standard deviations to distribution parameters -function beta_map(μ, σ) - α = ((1 - μ) / σ ^ 2 - 1 / μ) * μ ^ 2 - β = α * (1 / μ - 1) - return α, β -end - -function inv_gamma_map(μ, σ) - α = (μ / σ) ^ 2 + 2 - β = μ * ((μ / σ) ^ 2 + 1) - return α, β -end - -function gamma_map(μ, σ) - k = μ^2/σ^2 - θ = σ^2 / μ - return k, θ -end - -# test functions -# Gamma(gamma_map(.5,.2)...)|>mean -# Gamma(gamma_map(.5,.2)...)|>var|>sqrt - -# InverseGamma(inv_gamma_map(.1,2)...)|>mean -# InverseGamma(inv_gamma_map(.1,2)...)|>var|>sqrt - -# Beta(beta_map(.5,.2)...)|>mean -# Beta(beta_map(.5,.2)...)|>var|>sqrt - -get_SS(m) -using ForwardDiff -# define priors and likelihood -Turing.@model function kalman(data, m, observables) - z_ea ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - z_eb ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.025, 5) - z_eg ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - z_eqs ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - z_em ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - z_epinf ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - z_ew ~ truncated(InverseGamma(inv_gamma_map(0.1, 2)...), 0.01, 3) - - parameters[indexin([:z_ea],m.parameters)] .= z_ea - parameters[indexin([:z_eb],m.parameters)] .= z_eb - parameters[indexin([:z_eg],m.parameters)] .= z_eg - parameters[indexin([:z_eqs],m.parameters)] .= z_eqs - parameters[indexin([:z_em],m.parameters)] .= z_em - parameters[indexin([:z_epinf],m.parameters)] .= z_epinf - parameters[indexin([:z_ew],m.parameters)] .= z_ew - - - constepinf ~ truncated(Gamma(gamma_map(0.625, 0.1)...), 0.1, 2.0) - constebeta ~ truncated(Gamma(gamma_map(0.25, 0.1)...), 0.01, 2.0) - - parameters[indexin([:constepinf],m.parameters)] .= constepinf - parameters[indexin([:constebeta],m.parameters)] .= constebeta - - - crhoa ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhob ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhog ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhoqs ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhoms ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhopinf~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - crhow ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.001, .9999) - cmap ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - cmaw ~ truncated(Beta(beta_map(0.5, 0.2)...), 0.01, .9999) - chabb ~ truncated(Beta(beta_map(0.7, 0.1)...), 0.001, 0.99) - cprobw ~ truncated(Beta(beta_map(0.5, 0.1)...), 0.3, 0.95) - cprobp ~ truncated(Beta(beta_map(0.5, 0.1)...), 0.5, 0.95) - cindw ~ truncated(Beta(beta_map(0.5, 0.15)...), 0.01, 0.99) - cindp ~ truncated(Beta(beta_map(0.5, 0.15)...), 0.01, 0.99) - czcap ~ truncated(Beta(beta_map(0.5, 0.15)...), 0.01, 1) - crr ~ truncated(Beta(beta_map(0.75, 0.1)...), 0.5, 0.975) - - parameters[indexin([:crhoa],m.parameters)] .= crhoa - parameters[indexin([:crhob],m.parameters)] .= crhob - parameters[indexin([:crhog],m.parameters)] .= crhog - parameters[indexin([:crhoqs],m.parameters)] .= crhoqs - parameters[indexin([:crhoms],m.parameters)] .= crhoms - parameters[indexin([:crhopinf],m.parameters)] .= crhopinf - parameters[indexin([:crhow],m.parameters)] .= crhow - parameters[indexin([:cmap],m.parameters)] .= cmap - parameters[indexin([:cmaw],m.parameters)] .= cmaw - parameters[indexin([:chabb],m.parameters)] .= chabb - parameters[indexin([:cprobw],m.parameters)] .= cprobw - parameters[indexin([:cprobp],m.parameters)] .= cprobp - parameters[indexin([:cindw],m.parameters)] .= cindw - parameters[indexin([:cindp],m.parameters)] .= cindp - parameters[indexin([:czcap],m.parameters)] .= czcap - parameters[indexin([:crr],m.parameters)] .= crr - - - csigl ~ truncated(Normal(2.0 ,0.75), (0.25) ,(10)) - csadjcost~ truncated(Normal(4.0 ,1.5), (2.0) ,(15)) - csigma ~ truncated(Normal(1.50 ,0.375),(0.25) ,(3)) - cfc ~ truncated(Normal(1.25 ,0.125),(1.0) ,(3)) - crpi ~ truncated(Normal(1.5 ,0.25), (1.0) ,(3)) - cry ~ truncated(Normal(0.125 ,0.05), (0.001),(0.5)) - crdy ~ truncated(Normal(0.125 ,0.05), (0.001),(0.5)) - constelab~ truncated(Normal(0.0 ,2.0), (-10.0),(10.0)) - ctrend ~ truncated(Normal(0.4 ,0.10), (0.1) ,(0.8)) - cgy ~ truncated(Normal(0.5 ,0.25), (0.01) ,(2.0)) - calfa ~ truncated(Normal(0.3 ,0.05), (0.01) ,(1.0)) - - parameters[indexin([:csigl],m.parameters)] .= csigl - parameters[indexin([:csadjcost],m.parameters)] .= csadjcost - parameters[indexin([:csigma],m.parameters)] .= csigma - parameters[indexin([:cfc],m.parameters)] .= cfc - parameters[indexin([:crpi],m.parameters)] .= crpi - parameters[indexin([:cry],m.parameters)] .= cry - parameters[indexin([:crdy],m.parameters)] .= crdy - parameters[indexin([:constelab],m.parameters)] .= constelab - parameters[indexin([:ctrend],m.parameters)] .= ctrend - parameters[indexin([:cgy],m.parameters)] .= cgy - parameters[indexin([:calfa],m.parameters)] .= calfa - - - # data likelihood - # Turing.@addlogprob! begin - # try - # calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) - # catch e - # return -Inf - # end - # end - - # println(ForwardDiff.value.(parameters)) - Turing.@addlogprob! calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) - - - # # system prior on IRFs - # Turing.@addlogprob! loglikelihood(Normal(.03, .01), get_irf(parameters,m)[6,4,2]) - - # # system prior on SS and stdev - # moments = get_variances(RBC_estim, parameters) - # Turing.@addlogprob! loglikelihood(Normal(.6, .05), moments[1][1]) - # Turing.@addlogprob! loglikelihood(Normal(.014, .001), moments[2][5]) -end - -observables = Symbol.(names(dat))#[:dinve, :dc] - - -using BenchmarkTools -calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = m.parameter_values) -@benchmark calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = m.parameter_values) - -@profview calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = m.parameter_values) - -using ForwardDiff -ForwardDiff.gradient(x->calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = x), Float64[m.parameter_values...]) -@benchmark ForwardDiff.gradient(x->calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = x), Float64[m.parameter_values...]) samples = 10 seconds = 100 - -@profview ForwardDiff.gradient(x->calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = x), Float64[m.parameter_values...]) - - - -turing_model = kalman(data, m, observables) # passing observables from before - -# sample -n_samples = 1000 -n_adapts = 250 -δ = 0.65 - -chain_1_marginal = sample(turing_model, NUTS(), n_samples; progress = true) -# chain_1_marginal = sample(turing_model, NUTS(), MCMCDistributed(), n_samples, 2; progress = true) # multi-threaded sampling diff --git a/test/estimation_FS2000.jl b/test/estimation_FS2000.jl deleted file mode 100644 index 31f6773c..00000000 --- a/test/estimation_FS2000.jl +++ /dev/null @@ -1,431 +0,0 @@ -import Turing -import Turing: Normal, Beta, Gamma, InverseGamma, Uniform, Poisson, truncated, NUTS, HMC, HMCDA, MH, PG, SMC, IS, sample, mean, var, @logprob_str, logpdf -using MacroModelling, OptimizationNLopt, OptimizationOptimisers -using CSV, DataFrames, AxisKeys - -# load and solve model once -include("models/FS2000.jl") -# m.SS_optimizer = NLopt.LD_TNEWTON_PRECOND_RESTART -# m.SS_optimizer = NLopt.LN_NEWUOA_BOUND # nope -# m.SS_optimizer = NLopt.GD_STOGO# nope -# m.SS_optimizer = NLopt.LN_COBYLA# nope -# m.SS_optimizer = NLopt.LN_COBYLA# nope -# m.SS_optimizer = NLopt.LN_PRAXIS -# m.SS_optimizer = NLopt.LN_NELDERMEAD -# m.SS_optimizer = NLopt.LD_MMA #nope -# m.SS_optimizer = NLopt.LD_SLSQP -# m.SS_optimizer = NLopt.LD_VAR1 -# m.SS_optimizer = Optimisers.ADAM -# m.SS_optimizer = Optimisers.AdaMax -# solve!(m,symbolic_SS = true) -get_SS(m) -get_solution(m) - - -# m.NSSS_solver_cache - -# pars1 = [0.41150191239122613, 0.9961786187508863, 0.0031745098374241546, 1.0119018843241043, 0.8720610472237464, 0.7576218838388646, 0.0003046024734065515, 0.012647803563655321, 0.0031452245745823937]; -# aux_res1 = get_SS(m, parameters = pars1) -# m.NSSS_solver_cache - -# pars2 = [0.4115505276884593, 0.9961610698201956, 0.0031892263438955946, 1.0125501237734196, 0.8723284266761051, 0.7569466782764831, 0.00029867203541913143, 0.012709213813776992, 0.003196765679883496]; -# aux_res2 = get_SS(m, parameters = pars2) - -# # m.NSSS_solver_cache -# get_SS(m,parameters = [0.44728295202065166, 0.9988884445965371, 0.0028058657322557485, 1.0075373840302122, 0.6142408307950538, 0.5318308372997724, 0.0011670521404654407, 0.07535090815216333, 0.012834752100689741]) -# # length(m.NSSS_solver_cache) < 1 -# # # m.SS_solve_func -# # parameters = [0.4035,0.9909, 0.0046, 1.0143, 0.8455, 0.6890, 0.0017, 0.0136, 0.0033] - - -# # findmin([sum(abs2,pars[end] - parameters) for pars in m.NSSS_solver_cache])[2] -# # findmin([sum(abs2,pars[end] ./ parameters .- 1) for pars in m.NSSS_solver_cache])[2] - -# get_SS(m,parameters = [0.6750005457453657, 0.7705742051621937, -0.13003647764699267, 0.6057594085497515, 0.7171103532068533, 0.7901279425902789, 0.5380666025781062, 0.2961217015642633, 4.264173335281647]) -# # get_SS(m,parameters = [0.6695526157125993, 0.7782097900770949, 1.399954432139673, 0.9777895536920106, 0.7173213885987454, 0.7899294918080639, 0.5385159934129353, 0.29591747435564625, 4.253028889230297]) -# # # get_SS(m,parameters = ([0.6585547093545611, 0.797796110027983, -27.99086509624363, 1.7260870685765246, 0.7176543116605183, 0.7893164495740828, 0.5286306119368696, 0.2900532604080456, 4.158761080384637] .+ [0.6695526157125993, 0.7782097900770949, 1.399954432139673, 0.9777895536920106, 0.7173213885987454, 0.7899294918080639, 0.5385159934129353, 0.29591747435564625, 4.253028889230297])/2) -# get_SS(m,parameters = [0.6585547093545611, 0.797796110027983, -27.99086509624363, 1.7260870685765246, 0.7176543116605183, 0.7893164495740828, 0.5286306119368696, 0.2900532604080456, 4.158761080384637]) - -# old = [0.6695526157125993, 0.7782097900770949, 1.399954432139673, 0.9777895536920106, 0.7173213885987454, 0.7899294918080639, 0.5385159934129353, 0.29591747435564625, 4.253028889230297] -# new = [0.6585547093545611, 0.797796110027983, -27.99086509624363, 1.7260870685765246, 0.7176543116605183, 0.7893164495740828, 0.5286306119368696, 0.2900532604080456, 4.158761080384637] -# x = .918 -# get_SS(m,parameters = x * old + (1-x) * new) - - - - - -# get_SS(m,parameters = [0.17276964952137486, 0.7920896296538025, -0.8033846461311837, 0.8677000303674002, 0.16328753269059, 0.8373335368867071, 0.7368146848615, 1.0262811493098323, 0.17124795333976325]) - -# old = [0.17276964952137486, 0.7920896296538025, -0.8033846461311837, 0.8677000303674002, 0.16328753269059, 0.8373335368867071, 0.7368146848615, 1.0262811493098323, 0.17124795333976325] -# new = [0.42765909391665374, 0.9907036907663795, 2.1176282461553012e76, 1.1960317010498268e10, 0.16585006558379037, 0.8188150453606395, 0.15798111883923274, 0.39220085985173697, 0.0752297106516448] -# x = .999 -# get_SS(m,parameters = x * old + (1-x) * new) - - -# get_SS(m,parameters = [0.4506243383700943, 0.8339225002267898, 0.1800531394330218, 1.051725550641863, 0.7507896555638963, 0.195768694997821, 0.22133536264548384, 2.821842569292302, 0.19527805437581103]) - -# ([0.6585547093545611, 0.797796110027983, -27.99086509624363, 1.7260870685765246, 0.7176543116605183, 0.7893164495740828, 0.5286306119368696, 0.2900532604080456, 4.158761080384637] .+ [0.6695526157125993, 0.7782097900770949, 1.399954432139673, 0.9777895536920106, 0.7173213885987454, 0.7899294918080639, 0.5385159934129353, 0.29591747435564625, 4.253028889230297])/2 - - - -parameters = deepcopy(m.parameter_values) - -# load data -dat = CSV.read("test/FS2000_data.csv",DataFrame) -# data = KeyedArray(Array(dat)',Variable = Symbol.(names(dat)),Time = 1:size(dat)[1]) -data = KeyedArray(Array(dat)',Variable = Symbol.("log_".*names(dat)),Time = 1:size(dat)[1]) -data = log.(data) - -# declare observables -# observables = Symbol.(names(dat))#[:dinve, :dc] -observables = sort(Symbol.("log_".*names(dat)))#[:dinve, :dc] - -data = data(observables,:) - -# calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) -# calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = [0.4035, 0.9909, 0.0046, 1.0143, 0.8455, 0.6891, 0.0017, 0.0136, 0.0033]) -# calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = [0.7, 0.9999, 0.0046, 1.0143, 0.8455, 0.6891, 0.0017, 0.0136, 0.0033]) - -# using ForwardDiff -# ForwardDiff.gradient(x -> calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = x),[0.7, 0.9999, 0.0046, 1.0143, 0.8455, 0.6891, 0.0017, 0.0136, 0.0033]) - - -# functions to map mean and standard deviations to distribution parameters -function beta_map(μ, σ) - α = ((1 - μ) / σ ^ 2 - 1 / μ) * μ ^ 2 - β = α * (1 / μ - 1) - return α, β -end - -function inv_gamma_map(μ, σ) - α = (μ / σ) ^ 2 + 2 - β = μ * ((μ / σ) ^ 2 + 1) - return α, β -end - -function gamma_map(μ, σ) - k = μ^2/σ^2 - θ = σ^2 / μ - return k, θ -end - -# test functions -# Gamma(gamma_map(.5,.2)...)|>mean -# Gamma(gamma_map(.5,.2)...)|>var|>sqrt - -# InverseGamma(inv_gamma_map(.1,2)...)|>mean -# InverseGamma(inv_gamma_map(.1,2)...)|>var|>sqrt - -# Beta(beta_map(0.356, 0.02)...)|>mean -# Beta(beta_map(0.356, 0.02)...)|>var|>sqrt - -# Normal(0.0085, 0.003)|>mean -# Normal(0.0085, 0.003)|>var|>sqrt - - -# calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) - -# @profview calculate_kalman_filter_loglikelihood(m, data(observables,1:10), observables; parameters = parameters) -# @time calculate_kalman_filter_loglikelihood(m, data(observables,1:10), observables; parameters = parameters) -# using ForwardDiff -#find mode -function calculate_posterior_loglikelihood(parameters, u) - # println(ForwardDiff.value.(parameters)) - alp, bet, gam, mst, rho, psi, del, z_e_a, z_e_m = parameters - log_lik = 0 - log_lik -= calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) - log_lik -= logpdf(Beta(beta_map(0.356, 0.02)...),min(1,max(0,alp))) - log_lik -= logpdf(Beta(beta_map(0.993, 0.002)...),min(1,max(0,bet))) - log_lik -= logpdf(Normal(0.0085, 0.003),gam) - log_lik -= logpdf(Normal(1.0002, 0.007),mst) - log_lik -= logpdf(Beta(beta_map(0.129, 0.223)...),min(1,max(0,rho))) - log_lik -= logpdf(Beta(beta_map(0.65, 0.05)...),min(1,max(0,psi))) - log_lik -= logpdf(Beta(beta_map(0.01, 0.005)...),min(1,max(0,del))) - log_lik -= logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...),max(0,z_e_a)) - log_lik -= logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...),max(0,z_e_m)) - return log_lik -end - -# using BenchmarkTools -# @benchmark find_mode(parameters, []) -# @profview find_mode(parameters, []) -# find_mode([0.4035,0.9909, 0.0046, 1.0143, 0.8455, 0.6890, 0.0017, 0.0136, 0.0033],[]) -using OptimizationNLopt -using OptimizationOptimisers - -# parameters = [0.6750005457453657, 0.7705742051621937, -0.13003647764699267, 0.6057594085497515, 0.7171103532068533, 0.7901279425902789, 0.5380666025781062, 0.2961217015642633, 4.264173335281647] -# parameters = [0.4035,0.9909, 0.0046, 1.0143, 0.8455, 0.6890, 0.0017, 0.0136, 0.0033] - -# lbs = [.0001,.5,eps(),.5,.0001,.0001,.0001,.000001,.000001] -# ubs = [.6,.999,.5,1.5,.95,.999,.1,1,1] - - -lbs = [eps(), eps(), -1e12, -1e12, eps(), eps(), eps(), eps(), eps()] -ubs = [1-eps(), 1-eps(), 1e12, 1e12, 1-eps(), 1-eps(), 1-eps(), 1e12, 1e12] - -f = OptimizationFunction(calculate_posterior_loglikelihood, Optimization.AutoForwardDiff()) - -prob = OptimizationProblem(f, Float64[parameters...], [])#, lb = lbs, ub = ubs) -# prob = OptimizationProblem(f, sol_new.u, [])#, lb = lbs, ub = ubs) -sol = solve(prob, Optimisers.ADAM(), maxiters = 1000, progress = true) -sol.minimum -# m.NSSS_solver_cache - -prob = OptimizationProblem(f, min.(max.(sol.u,lbs),ubs), [], lb = lbs, ub = ubs) -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -sol_new = solve(prob, NLopt.LD_LBFGS()) -sol_new.minimum - -parameters = sol_new.u - -using ForwardDiff -hessian_at_posterior_mode = ForwardDiff.hessian(x->calculate_posterior_loglikelihood(x,[]),parameters) -# using BenchmarkTools -# @benchmark calculate_posterior_loglikelihood(parameters * exp(randn()/1e3), []) -# sol_new = solve(prob, NLopt.G_MLSL_LDS(), local_method = NLopt.LN_BOBYQA(), population = length(ubs), local_maxtime = 120, maxtime = 120, progress = true) - -# prob = OptimizationProblem(f, Float64[parameters...], [])#, lb = lbs, ub = ubs) -# sol_new = solve(prob, Optimisers.ADAM(), maxiters = 1000, progress = true) - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.LN_BOBYQA(), maxiters = 100000, maxtime = 100, local_maxtime = 100) -# sol.minimum - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.LN_COBYLA(), maxiters = 100000, maxtime = 100, local_maxtime = 100) -# sol.minimum - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.LN_NELDERMEAD(), maxiters = 100000, maxtime = 100, local_maxtime = 100) -# sol.minimum - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.LD_TNEWTON_PRECOND_RESTART(), maxiters = 100000, maxtime = 100, local_maxtime = 100) - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.GD_STOGO_RAND(), maxiters = 100000, maxtime = 10, local_maxtime = 10) - -# prob = OptimizationProblem(f, Float64[parameters...], [], lb = lbs, ub = ubs) -# sol = solve(prob, NLopt.GN_AGS(), maxiters = 100000, maxtime = 10, local_maxtime = 10) - -# prob = OptimizationProblem(f, Float64[parameters...], [])#, lb = fill(eps(),9), ub = [1,1,1,2,1,1,1,10,10]) -# sol = solve(prob, Optimisers.AdaMax(), maxiters = 10000) - - -# lbs = [.2,.5,eps(),.5,.0001,.0001,.0001,.000001,.000001] -# ubs = [.5,.999,.5,1.5,.95,.999,.1,1,1] - -# using ForwardDiff -# define priors and likelihood -Turing.@model function kalman(data, m, observables) - # parameters = deepcopy(m.parameter_values) - alp ~ Beta(beta_map(0.356, 0.02)...) - bet ~ Beta(beta_map(0.993, 0.002)...) - gam ~ Normal(0.0085, 0.003)#, eps(), .1) - mst ~ Normal(1.0002, 0.007) - rho ~ Beta(beta_map(0.129, 0.223)...) - psi ~ Beta(beta_map(0.65, 0.05)...) - del ~ Beta(beta_map(0.01, 0.005)...) - z_e_a ~ InverseGamma(inv_gamma_map(0.035449, Inf)...) - z_e_m ~ InverseGamma(inv_gamma_map(0.008862, Inf)...) - - # alp ~ truncated(Beta(beta_map(0.356, 0.02)...), eps(), .6) - # bet ~ truncated(Beta(beta_map(0.993, 0.002)...),eps(), .999) - # gam ~ Normal(0.0085, 0.003)#, eps(), .1) - # mst ~ truncated(Normal(1.0002, 0.007), .5, 1.5) - # rho ~ Beta(beta_map(0.129, 0.223)...) - # psi ~ Beta(beta_map(0.65, 0.05)...) - # del ~ Beta(beta_map(0.01, 0.005)...) - # z_e_a ~ truncated(InverseGamma(inv_gamma_map(0.035449, Inf)...), eps(), 1.5) - # z_e_m ~ truncated(InverseGamma(inv_gamma_map(0.008862, Inf)...), eps(), 1.5) - # z_e_a ~ Uniform(eps(),2) - # z_e_m ~ Uniform(eps(),2) - - parameters[indexin([:alp, :bet, :rho, :psi, :del, :gam, :mst, :z_e_a, :z_e_m],m.parameters)] .= [alp, bet, rho, psi, del, gam, mst, z_e_a, z_e_m] - # parameters[indexin([:bet],m.parameters)] .= bet - # parameters[indexin([:rho],m.parameters)] .= rho - # parameters[indexin([:psi],m.parameters)] .= psi - # parameters[indexin([:del],m.parameters)] .= del - # parameters[indexin([:gam],m.parameters)] .= gam - # parameters[indexin([:mst],m.parameters)] .= mst - # parameters[indexin([:z_e_a],m.parameters)] .= z_e_a - # parameters[indexin([:z_e_m],m.parameters)] .= z_e_m - - # println(ForwardDiff.value.(parameters)) - data_log_lik = calculate_kalman_filter_loglikelihood(m, data(observables), observables; parameters = parameters) - # println(ForwardDiff.value.(data_log_lik)) - # println(data_log_lik) - # data likelihood - Turing.@addlogprob! data_log_lik - - Turing.@addlogprob! logpdf(Beta(beta_map(0.356, 0.02)...),alp) - Turing.@addlogprob! logpdf(Beta(beta_map(0.993, 0.002)...),bet) - Turing.@addlogprob! logpdf(Beta(beta_map(0.129, 0.223)...),rho) - Turing.@addlogprob! logpdf(Beta(beta_map(0.65, 0.05)...),psi) - Turing.@addlogprob! logpdf(Beta(beta_map(0.01, 0.005)...),del) - Turing.@addlogprob! logpdf(Normal(0.0085, 0.003),gam) - Turing.@addlogprob! logpdf(Normal(1.0002, 0.007),mst) - Turing.@addlogprob! logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...),z_e_a) - Turing.@addlogprob! logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...),z_e_m) - # # system prior on IRFs - # Turing.@addlogprob! loglikelihood(Normal(.03, .01), get_irf(parameters,m)[6,4,2]) - - # # system prior on SS and stdev - # moments = get_variances(RBC_estim, parameters) - # Turing.@addlogprob! loglikelihood(Normal(.6, .05), moments[1][1]) - # Turing.@addlogprob! loglikelihood(Normal(.014, .001), moments[2][5]) -end - -# get_SS(m,parameters = [.495,.99765,.0015,1.0043,.59,.509,.0075,.0789,.013]) -# m.solution.non_stochastic_steady_state - -# logpdf(InverseGamma(inv_gamma_map(0.035449, Inf)...),0.035449) -# logpdf(InverseGamma(inv_gamma_map(0.008862, Inf)...),0.008862) -# # ldens(idx) = log(2) - gammaln(.5*nu(idx)) - .5*nu(idx).*(log(2)-log(s(idx))) - (nu(idx)+1).*log(x(idx)) - .5*s(idx)./(x(idx).*x(idx)) ; -# # nu = 2 -# logpdf(Normal(1.0002, 0.007),1.0002) -# logpdf(Normal(0.0085, 0.003),0.0085) - - -# logpdf(Beta(beta_map(0.356, 0.02)...), 0.356) -# logpdf(Beta(beta_map(0.993, 0.002)...), 0.993) -# logpdf(Beta(beta_map(0.129, 0.223)...), 0.129) -# logpdf(Beta(beta_map(0.65, 0.05)...), 0.65) -# logpdf(Beta(beta_map(0.01, 0.005)...), 0.01) - - - -turing_model = kalman(data, m, observables) # passing observables from before - -# logprob"data = data, observables = observables, m = m | model = turing_model, alp = 0.356, bet = 0.993, gam = 0.0085, mst = 1.0002, rho = 0.129, psi = 0.65, del = 0.01, z_e_a = 0.035449, z_e_m = 0.008862" -# pars = [0.5999999999999941, 0.999, 0.00022410786148670898, 1.5, 0.2918845841974984, 0.0023597321974304225, 0.0036122338038623494, 9.667230108300879e-16, 6.186816831182828e-7] -# pars1 = [0.4057990671188101, 0.9939453787866409, 2.684106868506867e-6, 1.0102466111491866, 0.9260781713903609, 0.6255494229713717, 0.0007961626163605908, 0.014329941996977557, 0.0032669429428229045] -# aux_res = get_SS(m, parameters = pars1) -# pars2 = [0.4060354127026275, 0.9939696880461915, 2.676217146735149e-6, 1.0099951272753809, 0.9256873341280071, 0.6276800066680917, 0.0007881343164889416, 0.014477030943022696, 0.0032982783449941383] -# get_SS(m, parameters = pars2) - -# sum(abs2,pars1 - pars2) -# aux_res[:,2:end] * (pars1 - pars2) + aux_res[:,1] - - - - - - -# include("models/FS2000.jl") -# get_SS(m) -# m.NSSS_solver_cache - -# pars1 = [0.41150191239122613, 0.9961786187508863, 0.0031745098374241546, 1.0119018843241043, 0.8720610472237464, 0.7576218838388646, 0.0003046024734065515, 0.012647803563655321, 0.0031452245745823937]; -# aux_res = get_SS(m, parameters = pars1) -# m.NSSS_solver_cache - -# pars2 = [0.4115505276884593, 0.9961610698201956, 0.0031892263438955946, 1.0125501237734196, 0.8723284266761051, 0.7569466782764831, 0.00029867203541913143, 0.012709213813776992, 0.003196765679883496]; -# # push!(m.NSSS_solver_cache,[collect((aux_res[:,2:end] * (pars2-pars1) + aux_res[:,1])([:P,:c,:k,:l,:n])),pars1]) -# sum(abs2,pars1 - (pars1*31/32+pars2*1/32)) - - -# x = .25 -# aux_res2 = get_SS(m, parameters = x * pars2 + (1-x)*pars1) -# x = .5 -# aux_res2 = get_SS(m, parameters = x * pars2 + (1-x)*pars1) -# x = .75 -# aux_res2 = get_SS(m, parameters = x * pars2 + (1-x)*pars1) - - -# aux_res2 = get_SS(m, parameters = pars2) - - - - -# pars1 = [0.4090531876949292, 0.9922026277043132, 3.7270004959805524e-11, 0.9854252206393719, 0.8926246975110997, 0.42404142756503127, 0.0310239576746275, 1.1347210157951444, 0.034292863714027705] -# aux_res = get_SS(m, parameters = pars1) - -# pars2 = [0.43805847862197406, 0.9870471979008302, 4.6187033193934515e-11, 1.5, 0.9985956426786606, 0.9989980021158512, 0.02604273081193925, 2.802946371762405e-9, 2.220446049250313e-16] -# aux_res = get_SS(m, parameters = pars2) - - -# parameters -# pars2 = [ 0.356 -# 0.993 -# 0.0085 -# 1.0002 -# 0.129 -# 0.99355 -# 0.01 -# 0.035449 -# 0.008862] - -# # pars2 = [0.4090531876949292, 0.9922026277043132, 3.7270004959805524e-11, 1.5, 0.9985956426786606, 0.985, 0.0310239576746275, 1.1347210157951444, 0.034292863714027705] -# aux_res = get_SS(m, parameters = pars2) - - - -# pars = [0.61, 0.999, 2.676217146735149e-3*2.5, 1.0099951272753809, 0.9256873341280071, 0.6276800066680917, 0.0007896, 0.014329941996977557, 0.0032669429428229045] -# # pars = [0.5, 0.999, 0.00019596038697428447, 0.5, 0.9613020894154952, 0.21357589547162303, 0.0003397291645318067, 7.751707376780153e-9, 1.8728386399634146e-11] -# pars = [0.5999999999922886, 0.9989999999999681, 1.4297470897549595e-8, 1.5, 0.9, 0.9, 1.1786838316189486e-22, 2.220446049250313e-16, 1.4089183824793878e-11] -# get_SS(m, parameters = pars) -# m.parameter_values -# m.NSSS_solver_cache -# get_SS(m, parameters = (:del => 0.0007896, :alp => .41, :gam => 1e-6, :rho => .926, :psi => .627)) -# x = .04 -# get_SS(m, parameters = pars * x + m.NSSS_solver_cache[100][2] * (1 - x)) -# findmin([sum(abs2,i[2]- pars) for i in m.NSSS_solver_cache]) -using LinearAlgebra -inv_hess = Hermitian(inv(hessian_at_posterior_mode)) - -# sample -n_samples = 1000 -# chain_NUTS = sample(turing_model, NUTS(1000, .65, max_depth = 10, Δ_max = 400.0, init_ϵ = .02), n_samples; θ = sol.u, progress = true) -chain_NUTS = sample(turing_model, NUTS(), n_samples; θ = parameters, progress = true) -chain_HMC = sample(turing_model, HMC(.05,10), n_samples; θ = parameters, progress = true) -chain_HMCDA = sample(turing_model, HMCDA(2000, 0.65, .02), n_samples; θ = sol.u, progress = true) -# chain_PG = sample(turing_model, PG(20), n_samples; θ = sol.u, progress = true) -chain_MH = sample(turing_model, MH(inv_hess), Int(1e5); θ = parameters, progress = true) - -using AdaptiveMCMC -chain_MH = adaptive_rwm(parameters,x->calculate_posterior_loglikelihood(x,[]),Int(1e2)) - -# chain_MH = sample(turing_model, SMC(), Int(1e5); θ = sol.u, progress = true) - - -using MCMCChains, MCMCDiagnosticTools, StatsPlots -StatsPlots.plot(chain_NUTS) -ess_rhat(chain_NUTS) -autocor(chain_NUTS) -bfmi(chain_NUTS[:hamiltonian_energy]) -# gelmandiag(chain_NUTS) -# gelmandiag_multivariate(chain_NUTS) -geweke = gewekediag(chain_NUTS) -heidel = heideldiag(chain_NUTS) -raftery = rafterydiag(chain_NUTS) - - -StatsPlots.plot(chain_MH) -ess_rhat(chain_MH) -autocor(chain_MH) -# bfmi(chain_MH[:hamiltonian_energy]) -# gelmandiag(chain_MH) -# gelmandiag_multivariate(chain_MH) -geweke = gewekediag(chain_MH) -heidel = heideldiag(chain_MH) -raftery = rafterydiag(chain_MH) - - - -m.NSSS_solver_cache - - - - - -m.SS_init_guess -get_SS(m,parameters = [0.4462257879893407, 0.9988469595418614, 0.0037864220598411366, 1.008999298796174, 0.6052810770277287, 0.5360474465184352, 0.0015706409192591743, 0.07484474682965438, 0.012156383477978388]) - -get_SS(m,parameters = [0.447388317851787, 0.9988884614609232, 0.002725486533226825, 1.0084286121820523, 0.6187187429894266, 0.5315973807951158, 0.0011616665715356112, 0.07715423484471479, 0.012839096692139697]) - -get_SS(m,parameters = [0.33, 0.9988884445965371, 0.0028058657322557485, 1.0075373840302122, 0.6142408307950538, 0.5318308372997724, 0.0011670521404654407, 0.07535090815216333, 0.012834752100689741]) - -get_SS(m,parameters = [0.44728295202065166, 0.9988884445965371, 0.0028058657322557485, 1.0075373840302122, 0.6142408307950538, 0.5318308372997724, 0.0011670521404654407, 0.07535090815216333, 0.012834752100689741]) diff --git a/test/investment_model.jl b/test/investment_model.jl deleted file mode 100644 index 81a229a5..00000000 --- a/test/investment_model.jl +++ /dev/null @@ -1,482 +0,0 @@ -using MacroModelling, BlockTriangularForm, SparseArrays - - -@model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - c_normcdf[0]= normcdf(c[0]) - c_normpdf[0]= normpdf(c[0]) - c_norminvcdf[0]= norminvcdf(c[0]-1) - c_norminv[0]= norminv(c[0]-1) - c_qnorm[0]= qnorm(c[0]-1) - c_dnorm[0]= dnorm(c[0]) - c_pnorm[0]= pnorm(c[0]) - c_normlogpdf[0]= normlogpdf(c[0]) - # c_norm[0]= cdf(Normal(),c[0]) - c_inv[0] = erfcinv(c[0]) - # c_binomlogpdf[0]= binomlogpdf(c[0]) - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] -end - - -@parameters RBC_CME begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - - beta | R[ss] = R_ss - R_ss = 1.0035 - # beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - Pibar | Pi[ss] = Pi_ss - Pi_ss = R_ss - Pi_real - Pi_real = .001 - # Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = rho_z_delta - std_eps = .0068 - rho_z_delta = 9 / 10 - std_z_delta = .005 -end - -get_moments(RBC_CME) - - - - - -𝓂 = RBC_CME -parameters = 𝓂.parameter_values - -cap_share = parameters[1] -R_ss = parameters[2] -delta = parameters[3] -phi_pi = parameters[5] -#= /Users/thorekockerols/GitHub/MacroModelling.jl/src/MacroModelling.jl:516 =# -R = R_ss -Pi = Pi_ss -beta = Pi / R -A = 1 -lbs = [-1.0e12, 2.220446049250313e-16, -1.0e12] -ubs = [1.0e12, 1.0e12, 1.0e12] -𝓂.SS_init_guess = initial_guess -f = OptimizationFunction(𝓂.ss_solve_blocks_optim[1], Optimization.AutoForwardDiff()) -inits = max.(lbs, min.(ubs, 𝓂.SS_init_guess[[17, 14, 15]])) -sol = block_solver([cap_share, delta, beta], 1, 𝓂.ss_solve_blocks[1], 𝓂.SS_optimizer, f, inits, lbs, ubs) - -RBC_CME.calibration_equations -RBC_CME.calibration_equations_no_var -RBC_CME.parameters -RBC_CME.parameter_values -RBC_CME.calibration_equations_no_var - -RBC_CME.ss_no_var_calib_list -RBC_CME.par_no_var_calib_list - - -import MacroTools: postwalk, unblock - - -ex = :(begin - alpha | k[ss] / (4 * y[ss]) = cap_share - omega = 1 / 6 - Pibar = 1.01 - nu = .36 - kappa = (Pi_ss / R_ss) ^ 2 - R_ss = omega / 2 * Pibar - Pi_ss = R_ss ^ nu - alpha = 1 / 3 - beta = .999 -end) - -dump(ex) - - - -calib_equations = [] -calib_equations_no_var = [] -calib_values_no_var = [] - -calib_parameters_no_var = [] - - -calib_eq_parameters = [] -calib_equations_list = [] - -ss_calib_list = [] -par_calib_list = [] - - -calib_equations_no_var_list = [] - -ss_no_var_calib_list = [] -par_no_var_calib_list = [] - -calib_parameters = [] -calib_values = [] - - -bounds = [] - -# label all variables parameters and exogenous vairables and timings across all equations -postwalk(x -> - x isa Expr ? - x.head == :(=) ? - x.args[1] isa Symbol ? - typeof(x.args[2]) ∈ [Int, Float64] ? - begin # this is normal calibration by setting values of parameters - push!(calib_values,x.args[2]) - push!(calib_parameters,x.args[1]) - end : - begin # this is normal calibration by setting values of parameters - # push!(calib_equations_no_var,Expr(:(=),x.args[1], unblock(x.args[2]))) - push!(calib_values_no_var,unblock(x.args[2])) - push!(calib_parameters_no_var,x.args[1]) - end : - begin # this is calibration by targeting SS values - push!(calib_eq_parameters,x.args[1].args[2]) - push!(calib_equations,Expr(:(=),x.args[1].args[3], unblock(x.args[2]))) - end : - x.head == :comparison ? - push!(bounds,x) : - x.head == :call ? - issubset([x.args[1]], [:(<) :(>) :(<=) :(>=)]) ? - push!(bounds,x) : - x : - x : - x, -ex) - - -for (i, v) in enumerate(calib_values_no_var) - out = try eval(v) catch e end - if out isa Float64 - push!(calib_parameters, calib_parameters_no_var[i]) - push!(calib_values, out) - else - push!(calib_equations_no_var, Expr(:(=),calib_parameters_no_var[i], calib_values_no_var[i])) - end -end - -calib_parameters_no_var = setdiff(calib_parameters_no_var,calib_parameters) - -for (i, cal_eq) in enumerate(calib_equations) - ss_tmp = Set() - par_tmp = Set() - - # parse SS variables - postwalk(x -> - x isa Expr ? - x.head == :ref ? - occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? - push!(ss_tmp,x.args[1]) : - x : - x : - x, - cal_eq) - - # get SS variables per non_linear_solved_vals - postwalk(x -> - x isa Symbol ? - occursin(r"^(\+|\-|\*|\/|\^|ss|stst|steady|steadystate|steady_state){1}$"i,string(x)) ? - x : - begin - diffed = setdiff([x],ss_tmp) - if !isempty(diffed) - push!(par_tmp,diffed[1]) - end - end : - x, - cal_eq) - - push!(ss_calib_list,ss_tmp) - push!(par_calib_list,par_tmp) - - # write down calibration equations - prs_ex = postwalk(x -> - x isa Expr ? - x.head == :(=) ? - Expr(:call,:(-),x.args[1],x.args[2]) : #convert = to - - x.head == :ref ? - occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? - x.args[1] : - x : - x.head == :call ? - x.args[1] == :* ? - x.args[2] isa Int ? - x.args[3] isa Int ? - x : - :($(x.args[3]) * $(x.args[2])) : - x : - x : - unblock(x) : - x, - cal_eq) - push!(calib_equations_list,unblock(prs_ex)) -end - - -for (i, cal_eq) in enumerate(calib_equations_no_var) - ss_tmp = Set() - par_tmp = Set() - - # parse SS variables - postwalk(x -> - x isa Expr ? - x.head == :ref ? - occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? - push!(ss_tmp,x.args[1]) : - x : - x : - x, - cal_eq) - - # get SS variables per non_linear_solved_vals - postwalk(x -> - x isa Symbol ? - occursin(r"^(\+|\-|\*|\/|\^|ss|stst|steady|steadystate|steady_state){1}$"i,string(x)) ? - x : - begin - diffed = setdiff([x],ss_tmp) - if !isempty(diffed) - push!(par_tmp,diffed[1]) - end - end : - x, - cal_eq) - - push!(ss_no_var_calib_list,ss_tmp) - push!(par_no_var_calib_list,setdiff(par_tmp,calib_parameters)) - - # write down calibration equations - prs_ex = postwalk(x -> - x isa Expr ? - # x.head == :(=) ? - # Expr(:call,:(-),x.args[1],x.args[2]) : #convert = to - - x.head == :ref ? - occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? - x.args[1] : - x : - # x : - x.head == :call ? - x.args[1] == :* ? - x.args[2] isa Int ? - x.args[3] isa Int ? - x : - :($(x.args[3]) * $(x.args[2])) : - x : - x : - unblock(x) : - x, - cal_eq) - push!(calib_equations_no_var_list,unblock(prs_ex)) -end - - - - -incidence_matrix = fill(0,length(calib_parameters_no_var),length(calib_parameters_no_var)) - -for i in 1:length(calib_parameters_no_var) - for k in 1:length(calib_parameters_no_var) - incidence_matrix[i,k] = collect(calib_parameters_no_var)[i] ∈ collect(par_no_var_calib_list)[k] - end -end - -Q, P, R, nmatch, n_blocks = BlockTriangularForm.order(sparse(incidence_matrix)) - -@assert length(Q) == n_blocks "Check the parameter definitions. They are either incomplete or have more than only the defined parameter on the LHS." - -calib_equations_no_var_list = calib_equations_no_var_list[Q] - - - - -calib_values_no_var[2] |> eval - - - - - -nnaux = [:(nonnegativity_auxilliary₃₁ = max(eps(), -((C * h - C)))), -:(nonnegativity_auxilliary₂₄ = max(eps(), -((C * h - C)))), -:(nonnegativity_auxilliary₃ = max(eps(), -(-K * z))), -:(nonnegativity_auxilliary₂₀ = max(eps(), -(-K * z))), -:(nonnegativity_auxilliary₁ = max(eps(), -((C * h - C)))), -:(nonnegativity_auxilliary₂₅ = max(eps(), w_star / W)), -:(nonnegativity_auxilliary₅₂ = max(eps(), -((C * h - C)))), -:(nonnegativity_auxilliary₃₉ = max(eps(), -((C * h - C)))), -:(nonnegativity_auxilliary₉ = max(eps(), -(-K * z))), -:(nonnegativity_auxilliary₂₉ = max(eps(), -(-L / nonnegativity_auxilliary₂₈ ^ ((lambda_w + 1) / lambda_w)))), -:(nonnegativity_auxilliary₂₈ = max(eps(), w_star / W)), -:(nonnegativity_auxilliary₃₃ = max(eps(), -((C * h - C))))] - - -import MacroTools: postwalk -using BlockTriangularForm, SparseArrays - -function get_symbols(ex) - list = Set() - postwalk(x -> x isa Symbol ? push!(list, x) : x, ex) - return list -end - -nn_symbols = map(x->intersect(SW03.nonnegativity_auxilliary_vars,x),get_ex_symbols.(nnaux)) - -all_symbols = reduce(vcat,nn_symbols) |> Set - - -incidence_matrix = fill(0,length(all_symbols),length(all_symbols)) - - -for i in 1:length(all_symbols) - for k in 1:length(all_symbols) - incidence_matrix[i,k] = collect(all_symbols)[i] ∈ collect(nn_symbols)[k] - end -end - -Q, P, R, nmatch, n_blocks = BlockTriangularForm.order(sparse(incidence_matrix)) - -nnaux = nnaux[Q] - - -using MacroModelling; - -@model m begin - K[0] = (1 - δ) * K[-1] + I[0] - Z[0] = (1 - ρ) * μ + ρ * Z[-1] + eps_z[x] - I[1] = ((ρ + δ - Z[0])/(1 - δ)) + ((1 + ρ)/(1 - δ)) * I[0] -end - -@parameters m begin - ρ = 0.05 - δ = 0.10 - μ = .17 - σ = .2 -end - -get_solution(m) - -range(-.5*(1+1/3),(1+1/3)*.5,100) -m.solution.perturbation.first_order.solution_matrix -pol = [[i,m.solution.perturbation.first_order.state_update([0,0.0,i],[0.0])[1]] for i in range(-.05*(1+1/3),(1+1/3)*.05,100)] -solve!(m,algorithm = :second_order, dynamics= true) -using Plots - -pol2 = [[i,m.solution.perturbation.second_order.state_update([0,0.0,i],[0.0])[1]] for i in range(-.05*(1+1/3),(1+1/3)*.05,100)] - -Plots.plot(reduce(hcat,pol)[1,:],reduce(hcat,pol)[2,:]) -Plots.plot!(reduce(hcat,pol2)[1,:],reduce(hcat,pol2)[2,:]) - -@testset "Model without shocks" begin - @model m begin - K[0] = (1 - δ) * K[-1] + I[0] - Z[0] = (1 - ρ) * μ + ρ * Z[-1] - I[1] = ((ρ + δ - Z[0])/(1 - δ)) + ((1 + ρ)/(1 - δ)) * I[0] - end - - @parameters m begin - ρ = 0.05 - δ = 0.10 - μ = .17 - σ = .2 - end - - m_ss = get_steady_state(m) - @test isapprox(m_ss(:,:Steady_state),[1/7.5,1/.75,.17],rtol = eps(Float32)) - - m_sol = get_solution(m) - @test isapprox(m_sol(:,:K),[1/.75,.9,.04975124378109454],rtol = eps(Float32)) -end - -get_irf(m, initial_state = init) - -plot_irf(m, initial_state = init, shocks = :none, save_plots = true, save_plots_path = "~/Downloads", save_plots_format = :png) - -plot(m, initial_state = init) -m.timings.nExo - - - - -using MacroModelling; - -@model m begin - Z[0] = (1 - ρ) * μ + ρ * Z[-1] - I[1] = (ρ + δ - Z[0]) / (1 - δ) + (1 + ρ) / (1 - δ) * I[0] -end -# Model: m -# Variables: 2 -# Shocks: 0 -# Parameters: 3 -# Auxiliary variables: 0 - -@parameters m begin - ρ = 0.05 - δ = 0.10 - μ = .17 - σ = .2 -end -m_ss = get_steady_state(m) -# 2-dimensional KeyedArray(NamedDimsArray(...)) with keys: -# ↓ Variables_and_calibrated_parameters ∈ 2-element Vector{Symbol} -# → Steady_state_and_∂steady_state∂parameter ∈ 4-element Vector{Symbol} -# And data, 2×4 Matrix{Float64}: -# (:Steady_state) (:ρ) (:δ) (:μ) -# (:I) 0.133333 -7.55556 -7.55556 6.66667 -# (:Z) 0.17 0.0 0.0 1.0 - -m.SS_solve_func -# RuntimeGeneratedFunction(#=in MacroModelling=#, #=using MacroModelling=#, :((parameters, initial_guess, 𝓂)->begin -# -# -# ρ = parameters[1] -# δ = parameters[2] -# μ = parameters[3] -# -# Z = μ -# I = ((Z - δ) - ρ) / (δ + ρ) -# SS_init_guess = [I, Z] -# 𝓂.SS_init_guess = if typeof(SS_init_guess) == Vector{Float64} -# SS_init_guess -# else -# ℱ.value.(SS_init_guess) -# end -# return ComponentVector([I, Z], Axis([sort(union(𝓂.exo_present, 𝓂.var))..., 𝓂.calibration_equations_parameters...])) -# end)) - -m_sol = get_solution(m) -# 2-dimensional KeyedArray(NamedDimsArray(...)) with keys: -# ↓ Steady_state__States__Shocks ∈ 2-element Vector{Symbol} -# → Variable ∈ 2-element Vector{Symbol} -# And data, 2×2 adjoint(::Matrix{Float64}) with eltype Float64: -# (:I) (:Z) -# (:Steady_state) 0.133333 0.17 -# (:Z₍₋₁₎) 0.0497512 0.05 - -init = m_ss(:,:Steady_state) |> collect -init[2] *= 1.5 -get_irf(m, initial_state = init, shocks = :none) - -plot_irf(m, initial_state = init, shocks = :none) - -# , save_plots = true, save_plots_path = "~/Downloads", save_plots_format = :png) \ No newline at end of file diff --git a/test/macrotoolstest.jl b/test/macrotoolstest.jl deleted file mode 100644 index 2090464d..00000000 --- a/test/macrotoolstest.jl +++ /dev/null @@ -1,269 +0,0 @@ -import MacroTools: postwalk -using MacroTools -using Subscripts - - - -ex = :(begin - R[0] * beta = C[1] / C[0] - C[0] = w[0] * L[0] - B[0] + R[-1] * B[-1] + (1-v) * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) - We - w[0] = C[0] / (1-L[0]) - K[0] = (1-delta) * K[-1] + I[0] - Q[0] = 1 + chi * (I[0] / K[-1] - delta) - Y[0] = (A[0] * K[-1])^alpha * L[0]^(1-alpha) - Rk[-1] = (alpha * Y[0] / K[-1] + Q[0] * (1-delta))/Q[-1] - w[0] = (1-alpha) * Y[0] / L[0] - N[0] = v * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) + We - 0 = (omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] * Q[0] * K[0] / N[0] - (Q[0] * K[0] / N[0] - 1) - 0 = (1 - (omegabar[0] * (1 - F[0]) + G[0])) * Rk[0] / R[0] + (1 - F[0]) / (1 - F[0] - omegabar[0] * mu * (normpdf((log(omegabar[0]) + sigma^2/2) / sigma)/ omegabar[0] / sigma)) * ((omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] - 1) - G[0] = normcdf(((log(omegabar[0])+sigma^2/2)/sigma) - sigma) - F[0] = normcdf((log(omegabar[0])+sigma^2/2)/sigma) - EFP[0] = (mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) - Y[0] + walras[0] = C[0] + I[0] + EFP[0] * (Q[-1] * K[-1] - N[-1]) - B[0] = Q[0] * K[0] - N[0] - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] -end) - -Expr(:call,:log,:K) -dump(:((log(omegabar[0])+sigma^2/2)/sigma)) - -# dump(:((A[0] * K[-1])^alpha * L[0]^(1-alpha))) - -# dump(:(K[-1])) - -# Expr(:ref,:K,-1) - - - - -lower_bounds = [] -upper_bounds = [] -bounded_vars = [] -nonnegativity_aux_vars = [] -ss_and_aux_equations = [] - - -for (i,arg) in enumerate(ex.args) - if isa(arg,Expr) - # find nonegative variables, parameters, or terms - eqs = MacroTools.postwalk(x -> - x isa Expr ? - x.head == :(=) ? - Expr(:call,:(-),x.args[1],x.args[2]) : #convert = to - - x.head == :ref ? - occursin(r"^(x|ex|exo|exogenous){1}"i,string(x.args[2])) ? 0 : # set shocks to zero and remove time scripts - x : - x.head == :call ? - x.args[1] == :* ? - x.args[2] isa Int ? - x.args[3] isa Int ? - x : - :($(x.args[3]) * $(x.args[2])) : - x : - x.args[1] ∈ [:^, :log] ? - x.args[2] isa Symbol ? # nonnegative parameters - begin - if length(intersect(bounded_vars,[x.args[2]])) == 0 - push!(lower_bounds,eps()) - push!(upper_bounds,Inf) - push!(bounded_vars,x.args[2]) - end - x - end : - x.args[2].head == :ref ? - x.args[2].args[1] isa Symbol ? # nonnegative variables - begin - if length(intersect(bounded_vars,[x.args[2].args[1]])) == 0 - push!(lower_bounds,eps()) - push!(upper_bounds,Inf) - push!(bounded_vars,x.args[2].args[1]) - end - x - end : - x : - x.args[2].head == :call ? # nonnegative expressions - begin - push!(lower_bounds,eps()) - push!(upper_bounds,Inf) - push!(bounded_vars,:($(Symbol("nonnegativity_auxilliary" * sub(string(length(nonnegativity_aux_vars)+1)))))) - push!(ss_and_aux_equations, Expr(:call,:-, :($(Expr(:ref,Symbol("nonnegativity_auxilliary" * sub(string(length(nonnegativity_aux_vars)+1))),0))), x.args[2])) # take position of equation in order to get name of vars which are being replaced and substitute accordingly or rewrite to have substitutuion earlier i the code - push!(nonnegativity_aux_vars,Symbol("nonnegativity_auxilliary" * sub(string(length(nonnegativity_aux_vars)+1)))) - :($(Expr(:ref,Symbol("nonnegativity_auxilliary" * sub(string(length(nonnegativity_aux_vars)))),0)) ^ $(x.args[3])) - end : - x : - x : - x : - x, - ex.args[i]) - - push!(ss_and_aux_equations,unblock(eqs)) - end -end - - -ss_aux_equations = [] - -# tag vars and pars in changed SS equations -var_list_aux_SS = [] -ss_list_aux_SS = [] -par_list_aux_SS = [] - -var_future_list_aux_SS = [] -var_present_list_aux_SS = [] -var_past_list_aux_SS = [] - -# # label all variables parameters and exogenous variables and timings for changed SS equations including nonnegativity auxilliary variables -for eq in ss_and_aux_equations - var_tmp = Set() - ss_tmp = Set() - par_tmp = Set() - var_future_tmp = Set() - var_present_tmp = Set() - var_past_tmp = Set() - - # label all variables parameters and exogenous variables and timings for individual equations - postwalk(x -> - x isa Expr ? - x.head == :call ? - for i in 2:length(x.args) - x.args[i] isa Symbol ? - occursin(r"^(ss|stst|steady|steadystate|steady_state|x|ex|exo|exogenous){1}$"i,string(x.args[i])) ? - x : - push!(par_tmp,x.args[i]) : - x - end : - x.head == :ref ? - x.args[2] isa Int ? - x.args[2] == 0 ? - push!(var_present_tmp,x.args[1]) : - x.args[2] > 0 ? - push!(var_future_tmp,x.args[1]) : - x.args[2] < 0 ? - push!(var_past_tmp,x.args[1]) : - x : - occursin(r"^(x|ex|exo|exogenous){1}(?=(\s{1}\-{1}\s{1}\d+$))"i,string(x.args[2])) ? - push!(var_past_tmp,x.args[1]) : - occursin(r"^(x|ex|exo|exogenous){1}(?=(\s{1}\+{1}\s{1}\d+$))"i,string(x.args[2])) ? - push!(var_future_tmp,x.args[1]) : - occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? - push!(ss_tmp,x.args[1]) : - x : - x : - x, - eq) - - var_tmp = union(var_future_tmp,var_present_tmp,var_past_tmp) - - push!(var_list_aux_SS,var_tmp) - push!(ss_list_aux_SS,ss_tmp) - push!(par_list_aux_SS,par_tmp) - push!(var_future_list_aux_SS,var_future_tmp) - push!(var_present_list_aux_SS,var_present_tmp) - push!(var_past_list_aux_SS,var_past_tmp) - - - # write down SS equations including nonnegativity auxilliary variables - prs_ex = postwalk(x -> - x isa Expr ? - x.head == :(=) ? - Expr(:call,:(-),x.args[1],x.args[2]) : #convert = to - - x.head == :ref ? - occursin(r"^(x|ex|exo|exogenous){1}"i,string(x.args[2])) ? 0 : - x.args[1] : - x.head == :call ? - x.args[1] == :* ? - x.args[2] isa Int ? - x.args[3] isa Int ? - x : - :($(x.args[3]) * $(x.args[2])) : - x : - x : - unblock(x) : - x, - eq) - - push!(ss_aux_equations,unblock(prs_ex)) - -end - - - -convert(Expr,ss_aux_equations[1]) - -var_list_aux_SS -ss_list_aux_SS -par_list_aux_SS -var_future_list_aux_SS -var_present_list_aux_SS -var_past_list_aux_SS - - -lower_bounds -upper_bounds -bounded_vars - - - - - - - -using MacroModelling - -@model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - c_normcdf[0]= normcdf(c[0]) - c_normpdf[0]= normpdf(c[0]) - c_norminvcdf[0]= norminvcdf(c[0]-1) - c_norminv[0]= norminv(c[0]-1) - c_qnorm[0]= qnorm(c[0]-1) - c_dnorm[0]= dnorm(c[0]) - c_pnorm[0]= pnorm(c[0]) - c_normlogpdf[0]= normlogpdf(c[0]) - # c_norm[0]= cdf(Normal(),c[0]) - c_inv[0] = erfcinv(c[0]) - # c_binomlogpdf[0]= binomlogpdf(c[0]) - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] -end -RBC_CME.var_present_list_aux_SS -RBC_CME.bounded_vars -RBC_CME.ss_aux_equations - -using SpecialFunctions - -erfcinv(-1) - - - -using AxisKeys -𝓂 = RBC_CME; - - -var = setdiff(𝓂.var,𝓂.nonnegativity_auxilliary_vars) - -KeyedArray([𝓂.solution.non_stochastic_steady_state[[indexin(sort([var; map(x -> Symbol(replace(string(x), r"ᴸ⁽⁻[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾|ᴸ⁽[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => "")), union(𝓂.aux,𝓂.exo_present))]), sort(union(var,𝓂.exo_present)))...]] 𝓂.solution.perturbation.first_order.solution_matrix]'; -Steady_state__States__Shocks = [:Steady_state; map(x->Symbol(string(x) * "₍₋₁₎"),𝓂.timings.past_not_future_and_mixed); map(x->Symbol(string(x) * "₍ₓ₎"),𝓂.exo)], -Variable = sort([var; 𝓂.aux; 𝓂.exo_present])) - - -double_info = intersect(𝓂.bounds⁺,𝓂.bounded_vars) -𝓂.lower_bounds[indexin(double_info,𝓂.bounded_vars)] = max.(eps(),𝓂.lower_bounds[indexin(double_info,𝓂.bounded_vars)]) - -new_info = setdiff(𝓂.bounds⁺,𝓂.bounded_vars) -𝓂.bounded_vars = vcat(𝓂.bounded_vars,new_info) -𝓂.lower_bounds = vcat(𝓂.lower_bounds,fill(eps(),length(new_info))) -𝓂.upper_bounds = vcat(𝓂.upper_bounds,fill(Inf,length(new_info))) \ No newline at end of file diff --git a/test/models/SW07_dynare_output.txt b/test/models/SW07_dynare_output.txt deleted file mode 100644 index ea5a3f1a..00000000 --- a/test/models/SW07_dynare_output.txt +++ /dev/null @@ -1,134 +0,0 @@ - -MODEL SUMMARY - - Number of variables: 40 - Number of stochastic shocks: 7 - Number of state variables: 20 - Number of jumpers: 12 - Number of static variables: 14 - - -MATRIX OF COVARIANCE OF EXOGENOUS SHOCKS -Variables ea eb eg eqs em epinf ew -ea 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -eb 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -eg 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -eqs 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -em 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -epinf 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -ew 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 - -POLICY AND TRANSITION FUNCTIONS - labobs robs pinfobs dy dc dinve dw ewma epinfma zcapf rkf kf pkf cf invef yf labf wf rrf mc zcap rk k pk c inve y lab pinf w r a b g qs ms spinf sw kpf kp -Constant 0 1.154180 0.500000 0.400000 0.400000 0.400000 0.400000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -yf(-1) -0.197453 0.154053 -0.059765 -0.287707 -0.278475 -0.358232 -0.040664 0 0 0 0 0 0 0 0 0 0 0 0 -0.046312 -0.173920 -0.064196 -0.173920 -0.781059 -0.278475 -0.358232 -0.287707 -0.197453 -0.059765 -0.040664 0.154053 0 0 0 0 0 0 0 0 -0.010347 -y(-1) 0.197453 -0.154053 0.059765 -0.712293 0.278475 0.358232 0.040664 0 0 0 0 0 0 0 0 0 0 0 0 0.046312 0.173920 0.064196 0.173920 0.781059 0.278475 0.358232 0.287707 0.197453 0.059765 0.040664 -0.154053 0 0 0 0 0 0 0 0 0.010347 -r(-1) -0.737145 0.575124 -0.223120 -1.074091 -1.039622 -1.337379 -0.151809 0 0 0 0 0 0 0 0 0 0 0 0 -0.172894 -0.649293 -0.239662 -0.649293 -2.915907 -1.039622 -1.337379 -1.074091 -0.737145 -0.223120 -0.151809 0.575124 0 0 0 0 0 0 0 0 -0.038629 -a(-1) -0.915809 -0.159399 -0.144157 0.267480 0.528281 0.336574 0.212057 0 0 0.397495 0.146721 0.397495 1.948964 0.978082 0.610919 0.816324 -0.722214 1.266430 -1.092886 -0.882072 -0.514020 -0.189732 -0.514020 0.240487 0.528281 0.336574 0.267480 -0.915809 -0.144157 0.212057 -0.159399 0.997700 0 0 0 0 0 0 0.017646 0.009722 -b(-1) 1.345793 0.493086 0.141359 1.929612 2.116784 1.800985 0.157980 0 0 0 0 0 0 0 0 0 0 0 3.877796 0.217365 1.098356 0.405417 1.098356 6.814523 2.116784 1.800985 1.929612 1.345793 0.141359 0.157980 0.493086 0 0.579900 0 0 0 0 0 0 0.052020 -g(-1) 0.693793 0.049270 0.020017 0.975226 -0.214801 -0.066332 0.007125 0 0 0.383168 0.141432 0.383168 -0.778068 -0.421525 -0.218293 0.786901 0.569264 -0.044663 0.458276 0.050767 0.511950 0.188967 0.511950 -0.093902 -0.214801 -0.066332 0.975226 0.693793 0.020017 0.007125 0.049270 0 0 0.995700 0 0 0 0 -0.006305 -0.001916 -qs(-1) 0.473669 0.071310 0.072746 0.678744 -0.059939 2.816576 0.054054 0 0 0.214002 0.078991 0.214002 -1.506211 -0.235425 2.395677 0.439490 0.317938 -0.024945 -0.299495 0.075227 0.385449 0.142274 0.385449 -1.160254 -0.059939 2.816576 0.678744 0.473669 0.072746 0.054054 0.071310 0 0 0 0.716500 0 0 0 0.194668 0.206825 -kpf(-1) 0.001394 0.020549 0.002742 0.002293 0.000182 0.007764 0.001282 0 0 -0.769607 -0.284072 0.230393 0.316607 0.134923 0.105724 -0.080518 -0.143386 0.089707 -0.178622 0.001147 0.001955 0.000722 0.001955 -0.006621 0.000182 0.007764 0.002293 0.001394 0.002742 0.001282 0.020549 0 0 0 0 0 0 0 0.974169 0.000224 -kp(-1) -0.199677 -0.048473 -0.024296 -0.181775 0.039217 0.018824 0.004965 0 0 0 0 0 0 0 0 0 0 0 0 -0.073529 -0.872618 -0.322094 0.127382 0.009499 0.039217 0.018824 -0.181775 -0.199677 -0.024296 0.004965 -0.048473 0 0 0 0 0 0 0 0 0.971659 -cf(-1) 0.007729 -0.066075 -0.002205 0.010656 0.015969 -0.000639 -0.000712 0 0 0.137300 0.050679 0.137300 -0.825262 0.482522 -0.181398 0.281968 0.203983 -0.016004 0.515041 -0.000087 0.005125 0.001892 0.005125 0.062373 0.015969 -0.000639 0.010656 0.007729 -0.002205 -0.000712 -0.066075 0 0 0 0 0 0 0 -0.005240 -0.000018 -invef(-1) 0.008502 -0.031146 -0.000588 0.012041 0.014139 0.009073 0.000432 0 0 0.068304 0.025212 0.068304 -0.435113 -0.075141 0.764638 0.140274 0.101477 -0.007962 0.179956 0.000907 0.006525 0.002409 0.006525 0.049156 0.014139 0.009073 0.012041 0.008502 -0.000588 0.000432 -0.031146 0 0 0 0 0 0 0 0.022086 0.000262 -c(-1) 0.322930 0.112406 0.011111 0.455950 -0.321980 -0.039840 0.011019 0 0 0 0 0 0 0 0 0 0 0 0 0.029983 0.243916 0.090033 0.243916 -0.180183 0.678020 -0.039840 0.455950 0.322930 0.011111 0.011019 0.112406 0 0 0 0 0 0 0 0 -0.001151 -inve(-1) 0.155092 0.054736 0.008598 0.219600 0.008180 -0.157174 0.007660 0 0 0 0 0 0 0 0 0 0 0 0 0.016352 0.118874 0.043878 0.118874 -0.174731 0.008180 0.842826 0.219600 0.155092 0.008598 0.007660 0.054736 0 0 0 0 0 0 0 0 0.024345 -pinf(-1) -0.058415 0.047523 0.408374 -0.114466 -0.076206 -0.167029 -0.123652 0 0 0 0 0 0 0 0 0 0 0 0 -0.105756 -0.132982 -0.049085 -0.132982 -0.179924 -0.076206 -0.167029 -0.114466 -0.058415 0.408374 -0.123652 0.047523 0 0 0 0 0 0 0 0 -0.004825 -w(-1) -0.073619 0.044632 0.099261 0.108854 -0.015295 -0.047547 -0.193225 0 0 0 0 0 0 0 0 0 0 0 0 0.660587 0.535497 0.197659 0.535497 0.120419 -0.015295 -0.047547 0.108854 -0.073619 0.099261 0.806775 0.044632 0 0 0 0 0 0 0 0 -0.001373 -ea -0.259789 -0.062126 -0.061990 0.354482 0.193715 0.140098 0.099839 0 0 0.274619 0.101366 0.274619 0.718066 0.353014 0.231139 0.563977 -0.199637 0.575621 -0.397460 -0.396272 -0.116828 -0.043123 -0.116828 0.089102 0.193715 0.140098 0.354482 -0.259789 -0.061990 0.099839 -0.062126 0.461800 0 0.235518 0 0 0 0 0.006676 0.004047 -eb 4.296373 1.574152 0.451282 6.160185 6.757721 5.749548 0.504344 0 0 0 0 0 0 0 0 0 0 0 12.379657 0.693927 3.506443 1.294273 3.506443 21.755003 6.757721 5.749548 6.160185 4.296373 0.451282 0.504344 1.574152 0 1.851300 0 0 0 0 0 0 0.166073 -eg 0.424345 0.030135 0.012243 0.596477 -0.131379 -0.040571 0.004358 0 0 0.234357 0.086504 0.234357 -0.475890 -0.257818 -0.133515 0.481292 0.348179 -0.027317 0.280295 0.031051 0.313124 0.115578 0.313124 -0.057433 -0.131379 -0.040571 0.596477 0.424345 0.012243 0.004358 0.030135 0 0 0.609000 0 0 0 0 -0.003856 -0.001172 -eqs 0.397776 0.059885 0.061091 0.569993 -0.050335 2.365295 0.045394 0 0 0.179714 0.066335 0.179714 -1.264881 -0.197704 2.011833 0.369073 0.266997 -0.020948 -0.251509 0.063174 0.323691 0.119479 0.323691 -0.974355 -0.050335 2.365295 0.569993 0.397776 0.061091 0.045394 0.059885 0 0 0 0.601700 0 0 0 0.163478 0.173687 -em -0.201659 0.157335 -0.061038 -0.293837 -0.284407 -0.365864 -0.041530 0 0 0 0 0 0 0 0 0 0 0 0 -0.047298 -0.177625 -0.065564 -0.177625 -0.797698 -0.284407 -0.365864 -0.293837 -0.201659 -0.061038 -0.041530 0.157335 0 0 0 0 0.239700 0 0 0 -0.010568 -epinf -0.015706 0.015028 0.171055 -0.068101 -0.032396 -0.068939 -0.175196 0 0.145500 0 0 0 0 0 0 0 0 0 0 -0.145501 -0.139434 -0.051467 -0.139434 -0.099571 -0.032396 -0.068939 -0.068101 -0.015706 0.171055 -0.175196 0.015028 0 0 0 0 0 0.145500 0 0 -0.001991 -ew -0.030720 0.018624 0.041419 0.045422 -0.006382 -0.019840 0.336650 0.208900 0 0 0 0 0 0 0 0 0 0 0 0.275649 0.223452 0.082479 0.223452 0.050249 -0.006382 -0.019840 0.045422 -0.030720 0.041419 0.336650 0.018624 0 0 0 0 0 0 0.208900 0 -0.000573 - - -THEORETICAL MOMENTS -VARIABLE MEAN STD. DEV. VARIANCE -labobs 0.0000 0.0000 0.0000 -robs 1.1542 0.0000 0.0000 -pinfobs 0.5000 0.0000 0.0000 -dy 0.4000 0.0000 0.0000 -dc 0.4000 0.0000 0.0000 -dinve 0.4000 0.0000 0.0000 -dw 0.4000 0.0000 0.0000 -ewma 0.0000 0.0000 0.0000 -epinfma 0.0000 0.0000 0.0000 -zcapf 0.0000 0.0000 0.0000 -rkf 0.0000 0.0000 0.0000 -kf 0.0000 0.0000 0.0000 -pkf 0.0000 0.0000 0.0000 -cf 0.0000 0.0000 0.0000 -invef 0.0000 0.0000 0.0000 -yf 0.0000 0.0000 0.0000 -labf 0.0000 0.0000 0.0000 -wf 0.0000 0.0000 0.0000 -rrf 0.0000 0.0000 0.0000 -mc 0.0000 0.0000 0.0000 -zcap 0.0000 0.0000 0.0000 -rk 0.0000 0.0000 0.0000 -k 0.0000 0.0000 0.0000 -pk 0.0000 0.0000 0.0000 -c 0.0000 0.0000 0.0000 -inve 0.0000 0.0000 0.0000 -y 0.0000 0.0000 0.0000 -lab 0.0000 0.0000 0.0000 -pinf 0.0000 0.0000 0.0000 -w 0.0000 0.0000 0.0000 -r 0.0000 0.0000 0.0000 -a 0.0000 0.0000 0.0000 -b 0.0000 0.0000 0.0000 -g 0.0000 0.0000 0.0000 -qs 0.0000 0.0000 0.0000 -ms 0.0000 0.0000 0.0000 -spinf 0.0000 0.0000 0.0000 -sw 0.0000 0.0000 0.0000 -kpf 0.0000 0.0000 0.0000 -kp 0.0000 0.0000 0.0000 - - - -VARIANCE DECOMPOSITION (in percent) - ea eb eg eqs em epinf ew -labobs 1.53 90.53 4.76 2.36 0.75 0.02 0.04 -robs 0.15 97.86 0.11 1.59 0.27 0.01 0.01 -pinfobs 0.79 92.80 0.27 2.16 2.51 1.20 0.28 -dy 0.38 97.45 0.77 1.09 0.29 0.02 0.01 -dc 0.16 99.52 0.06 0.03 0.22 0.01 0.00 -dinve 0.14 82.01 0.01 17.33 0.48 0.02 0.01 -dw 6.29 64.77 0.01 0.89 0.53 5.65 21.87 -ewma 0.00 0.00 0.00 0.00 0.00 0.00 100.00 -epinfma 0.00 0.00 0.00 0.00 0.00 100.00 0.00 -zcapf 23.00 0.00 30.72 46.28 0.00 0.00 0.00 -rkf 23.00 0.00 30.72 46.28 0.00 0.00 0.00 -kf 92.86 0.00 1.46 5.68 0.00 0.00 0.00 -pkf 4.34 0.00 1.84 93.82 0.00 0.00 0.00 -cf 80.87 0.00 17.66 1.47 0.00 0.00 0.00 -invef 52.59 0.00 3.98 43.43 0.00 0.00 0.00 -yf 91.00 0.00 8.01 0.99 0.00 0.00 0.00 -labf 23.07 0.00 70.77 6.16 0.00 0.00 0.00 -wf 99.47 0.00 0.21 0.32 0.00 0.00 0.00 -rrf 0.08 99.74 0.04 0.13 0.00 0.00 0.00 -mc 4.73 89.10 0.05 1.55 1.20 1.13 2.23 -zcap 5.32 69.95 7.17 16.54 0.85 0.07 0.10 -rk 5.32 69.95 7.17 16.54 0.85 0.07 0.10 -k 31.75 61.58 0.63 5.18 0.72 0.07 0.07 -pk 0.01 98.45 0.00 1.32 0.20 0.01 0.00 -c 27.91 65.25 5.77 0.59 0.45 0.01 0.02 -inve 15.48 60.45 1.04 21.92 1.02 0.03 0.07 -y 28.57 66.16 2.63 2.01 0.59 0.02 0.03 -lab 1.53 90.53 4.76 2.36 0.75 0.02 0.04 -pinf 0.79 92.80 0.27 2.16 2.51 1.20 0.28 -w 89.79 8.66 0.18 0.78 0.15 0.14 0.30 -r 0.15 97.86 0.11 1.59 0.27 0.01 0.01 -a 100.00 0.00 0.00 0.00 0.00 0.00 0.00 -b 0.00 100.00 0.00 0.00 0.00 0.00 0.00 -g 13.01 0.00 86.99 0.00 0.00 0.00 0.00 -qs 0.00 0.00 0.00 100.00 0.00 0.00 0.00 -ms 0.00 0.00 0.00 0.00 100.00 0.00 0.00 -spinf 0.00 0.00 0.00 0.00 0.00 100.00 0.00 -sw 0.00 0.00 0.00 0.00 0.00 0.00 100.00 -kpf 69.22 0.00 4.97 25.81 0.00 0.00 0.00 -kp 37.20 37.40 2.42 22.08 0.82 0.01 0.06