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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Archives
particles
Commits
43615ce4
Project 'Dynare/particles' was moved to 'Archives/particles'. Please update any links and bookmarks that may still have the old path.
Commit
43615ce4
authored
7 years ago
by
Frédéric Karamé
Browse files
Options
Downloads
Patches
Plain Diff
Add flags to deal with errors on Cholesky matrices in CPF filter.
parent
1f08164b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/conditional_filter_proposal.m
+20
-3
20 additions, 3 deletions
src/conditional_filter_proposal.m
src/conditional_particle_filter.m
+7
-2
7 additions, 2 deletions
src/conditional_particle_filter.m
with
27 additions
and
5 deletions
src/conditional_filter_proposal.m
+
20
−
3
View file @
43615ce4
function
[
ProposalStateVector
,
Weights
]
=
conditional_filter_proposal
(
ReducedForm
,
obs
,
StateVectors
,
SampleWeights
,
Q_lower_triangular_cholesky
,
H_lower_triangular_cholesky
,
H
,
ParticleOptions
,
ThreadsOptions
,
normconst2
)
function
[
ProposalStateVector
,
Weights
,
flag
]
=
conditional_filter_proposal
(
ReducedForm
,
obs
,
StateVectors
,
SampleWeights
,
Q_lower_triangular_cholesky
,
H_lower_triangular_cholesky
,
H
,
ParticleOptions
,
ThreadsOptions
,
normconst2
)
%
% Computes the proposal for each past particle using Gaussian approximations
% for the state errors and the Kalman filter
...
...
@@ -42,6 +42,7 @@ persistent init_flag2 mf0 mf1
persistent
number_of_state_variables
number_of_observed_variables
persistent
number_of_structural_innovations
flag
=
0
;
% Set local state space model (first-order approximation).
ghx
=
ReducedForm
.
ghx
;
ghu
=
ReducedForm
.
ghu
;
...
...
@@ -118,15 +119,31 @@ else
Error
=
obs
-
PredictedObservedMean
;
StateVectorMean
=
PredictedStateMean
+
KalmanFilterGain
*
Error
;
StateVectorVariance
=
PredictedStateVariance
-
KalmanFilterGain
*
PredictedObservedVariance
*
KalmanFilterGain
'
;
StateVectorVarianceSquareRoot
=
chol
(
StateVectorVariance
+
eye
(
number_of_state_variables
)
*
1e-6
)
'
;
StateVectorVariance
=
0.5
*
(
StateVectorVariance
+
StateVectorVariance
'
);
%StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)';%chol(StateVectorVariance + eye(number_of_state_variables)*1e-6)' ;
[
StateVectorVarianceSquareRoot
,
p
]
=
chol
(
StateVectorVariance
,
'lower'
)
;
if
p
flag
=
1
;
ProposalStateVector
=
zeros
(
number_of_state_variables
,
1
)
;
Weights
=
0.0
;
return
end
if
ParticleOptions
.
cpf_weights_method
.
amisanotristani
Weights
=
SampleWeights
.*
probability2
(
zeros
(
number_of_observed_variables
,
1
),
chol
(
PredictedObservedVariance
)
'
,
Error
)
;
end
end
PredictedStateVarianceSquareRoot
=
chol
(
PredictedStateVariance
+
eye
(
number_of_state_variables
)
*
1e-6
)
'
;
ProposalStateVector
=
StateVectorVarianceSquareRoot
*
randn
(
size
(
StateVectorVarianceSquareRoot
,
2
),
1
)
+
StateVectorMean
;
if
ParticleOptions
.
cpf_weights_method
.
murrayjonesparslow
PredictedStateVariance
=
0.5
*
(
PredictedStateVariance
+
PredictedStateVariance
'
);
%PredictedStateVarianceSquareRoot = reduced_rank_cholesky(PredictedStateVariance)';%chol(PredictedStateVariance + eye(number_of_state_variables)*1e-6)' ;
[
PredictedStateVarianceSquareRoot
,
p
]
=
chol
(
PredictedStateVariance
,
'lower'
)
;
if
p
flag
=
1
;
ProposalStateVector
=
zeros
(
number_of_state_variables
,
1
)
;
Weights
=
0.0
;
return
end
Prior
=
probability2
(
PredictedStateMean
,
PredictedStateVarianceSquareRoot
,
ProposalStateVector
)
;
Posterior
=
probability2
(
StateVectorMean
,
StateVectorVarianceSquareRoot
,
ProposalStateVector
)
;
Likelihood
=
probability2
(
obs
,
H_lower_triangular_cholesky
,
measurement_equations
(
ProposalStateVector
,
ReducedForm
,
ThreadsOptions
))
;
...
...
This diff is collapsed.
Click to expand it.
src/conditional_particle_filter.m
+
7
−
2
View file @
43615ce4
...
...
@@ -103,8 +103,13 @@ StateParticles = bsxfun(@plus,StateVectorVarianceSquareRoot*randn(state_variance
SampleWeights
=
ones
(
1
,
number_of_particles
)/
number_of_particles
;
for
t
=
1
:
sample_size
for
i
=
1
:
number_of_particles
[
StateParticles
(:,
i
),
SampleWeights
(
i
)]
=
...
[
StateParticles
(:,
i
),
SampleWeights
(
i
)
,
flag
]
=
...
conditional_filter_proposal
(
ReducedForm
,
Y
(:,
t
),
StateParticles
(:,
i
),
SampleWeights
(
i
),
Q_lower_triangular_cholesky
,
H_lower_triangular_cholesky
,
H
,
ParticleOptions
,
ThreadsOptions
,
normconst2
)
;
if
flag
==
1
LIK
=-
Inf
;
lik
(
t
)
=-
Inf
;
return
end
end
SumSampleWeights
=
sum
(
SampleWeights
)
;
lik
(
t
)
=
log
(
SumSampleWeights
)
;
...
...
This diff is collapsed.
Click to expand it.
Sébastien Villemot
@sebastien
mentioned in commit
4f68487f
·
5 years ago
mentioned in commit
4f68487f
mentioned in commit 4f68487fb146f003c29964d8ba32f0e4e924a1b3
Toggle commit list
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