Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
particles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Archives
particles
Commits
c50392de
Commit
c50392de
authored
9 years ago
by
Frédéric Karamé
Browse files
Options
Downloads
Patches
Plain Diff
Correct the auxiliary filter part.
parent
7dbc2acc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/online_auxiliary_filter.m
+19
-20
19 additions, 20 deletions
src/online_auxiliary_filter.m
with
19 additions
and
20 deletions
src/online_auxiliary_filter.m
+
19
−
20
View file @
c50392de
...
@@ -43,7 +43,7 @@ persistent start_param sample_size number_of_observed_variables number_of_struct
...
@@ -43,7 +43,7 @@ persistent start_param sample_size number_of_observed_variables number_of_struct
% Set seed for randn().
% Set seed for randn().
set_dynare_seed
(
'default'
)
;
set_dynare_seed
(
'default'
)
;
pruning
=
DynareOptions
.
particle
.
pruning
;
pruning
=
DynareOptions
.
particle
.
pruning
;
second_resample
=
1
;
second_resample
=
0
;
variance_update
=
1
;
variance_update
=
1
;
% initialization of state particles
% initialization of state particles
...
@@ -122,7 +122,7 @@ for t=1:sample_size
...
@@ -122,7 +122,7 @@ for t=1:sample_size
chol_sigma_bar
=
chol
(
h_square
*
sigma_bar
)
'
;
chol_sigma_bar
=
chol
(
h_square
*
sigma_bar
)
'
;
end
end
% Prediction (without shocks)
% Prediction (without shocks)
w
tilde
=
zeros
(
1
,
number_of_particles
)
;
tau_
tilde
=
zeros
(
1
,
number_of_particles
)
;
for
i
=
1
:
number_of_particles
for
i
=
1
:
number_of_particles
% model resolution
% model resolution
[
ys
,
trend_coeff
,
exit_flag
,
info
,
Model
,
DynareOptions
,
BayesInfo
,
DynareResults
,
ReducedForm
]
=
...
[
ys
,
trend_coeff
,
exit_flag
,
info
,
Model
,
DynareOptions
,
BayesInfo
,
DynareResults
,
ReducedForm
]
=
...
...
@@ -145,22 +145,23 @@ for t=1:sample_size
...
@@ -145,22 +145,23 @@ for t=1:sample_size
tmp
=
local_state_space_iteration_2
(
yhat
,
zeros
(
number_of_structural_innovations
,
1
),
ghx
,
ghu
,
constant
,
ghxx
,
ghuu
,
ghxu
,
DynareOptions
.
threads
.
local_state_space_iteration_2
);
tmp
=
local_state_space_iteration_2
(
yhat
,
zeros
(
number_of_structural_innovations
,
1
),
ghx
,
ghu
,
constant
,
ghxx
,
ghuu
,
ghxu
,
DynareOptions
.
threads
.
local_state_space_iteration_2
);
end
end
PredictionError
=
bsxfun
(
@
minus
,
Y
(
t
,:)
'
,
tmp
(
mf1
,:));
PredictionError
=
bsxfun
(
@
minus
,
Y
(
t
,:)
'
,
tmp
(
mf1
,:));
wtilde
(
i
)
=
exp
(
-.
5
*
(
const_lik
+
log
(
det
(
ReducedForm
.
H
))
+
sum
(
PredictionError
.*
(
ReducedForm
.
H
\
PredictionError
),
1
)))
;
% Replace Gaussian density with a Student density with 3 degrees of
% freedom for fat tails.
z
=
sum
(
PredictionError
.*
(
ReducedForm
.
H
\
PredictionError
),
1
)
;
tau_tilde
(
i
)
=
weights
(
i
)
.*
(
tpdf
(
z
,
3
*
ones
(
size
(
z
)))
+
1e-99
)
;
%tau_tilde(i) = weights(i).*exp(-.5*(const_lik+log(det(ReducedForm.H))+sum(PredictionError.*(ReducedForm.H\PredictionError),1))) ;
end
end
% unormalized weights and observation likelihood contribution
tau_tilde
=
weights
.*
wtilde
;
sum_tau_tilde
=
sum
(
tau_tilde
)
;
% particles selection
% particles selection
tau_tilde
=
tau_tilde
/
sum
_
tau_tilde
;
tau_tilde
=
tau_tilde
/
sum
(
tau_tilde
)
;
indx
=
resample
(
0
,
tau_tilde
'
,
DynareOptions
.
particle
);
indx
=
resample
(
0
,
tau_tilde
'
,
DynareOptions
.
particle
);
StateVectors
=
StateVectors
(:,
indx
)
;
StateVectors
=
StateVectors
(:,
indx
)
;
if
pruning
if
pruning
StateVectors_
=
StateVectors_
(:,
indx
)
;
StateVectors_
=
StateVectors_
(:,
indx
)
;
end
end
xparam
=
bsxfun
(
@
plus
,(
1
-
small_a
)
.*
m_bar
,
small_a
.*
xparam
(:,
indx
))
;
xparam
=
bsxfun
(
@
plus
,(
1
-
small_a
)
.*
m_bar
,
small_a
.*
xparam
(:,
indx
))
;
w
tilde
=
w
tilde
(
indx
)
;
w
_stage1
=
weights
(
indx
)
.
/
tau_
tilde
(
indx
)
;
% draw in the new distributions
% draw in the new distributions
lnw
=
zeros
(
1
,
number_of_particles
)
;
wtilde
=
zeros
(
1
,
number_of_particles
)
;
i
=
1
;
i
=
1
;
while
i
<=
number_of_particles
while
i
<=
number_of_particles
candidate
=
xparam
(:,
i
)
+
chol_sigma_bar
*
randn
(
number_of_parameters
,
1
)
;
candidate
=
xparam
(:,
i
)
+
chol_sigma_bar
*
randn
(
number_of_parameters
,
1
)
;
...
@@ -191,18 +192,16 @@ for t=1:sample_size
...
@@ -191,18 +192,16 @@ for t=1:sample_size
end
end
StateVectors
(:,
i
)
=
tmp
(
mf0
,:)
;
StateVectors
(:,
i
)
=
tmp
(
mf0
,:)
;
PredictionError
=
bsxfun
(
@
minus
,
Y
(
t
,:)
'
,
tmp
(
mf1
,:));
PredictionError
=
bsxfun
(
@
minus
,
Y
(
t
,:)
'
,
tmp
(
mf1
,:));
lnw
(
i
)
=
exp
(
-.
5
*
(
const_lik
+
log
(
det
(
ReducedForm
.
H
))
+
sum
(
PredictionError
.*
(
ReducedForm
.
H
\
PredictionError
),
1
)));
wtilde
(
i
)
=
w_stage1
(
i
)
*
exp
(
-.
5
*
(
const_lik
+
log
(
det
(
ReducedForm
.
H
))
+
sum
(
PredictionError
.*
(
ReducedForm
.
H
\
PredictionError
),
1
)));
i
=
i
+
1
;
i
=
i
+
1
;
end
end
end
end
% importance ratio
wtilde
=
lnw
.
/
wtilde
;
% normalization
% normalization
weights
=
wtilde
/
sum
(
wtilde
);
weights
=
wtilde
/
sum
(
wtilde
);
if
(
variance_update
==
1
)
&&
(
neff
(
weights
)
<
DynareOptions
.
particle
.
resampling
.
threshold
*
sample_size
)
if
(
variance_update
==
1
)
&&
(
neff
(
weights
)
<
DynareOptions
.
particle
.
resampling
.
threshold
*
sample_size
)
variance_update
=
0
;
variance_update
=
0
;
end
end
% final resampling (advised)
% final resampling (
not
advised)
if
second_resample
==
1
if
second_resample
==
1
indx
=
resample
(
0
,
weights
,
DynareOptions
.
particle
);
indx
=
resample
(
0
,
weights
,
DynareOptions
.
particle
);
StateVectors
=
StateVectors
(:,
indx
)
;
StateVectors
=
StateVectors
(:,
indx
)
;
...
@@ -234,16 +233,16 @@ for t=1:sample_size
...
@@ -234,16 +233,16 @@ for t=1:sample_size
pass2
=
1
;
pass2
=
1
;
pass3
=
1
;
pass3
=
1
;
for
j
=
1
:
number_of_particles
for
j
=
1
:
number_of_particles
if
cumulated_weights
(
j
)
>
0.025
&&
pass1
==
1
if
cumulated_weights
(
j
)
>
=
0.025
&&
pass1
==
1
lb95_xparam
(
i
,
t
)
=
(
temp
(
j
-
1
,
1
)
+
temp
(
j
,
1
))/
2
;
lb95_xparam
(
i
,
t
)
=
temp
(
j
,
1
)
;
pass1
=
2
;
pass1
=
2
;
end
end
if
cumulated_weights
(
j
)
>
0.5
&&
pass2
==
1
if
cumulated_weights
(
j
)
>
=
0.5
&&
pass2
==
1
median_xparam
(
i
,
t
)
=
(
temp
(
j
-
1
,
1
)
+
temp
(
j
,
1
))/
2
;
median_xparam
(
i
,
t
)
=
temp
(
j
,
1
)
;
pass2
=
2
;
pass2
=
2
;
end
end
if
cumulated_weights
(
j
)
>
0.975
&&
pass3
==
1
if
cumulated_weights
(
j
)
>
=
0.975
&&
pass3
==
1
ub95_xparam
(
i
,
t
)
=
(
temp
(
j
-
1
,
1
)
+
temp
(
j
,
1
))/
2
;
ub95_xparam
(
i
,
t
)
=
temp
(
j
,
1
)
;
pass3
=
2
;
pass3
=
2
;
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment