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
18059c01
Commit
18059c01
authored
9 years ago
by
Frédéric Karamé
Browse files
Options
Downloads
Patches
Plain Diff
Correction on a bug and extension of the original paper for the calculation of incremental weights.
parent
5b5e88b5
Branches
Branches containing commit
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
+8
-6
8 additions, 6 deletions
src/conditional_filter_proposal.m
src/conditional_particle_filter.m
+5
-11
5 additions, 11 deletions
src/conditional_particle_filter.m
with
13 additions
and
17 deletions
src/conditional_filter_proposal.m
+
8
−
6
View file @
18059c01
...
@@ -95,6 +95,7 @@ if ParticleOptions.proposal_approximation.cubature || ParticleOptions.proposal_a
...
@@ -95,6 +95,7 @@ if ParticleOptions.proposal_approximation.cubature || ParticleOptions.proposal_a
PredictedObservedMean
=
sum
(
PredictedObservedMean
,
2
)
;
PredictedObservedMean
=
sum
(
PredictedObservedMean
,
2
)
;
dState
=
bsxfun
(
@
minus
,
tmp
(
mf0
,:),
PredictedStateMean
)
'.*
sqrt
(
weights
)
;
dState
=
bsxfun
(
@
minus
,
tmp
(
mf0
,:),
PredictedStateMean
)
'.*
sqrt
(
weights
)
;
dObserved
=
bsxfun
(
@
minus
,
tmp
(
mf1
,:),
PredictedObservedMean
)
'.*
sqrt
(
weights
);
dObserved
=
bsxfun
(
@
minus
,
tmp
(
mf1
,:),
PredictedObservedMean
)
'.*
sqrt
(
weights
);
PredictedStateVariance
=
dState
*
dState
'
;
big_mat
=
[
dObserved
dState
;
[
H_lower_triangular_cholesky
zeros
(
number_of_observed_variables
,
number_of_state_variables
)]
];
big_mat
=
[
dObserved
dState
;
[
H_lower_triangular_cholesky
zeros
(
number_of_observed_variables
,
number_of_state_variables
)]
];
[
mat1
,
mat
]
=
qr2
(
big_mat
,
0
);
[
mat1
,
mat
]
=
qr2
(
big_mat
,
0
);
mat
=
mat
'
;
mat
=
mat
'
;
...
@@ -112,12 +113,13 @@ else
...
@@ -112,12 +113,13 @@ else
KalmanFilterGain
=
PredictedStateAndObservedCovariance
/
PredictedObservedVariance
;
KalmanFilterGain
=
PredictedStateAndObservedCovariance
/
PredictedObservedVariance
;
StateVectorMean
=
PredictedStateMean
+
KalmanFilterGain
*
(
obs
-
PredictedObservedMean
);
StateVectorMean
=
PredictedStateMean
+
KalmanFilterGain
*
(
obs
-
PredictedObservedMean
);
StateVectorVariance
=
PredictedStateVariance
-
KalmanFilterGain
*
PredictedObservedVariance
*
KalmanFilterGain
'
;
StateVectorVariance
=
PredictedStateVariance
-
KalmanFilterGain
*
PredictedObservedVariance
*
KalmanFilterGain
'
;
StateVectorVariance
=
.
5
*
(
StateVectorVariance
+
StateVectorVariance
'
);
%
StateVectorVariance = .5*(StateVectorVariance+StateVectorVariance');
StateVectorVarianceSquareRoot
=
chol
(
StateVectorVariance
)
';%reduced_rank_cholesky(StateVectorVariance
)'
;
StateVectorVarianceSquareRoot
=
chol
(
StateVectorVariance
+
1e-6
)
'
;
end
end
PredictedStateVarianceSquareRoot
=
chol
(
PredictedStateVariance
+
1e-6
)
'
;
ProposalStateVector
=
StateVectorVarianceSquareRoot
*
randn
(
size
(
StateVectorVarianceSquareRoot
,
2
),
1
)
+
StateVectorMean
;
ProposalStateVector
=
StateVectorVarianceSquareRoot
*
randn
(
size
(
StateVectorVarianceSquareRoot
,
2
),
1
)
+
StateVectorMean
;
ypred
=
measurement_equations
(
ProposalStateVector
,
ReducedForm
,
ThreadsOptions
)
;
Prior
=
probability2
(
PredictedStateMean
,
PredictedStateVarianceSquareRoot
,
ProposalStateVector
)
;
foo
=
H_lower_triangular_cholesky
\
(
obs
-
ypred
)
;
Posterior
=
probability2
(
StateVectorMean
,
StateVectorVarianceSquareRoot
,
ProposalStateVector
)
;
l
ikelihood
=
exp
(
-
0.5
*
(
foo
)
'*
foo
)/
normconst2
+
1e-99
;
L
ikelihood
=
probability2
(
obs
,
H_lower_triangular_cholesky
,
measurement_equations
(
ProposalStateVector
,
ReducedForm
,
ThreadsOptions
))
;
Weights
=
SampleWeights
.*
l
ikelihood
;
Weights
=
SampleWeights
.*
L
ikelihood
.*
(
Prior
.
/
Posterior
)
;
This diff is collapsed.
Click to expand it.
src/conditional_particle_filter.m
+
5
−
11
View file @
18059c01
...
@@ -68,10 +68,8 @@ end
...
@@ -68,10 +68,8 @@ end
% Set persistent variables.
% Set persistent variables.
if
isempty
(
init_flag
)
if
isempty
(
init_flag
)
%mf0 = ReducedForm.mf0;
mf1
=
ReducedForm
.
mf1
;
mf1
=
ReducedForm
.
mf1
;
sample_size
=
size
(
Y
,
2
);
sample_size
=
size
(
Y
,
2
);
%number_of_state_variables = length(mf0);
number_of_observed_variables
=
length
(
mf1
);
number_of_observed_variables
=
length
(
mf1
);
init_flag
=
1
;
init_flag
=
1
;
number_of_particles
=
ParticleOptions
.
number_of_particles
;
number_of_particles
=
ParticleOptions
.
number_of_particles
;
...
@@ -84,25 +82,23 @@ if isempty(H)
...
@@ -84,25 +82,23 @@ if isempty(H)
H
=
0
;
H
=
0
;
H_lower_triangular_cholesky
=
0
;
H_lower_triangular_cholesky
=
0
;
else
else
H_lower_triangular_cholesky
=
chol
(
H
)
';
%reduced_rank_cholesky(H)'
;
H_lower_triangular_cholesky
=
chol
(
H
)
'
;
end
end
% Get initial condition for the state vector.
% Get initial condition for the state vector.
StateVectorMean
=
ReducedForm
.
StateVectorMean
;
StateVectorMean
=
ReducedForm
.
StateVectorMean
;
StateVectorVarianceSquareRoot
=
reduced_rank_cholesky
(
ReducedForm
.
StateVectorVariance
)
'
;
StateVectorVarianceSquareRoot
=
chol
(
ReducedForm
.
StateVectorVariance
)
'
;
state_variance_rank
=
size
(
StateVectorVarianceSquareRoot
,
2
);
state_variance_rank
=
size
(
StateVectorVarianceSquareRoot
,
2
);
Q_lower_triangular_cholesky
=
chol
(
Q
)
';
%reduced_rank_cholesky(Q)'
;
Q_lower_triangular_cholesky
=
chol
(
Q
)
'
;
% Set seed for randn().
% Set seed for randn().
set_dynare_seed
(
'default'
);
set_dynare_seed
(
'default'
);
% Initialization of the likelihood.
% Initialization of the likelihood.
normconst2
=
log
(
2
*
pi
)
*
number_of_observed_variables
*
prod
(
d
iag
(
H_lower_triangular_cholesky
)
)
;
normconst2
=
sqrt
(
(
(
2
*
pi
)
^
number_of_observed_variables
)
*
prod
(
d
et
(
H
))
)
;
lik
=
NaN
(
sample_size
,
1
);
lik
=
NaN
(
sample_size
,
1
);
LIK
=
NaN
;
LIK
=
NaN
;
ks
=
0
;
ks
=
0
;
StateParticles
=
bsxfun
(
@
plus
,
StateVectorVarianceSquareRoot
*
randn
(
state_variance_rank
,
number_of_particles
),
StateVectorMean
);
StateParticles
=
bsxfun
(
@
plus
,
StateVectorVarianceSquareRoot
*
randn
(
state_variance_rank
,
number_of_particles
),
StateVectorMean
);
SampleWeights
=
ones
(
1
,
number_of_particles
)/
number_of_particles
;
SampleWeights
=
ones
(
1
,
number_of_particles
)/
number_of_particles
;
for
t
=
1
:
sample_size
for
t
=
1
:
sample_size
...
@@ -121,5 +117,3 @@ for t=1:sample_size
...
@@ -121,5 +117,3 @@ for t=1:sample_size
end
end
LIK
=
-
sum
(
lik
(
start
:
end
));
LIK
=
-
sum
(
lik
(
start
:
end
));
\ No newline at end of file
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