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
a73e4d94
Commit
a73e4d94
authored
9 years ago
by
Frédéric Karamé
Browse files
Options
Downloads
Patches
Plain Diff
Add the possibility of Gaussian-Mixture Particle Filter without resampling.
parent
a6a3e1b1
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/fit_gaussian_mixture.m
+2
-2
2 additions, 2 deletions
src/fit_gaussian_mixture.m
src/gaussian_mixture_filter.m
+7
-4
7 additions, 4 deletions
src/gaussian_mixture_filter.m
src/probability3.m
+39
-0
39 additions, 0 deletions
src/probability3.m
with
48 additions
and
6 deletions
src/fit_gaussian_mixture.m
+
2
−
2
View file @
a73e4d94
function
[
StateMu
,
StateSqrtP
,
StateWeights
]
=
fit_gaussian_mixture
(
X
,
StateMu
,
StateSqrtP
,
StateWeights
,
crit
,
niters
,
check
)
function
[
StateMu
,
StateSqrtP
,
StateWeights
]
=
fit_gaussian_mixture
(
X
,
X_weights
,
StateMu
,
StateSqrtP
,
StateWeights
,
crit
,
niters
,
check
)
% Copyright (C) 2013 Dynare Team
%
...
...
@@ -26,7 +26,7 @@ end
eold
=
-
Inf
;
for
n
=
1
:
niters
% Calculate posteriors based on old parameters
[
prior
,
likelihood
,
marginal
,
posterior
]
=
probability
(
StateMu
,
StateSqrtP
,
StateWeights
,
X
);
[
prior
,
likelihood
,
marginal
,
posterior
]
=
probability
3
(
StateMu
,
StateSqrtP
,
StateWeights
,
X
,
X_weights
);
e
=
sum
(
log
(
marginal
));
if
(
n
>
1
&&
abs
((
e
-
eold
)/
eold
)
<
crit
)
return
;
...
...
This diff is collapsed.
Click to expand it.
src/gaussian_mixture_filter.m
+
7
−
4
View file @
a73e4d94
...
...
@@ -294,7 +294,7 @@ for t=1:sample_size
StateParticles
=
bsxfun
(
@
plus
,
StateMuPost
(:,
i
),
StateSqrtPPost
(:,:,
i
)
*
nodes
'
)
;
IncrementalWeights
=
gaussian_mixture_densities
(
Y
(:,
t
),
StateMuPrior
,
StateSqrtPPrior
,
StateWeightsPrior
,
...
StateMuPost
,
StateSqrtPPost
,
StateWeightsPost
,
...
StateParticles
,
H
,
const_lik
,
weights
,
weights_c
,
ReducedForm
,
ThreadsOptions
)
;
StateParticles
,
H
,
const_lik
,
ReducedForm
,
ThreadsOptions
)
;
SampleWeights
(
i
)
=
sum
(
StateWeightsPost
(
i
)
*
weights
.*
IncrementalWeights
)
;
end
SumSampleWeights
=
sum
(
SampleWeights
)
;
...
...
@@ -312,13 +312,16 @@ for t=1:sample_size
StateParticles
=
importance_sampling
(
StateMuPost
,
StateSqrtPPost
,
StateWeightsPost
'
,
number_of_particles
)
;
IncrementalWeights
=
gaussian_mixture_densities
(
Y
(:,
t
),
StateMuPrior
,
StateSqrtPPrior
,
StateWeightsPrior
,
...
StateMuPost
,
StateSqrtPPost
,
StateWeightsPost
,
...
StateParticles
,
H
,
const_lik
,
1
/
number_of_particles
,
...
1
/
number_of_particles
,
ReducedForm
,
ThreadsOptions
)
;
StateParticles
,
H
,
const_lik
,
ReducedForm
,
ThreadsOptions
)
;
SampleWeights
=
IncrementalWeights
/
number_of_particles
;
SumSampleWeights
=
sum
(
SampleWeights
,
1
)
;
SampleWeights
=
SampleWeights
.
/
SumSampleWeights
;
lik
(
t
)
=
log
(
SumSampleWeights
)
;
[
StateMu
,
StateSqrtP
,
StateWeights
]
=
fit_gaussian_mixture
(
StateParticles
,
StateMu
,
StateSqrtP
,
StateWeights
,
0.001
,
10
,
1
)
;
if
(
ParticleOptions
.
resampling
.
status
.
generic
&&
neff
(
SampleWeights
)
<
ParticleOptions
.
resampling
.
threshold
*
sample_size
)
||
ParticleOptions
.
resampling
.
status
.
systematic
StateParticles
=
resample
(
StateParticles
',SampleWeights'
,
ParticleOptions
)
'
;
SampleWeights
=
ones
(
number_of_particles
,
1
)/
number_of_particles
;
end
[
StateMu
,
StateSqrtP
,
StateWeights
]
=
fit_gaussian_mixture
(
StateParticles
,
SampleWeights
'
,
StateMu
,
StateSqrtP
,
StateWeights
,
0.001
,
10
,
1
)
;
end
end
...
...
This diff is collapsed.
Click to expand it.
src/probability3.m
0 → 100644
+
39
−
0
View file @
a73e4d94
function
[
prior
,
likelihood
,
C
,
posterior
]
=
probability3
(
mu
,
sqrtP
,
prior
,
X
,
X_weights
)
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
[
dim
,
nov
]
=
size
(
X
);
M
=
size
(
mu
,
2
)
;
if
nargout
>
1
likelihood
=
zeros
(
M
,
nov
);
normfact
=
(
2
*
pi
)
^
(
dim
/
2
);
for
k
=
1
:
M
XX
=
bsxfun
(
@
minus
,
X
,
mu
(:,
k
));
S
=
sqrtP
(:,:,
k
);
foo
=
S
\
XX
;
likelihood
(
k
,:)
=
exp
(
-
0.5
*
sum
(
foo
.*
foo
,
1
))/
abs
((
normfact
*
prod
(
diag
(
S
))));
end
end
wlikelihood
=
bsxfun
(
@
times
,
X_weights
,
likelihood
)
+
1e-99
;
if
nargout
>
2
C
=
prior
*
wlikelihood
+
1e-99
;
end
if
nargout
>
3
posterior
=
bsxfun
(
@
rdivide
,
bsxfun
(
@
times
,
prior
'
,
wlikelihood
),
C
)
+
1e-99
;
posterior
=
bsxfun
(
@
rdivide
,
posterior
,
sum
(
posterior
,
1
));
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