|
109 | 109 | _, _, data = sample(rng, model, 20) |
110 | 110 |
|
111 | 111 | bf = BF(2^12; threshold=0.8) |
| 112 | + apf = APF(2^10, threshold=1.) |
112 | 113 | bf_state, llbf = GeneralisedFilters.filter(rng, model, bf, data) |
| 114 | + _, llapf= GeneralisedFilters.filter(rng, model, apf, data) |
113 | 115 | kf_state, llkf = GeneralisedFilters.filter(rng, model, KF(), data) |
114 | 116 |
|
115 | 117 | xs = bf_state.filtered.particles |
|
120 | 122 |
|
121 | 123 | # since this is log valued, we can up the tolerance |
122 | 124 | @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 |
165 | 126 | end |
166 | 127 |
|
167 | 128 | @testitem "Forward algorithm test" begin |
|
0 commit comments