Skip to content

Commit b78efce

Browse files
test
1 parent 9a8b28e commit b78efce

File tree

2 files changed

+4
-43
lines changed

2 files changed

+4
-43
lines changed

src/algorithms/apf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mutable struct AuxiliaryParticleFilter{RS<:AbstractConditionalResampler} <: Abst
77
end
88

99
function AuxiliaryParticleFilter(
10-
N::Integer; threshold::Real=1.0, resampler::AbstractResampler=Systematic()
10+
N::Integer; threshold::Real=0., resampler::AbstractResampler=Systematic()
1111
)
1212
conditional_resampler = ESSResampler(threshold, resampler)
1313
return AuxiliaryParticleFilter(N, conditional_resampler, zeros(N))

test/runtests.jl

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ end
109109
_, _, data = sample(rng, model, 20)
110110

111111
bf = BF(2^12; threshold=0.8)
112+
apf = APF(2^10, threshold=1.)
112113
bf_state, llbf = GeneralisedFilters.filter(rng, model, bf, data)
114+
_, llapf= GeneralisedFilters.filter(rng, model, apf, data)
113115
kf_state, llkf = GeneralisedFilters.filter(rng, model, KF(), data)
114116

115117
xs = bf_state.filtered.particles
@@ -120,48 +122,7 @@ end
120122

121123
# since this is log valued, we can up the tolerance
122124
@test llkf llbf atol = 0.1
123-
end
124-
125-
@testitem "APF filter test" begin
126-
using GeneralisedFilters
127-
using SSMProblems
128-
using StableRNGs
129-
using PDMats
130-
using LinearAlgebra
131-
using Random: randexp
132-
133-
T = Float32
134-
rng = StableRNG(1234)
135-
σx², σy² = randexp(rng, T, 2)
136-
137-
# initial state distribution
138-
μ0 = zeros(T, 2)
139-
Σ0 = PDMat(T[1 0; 0 1])
140-
141-
# state transition equation
142-
A = T[1 1; 0 1]
143-
b = T[0; 0]
144-
Q = PDiagMat([σx²; 0])
145-
146-
# observation equation
147-
H = T[1 0]
148-
c = T[0;]
149-
R = [σy²;;]
150-
151-
# when working with PDMats, the Kalman filter doesn't play nicely without this
152-
function Base.convert(::Type{PDMat{T,MT}}, mat::MT) where {MT<:AbstractMatrix,T<:Real}
153-
return PDMat(Symmetric(mat))
154-
end
155-
156-
model = create_homogeneous_linear_gaussian_model(μ0, Σ0, A, b, Q, H, c, R)
157-
_, _, data = sample(rng, model, 20)
158-
159-
bf = APF(2^10, threshold=0.8)
160-
_, llbf = GeneralisedFilters.filter(rng, model, bf, data)
161-
_, llkf = GeneralisedFilters.filter(rng, model, KF(), data)
162-
163-
# since this is log valued, we can up the tolerance
164-
@test llkf llbf atol = 2
125+
@test llkf llapf atol = 2
165126
end
166127

167128
@testitem "Forward algorithm test" begin

0 commit comments

Comments
 (0)