11export AuxiliaryParticleFilter, APF
22
3- mutable struct AuxiliaryParticleFilter{RS<: AbstractConditionalResampler } <: AbstractFilter
4- N :: Integer
3+ mutable struct AuxiliaryParticleFilter{N, RS<: AbstractConditionalResampler } < :
4+ AbstractParticleFilter{N}
55 resampler:: RS
66 aux:: Vector # Auxiliary weights
77end
@@ -10,20 +10,22 @@ function AuxiliaryParticleFilter(
1010 N:: Integer ; threshold:: Real = 0.0 , resampler:: AbstractResampler = Systematic ()
1111)
1212 conditional_resampler = ESSResampler (threshold, resampler)
13- return AuxiliaryParticleFilter (N, conditional_resampler, zeros (N))
13+ return AuxiliaryParticleFilter {N,typeof(conditional_resampler)} (
14+ conditional_resampler, zeros (N)
15+ )
1416end
1517
1618const APF = AuxiliaryParticleFilter
1719
1820function initialise (
1921 rng:: AbstractRNG ,
2022 model:: StateSpaceModel{T} ,
21- filter:: AuxiliaryParticleFilter ;
23+ filter:: AuxiliaryParticleFilter{N} ;
2224 ref_state:: Union{Nothing,AbstractVector} = nothing ,
2325 kwargs... ,
24- ) where {T}
25- initial_states = map (x -> SSMProblems. simulate (rng, model. dyn; kwargs... ), 1 : (filter . N) )
26- initial_weights = fill (- log (T (filter . N)), filter . N)
26+ ) where {T,N }
27+ initial_states = map (x -> SSMProblems. simulate (rng, model. dyn; kwargs... ), 1 : N )
28+ initial_weights = fill (- log (T (N)), N)
2729
2830 return update_ref! (
2931 ParticleContainer (initial_states, initial_weights), ref_state, filter
7577
7678function update (
7779 model:: StateSpaceModel{T} ,
78- filter:: AuxiliaryParticleFilter ,
80+ filter:: AuxiliaryParticleFilter{N} ,
7981 step:: Integer ,
8082 states:: ParticleContainer ,
8183 observation;
8284 kwargs... ,
83- ) where {T}
85+ ) where {T,N }
8486 @debug " step $step "
8587 log_increments = map (
8688 x -> SSMProblems. logdensity (model. obs, step, x, observation; kwargs... ),
@@ -90,7 +92,7 @@ function update(
9092 states. filtered. log_weights = states. proposed. log_weights + log_increments
9193 states. filtered. particles = states. proposed. particles
9294
93- return (states, logsumexp (log_increments) - log (T (filter . N)))
95+ return (states, logsumexp (log_increments) - log (T (N)))
9496end
9597
9698function step (
0 commit comments