Commit a451577
authored
perf(autoware_kalman_filter): use Cholesky solve in update() with full guard-branch test coverage (#1094)
* test(autoware_kalman_filter): cover validation and guard branches
Add unit tests for the previously-untested KalmanFilter dimension
validation FALSE branches (init/predict/update), the state and covariance
getters, and a closed-form numerical-equivalence update check on a
correlated covariance. Add TimeDelayKalmanFilter::updateWithDelay tests
for the non-column-vector, non-square-R, R/C-row-mismatch, and
non-positive-definite (LLT failure) rejection paths, capturing stderr so
test output stays clean.
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
* perf(autoware_kalman_filter): solve innovation covariance via Cholesky in update()
Mirror the optimization already applied to TimeDelayKalmanFilter::updateWithDelay
in the base KalmanFilter::update: compute the Kalman gain with a Cholesky (LLT)
solve of the innovation covariance S = C P C^T + R instead of an explicit matrix
inverse. This is faster and numerically more stable, and a failed decomposition
now rejects updates whose innovation covariance is not positive definite, which the
explicit inverse silently accepted with a meaningless gain (potentially corrupting
downstream state in autoware_ekf_localizer).
Also use noalias() in predict(x_next, A, Q) to drop the intermediate Eigen
temporaries of A P A^T in that hot per-cycle path.
The public bool API is unchanged; behavior is identical for valid inputs (verified
against the closed-form solution) and fails safe for non-positive-definite ones.
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
* test(autoware_kalman_filter): address review feedback
- assert update against hand-computed numeric literals instead of a re-typed copy of the solver formula
- strengthen the two-arg init test to verify stored state/covariance feed the filter math, keeping getXelement coverage
Refs: #1096
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
* test(autoware_kalman_filter): de-tautologize the kf end-to-end test (#78)
Replace the recomputed-with-the-same-Kalman-formula expectations in TEST(kalman_filter, kf) with independent hand-computed numeric literals for the predict and update steps (A=B=C=I, Q=0.01I, R=0.09I), with the derivations written out in comments. The previous expectations re-typed the implementation's own predict/update expressions, so a wrong formula would have passed in both places.
Refs: #1096
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
* test(autoware_kalman_filter): drop trivial init getter/setter test (#88)
interimadd flagged the two-argument init test as covering only
straightforward getters/setters and empty values, with no logic to
break. The follow-up commit had reworked it into
init_state_cov_feed_into_filter_math, but it still ultimately exercises
init() storing x/P round-tripped through getters, so it adds little
value. Remove it entirely per the reviewer's request.
The remaining tests already assert against hand-computed numeric
literals independent of the SUT (update_matches_closed_form_with_correlated_covariance)
and check only the boolean return of updateWithDelay for rejection
paths, so the other two review points are already satisfied on the PR
head.
Refs: #1096
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
* fix(autoware_kalman_filter): log LLT failure in update() like updateWithDelay
Address review: KalmanFilter::update() rejected non-positive-definite innovation
covariance silently (returned false with no message), an observability asymmetry
with TimeDelayKalmanFilter::updateWithDelay. Emit the same std::cerr diagnostic so
a caller that gets false can tell why the update was rejected.
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
---------
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>1 parent a0c2180 commit a451577
3 files changed
Lines changed: 291 additions & 31 deletions
File tree
- common/autoware_kalman_filter
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
98 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
| |||
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
131 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
132 | 154 | | |
133 | 155 | | |
134 | 156 | | |
135 | 157 | | |
136 | 158 | | |
137 | | - | |
138 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
139 | 162 | | |
140 | 163 | | |
141 | 164 | | |
| |||
Lines changed: 209 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
21 | 36 | | |
22 | 37 | | |
23 | 38 | | |
| |||
46 | 61 | | |
47 | 62 | | |
48 | 63 | | |
49 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
50 | 67 | | |
51 | 68 | | |
52 | 69 | | |
53 | 70 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 71 | + | |
58 | 72 | | |
59 | 73 | | |
60 | 74 | | |
61 | 75 | | |
62 | 76 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
67 | 81 | | |
68 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
72 | 93 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | 94 | | |
81 | 95 | | |
82 | 96 | | |
83 | 97 | | |
84 | 98 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
91 | 103 | | |
| 104 | + | |
| 105 | + | |
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
| |||
97 | 111 | | |
98 | 112 | | |
99 | 113 | | |
100 | | - | |
101 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
102 | 117 | | |
103 | | - | |
104 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
105 | 287 | | |
106 | 288 | | |
107 | 289 | | |
| |||
0 commit comments