@@ -24,7 +24,6 @@ gr(legend = :topleft, grid = false, color = colors[2], lw = 2, legendfontsize=8,
2424 xtickfontsize= 8 , ytickfontsize= 8 , xguidefontsize= 8 , yguidefontsize= 8 ,
2525 titlefontsize = 10 , markerstrokecolor = :auto )
2626
27- myquantile (A, p; dims, kwargs... ) = mapslices (x -> quantile (x, p; kwargs... ), A; dims)
2827Random. seed! (123 );
2928
3029# ### Set up Poisson model
@@ -79,7 +78,7 @@ function plotEvolDistributions!(plt, postDraws, quantiles, trueEvol = nothing,
7978 label = nothing , shaded = false ; plotSettings... )
8079
8180 T, nState, nSim = size (postDraws)
82- postquantiles = myquantile (postDraws, quantiles, dims = 3 );
81+ postquantiles = quantile_multidim (postDraws, quantiles, dims = 3 );
8382
8483 if ! isnothing (trueEvol)
8584 plot! (plt, 1 : T, trueEvol, lw = 1 , c = :black , label = " true" ; plotSettings... )
@@ -122,17 +121,20 @@ plt
122121# ### PGAS sampling
123122nSim = 1000 ; # Number of samples from posterior
124123nParticles = 100 # Number of particles for PGAS
125- PGASdraws = PGASsampler (y, θ, nSim, nParticles, prior, transition, observation);
124+ sample_t0 = true # Sample state at t=0 ?
125+ PGASdraws = PGASsampler (y, θ, nSim, nParticles, prior, transition, observation;
126+ sample_t0 = sample_t0);
126127
127128# Plot the true evolution and the posterior distributions from PGAS
128129quantiles = [0.025 , 0.5 , 0.975 ]
129130pltLogIntensity = plot (; title = " Log Intensity " * L " \l og\l ambda_t = x_t" )
130- plotEvolDistributions! (pltLogIntensity, PGASdraws, quantiles, x ,
131+ plotEvolDistributions! (pltLogIntensity, PGASdraws, quantiles, [ NaN * ones (sample_t0);x] ,
131132 " PGAS(N=$nParticles )" , true ; color = colors[3 ], lw = 1 , legend = :topright )
132133
133134pltIntensity = plot (; title = " Intensity " * L " \l ambda_t = \e xp(x_t)" )
134- plotEvolDistributions! (pltIntensity, exp .(PGASdraws), quantiles, exp .(x),
135- " PGAS(N=$nParticles )" , true ; color = colors[3 ], lw = 1 , legend = :topright )
135+ plotEvolDistributions! (pltIntensity, exp .(PGASdraws), quantiles,
136+ exp .([NaN * ones (sample_t0);x]), " PGAS(N=$nParticles )" , true ; color = colors[3 ],
137+ lw = 1 , legend = :topright )
136138
137139plot (pltLogIntensity, pltIntensity, layout = (1 ,2 ), size = (800 , 300 ), bottommargin = 5 mm)
138140
@@ -147,7 +149,8 @@ B = θ.μ*(1-θ.a) # The transition model is x_t = μ + a (x_{t-1} - μ) + η_t,
147149U = ones (T,1 );
148150
149151# Simulate from the Laplace approximation of the posterior distribution
150- LaplaceDraws = FFBS_laplace (U, y, A, B, Σₙ, μ₀, Σ₀, observation, θ, nSim);
152+ LaplaceDraws = FFBS_laplace (U, y, A, B, Σₙ, μ₀, Σ₀, observation, θ, nSim;
153+ sample_t0 = sample_t0);
151154
152155# Plot the PGAS and Laplace posterior distributions, this time without true evolution
153156pltLogIntensity = plot (; title = " Log Intensity " * L " \l og\l ambda_t = x_t" )
@@ -179,10 +182,12 @@ x, y, plt = simTvPoisson(observation, transition, prior, θ, T);
179182plt
180183
181184# Simulate from the PGAS posterior distribution
182- PGASdraws = PGASsampler (y, θ, nSim, nParticles, prior, transition, observation);
185+ PGASdraws = PGASsampler (y, θ, nSim, nParticles, prior, transition, observation;
186+ sample_t0 = sample_t0);
183187
184188# Simulate from the Laplace approximation of the posterior distribution
185- LaplaceDraws = FFBS_laplace (U, y, A, B, Σₙ, μ₀, Σ₀, observation, θ, nSim);
189+ LaplaceDraws = FFBS_laplace (U, y, A, B, Σₙ, μ₀, Σ₀, observation, θ, nSim;
190+ sample_t0 = sample_t0);
186191
187192# Plot the PGAS and Laplace posterior distributions, without true evolution
188193pltLogIntensity = plot (; title = " Log Intensity " * L " \l og\l ambda_t = x_t" )
0 commit comments