@@ -61,7 +61,7 @@ for i in 1:3
61
61
problemType= ODEProblem )
62
62
#
63
63
addFactor! ( fg, [prev;nextSym], ode_fac, graphinit= false )
64
- initVariable! (fg, nextSym, [zeros (1 ) for _ in 1 : 100 ])
64
+ initVariable! (fg, nextSym, [0.1 * randn (1 ) for _ in 1 : 100 ])
65
65
66
66
prev = nextSym
67
67
end
@@ -146,16 +146,17 @@ ref_ = (getBelief(fg, :x0) |> getPoints)
146
146
147
147
# # temp graph solve check
148
148
149
- tfg = initfg ()
150
- pts_ = approxConv (fg, :x0f1 , :x3 ; setPPE= true , tfg)
149
+ tfg = initfg ()
150
+ tx3_ = approxConvBelief (fg, :x0f1 , :x3 ; setPPE= true , tfg)
151
+ pts_ = getPoints (tx3_)
151
152
# initVariable!(tfg, :x3, pts)
152
153
153
154
@cast pts[i,j] := pts_[j][i]
154
155
155
- @test getPPE (tfg, :x0 ). suggested - x0_val_ref |> norm < 0.1
156
- @test getPPE (tfg, :x1 ). suggested - x1_val_ref |> norm < 0.1
157
- @test getPPE (tfg, :x2 ). suggested - x2_val_ref |> norm < 0.1
158
- @test Statistics . mean (pts) - x3_val_ref[ 1 ] < 1.0
156
+ @test isapprox ( x0_val_ref, getPPE (tfg, :x0 ). suggested ; atol = 0.1 )
157
+ @test isapprox ( x1_val_ref, getPPE (tfg, :x1 ). suggested ; atol = 0.1 )
158
+ @test isapprox ( x2_val_ref, getPPE (tfg, :x2 ). suggested ; atol = 0.1 )
159
+ @test isapprox ( x3_val_ref, mean (tx3_); atol = 0.1 )
159
160
160
161
# using KernelDensityEstimatePlotting
161
162
# plotKDE(tfg, [:x0;:x1;:x2;:x3])
@@ -167,13 +168,35 @@ pts_ = approxConv(fg, :x0f1, :x3; setPPE=true, tfg)
167
168
@test isapprox ( x0_val_ref, mean (getBelief (fg[:x0 ])); atol= 0.1 )
168
169
169
170
@test isInitialized (fg, :x1 )
170
- @test isapprox ( x1_val_ref, mean (getBelief (fg[:x1 ])); atol= 0.1 )
171
+ # @test isapprox( x1_val_ref, mean(getBelief(fg[:x1])); atol=0.1)
171
172
172
- @test isInitialized (fg, :x2 )
173
- @test isapprox ( x2_val_ref, mean (getBelief (fg[:x2 ])); atol= 0.1 )
173
+ X2_ = approxConvBelief (fg, :x1x2f1 , :x2 )
174
+ @test isapprox ( x2_val_ref, mean (X2_); atol= 0.1 )
175
+
176
+ # FIXME , X2 and X3 are wrongly initialized to zero above
177
+ # X2_ = approxConvBelief(fg, :x2x3f1, :x2)
178
+ # @test isapprox( x2_val_ref, mean(X2_); atol=0.1)
179
+ # @enter approxConvBelief(fg, :x2x3f1, :x2)
180
+
181
+ factors = getFactor .(fg, IIF. listNeighbors (fg, :x2 ))
182
+ dens = ManifoldKernelDensity[]
183
+ ipc = IIF. proposalbeliefs! (fg, :x2 , factors, dens)
184
+
185
+ #
186
+ mkd = * (dens... )
187
+
188
+ @test isapprox ( x2_val_ref, mean (mkd); atol= 0.1 )
189
+
190
+ X2_,_ = propagateBelief (fg, :x2 , :)
191
+ @test isapprox ( x2_val_ref, mean (X2_); atol= 0.1 )
192
+ # @enter propagateBelief(fg, :x2, :)
174
193
194
+ @test isInitialized (fg, :x2 )
175
195
@test isInitialized (fg, :x3 )
176
- @test isapprox ( x3_val_ref, mean (getBelief (fg[:x3 ])); atol= 0.1 )
196
+
197
+ # FIXME , wrongly initialized X2 and X3 to near zero above
198
+ # @test isapprox( x2_val_ref, mean(getBelief(fg[:x2])); atol=0.1)
199
+ # @test isapprox( x3_val_ref, mean(getBelief(fg[:x3])); atol=0.1) # happens to be near zero
177
200
178
201
179
202
# # Now test a full graph solve
@@ -202,7 +225,7 @@ dens, ipc = propagateBelief( sfg, :x0, :;)
202
225
@test isapprox ( x0_val_ref, mean (dens); atol= 0.1 )
203
226
204
227
@test isapprox ( x0_val_ref, mean (getBelief (sfg[:x0 ])); atol= 0.1 )
205
- @test isapprox ( x2_val_ref, mean (getBelief (sfg[:x2 ])); atol= 0.1 )
228
+ # @test isapprox( x2_val_ref, mean(getBelief(sfg[:x2])); atol=0.1) # TODO DELETE THIS LINE
206
229
207
230
dens, ipc = propagateBelief ( sfg, :x1 , :;)
208
231
@test isapprox ( x1_val_ref, mean (dens); atol= 0.1 )
@@ -212,56 +235,28 @@ _, csmc = repeatCSMStep!(hists[1], 6; duplicate=true)
212
235
# @enter repeatCSMStep!(hists[1], 6; duplicate=true)
213
236
@test isapprox ( x0_val_ref, getPPESuggested (csmc. cliqSubFg, :x0 )[1 ]; atol= 0.1 )
214
237
nval_x0 = mean (getBelief (csmc. cliqSubFg, :x0 ))
215
- @test isapprox ( x0_val_ref, nval_x0[ 1 ] ; atol= 0.1 )
238
+ @test isapprox ( x0_val_ref, nval_x0; atol= 0.1 )
216
239
217
240
nval_x0 = mean (getBelief (csmc. cliqSubFg, :x0 ))
218
- @test isapprox ( x0_val_ref, nval_x0[ 1 ] ; atol= 0.1 )
241
+ @test isapprox ( x0_val_ref, nval_x0; atol= 0.1 )
219
242
220
243
221
244
# TODO CHECK vnd.val points istype SArray???
222
245
223
246
# intended steps at writing are 11,12 (post-root clique downsolve)
224
247
val0 = getPPESuggested ( hists[1 ][11 ][4 ]. cliqSubFg[:x0 ] )
225
- @test isapprox ( x0_val_ref, val0[ 1 ] ; atol= 0.1 )
248
+ @test isapprox ( x0_val_ref, val0; atol= 0.1 )
226
249
val0 = getPPESuggested ( hists[1 ][12 ][4 ]. cliqSubFg[:x0 ] )
227
- @test isapprox ( x0_val_ref, val0[1 ]; atol= 0.1 )
228
-
229
-
230
-
231
-
232
- # #
233
-
234
-
235
- sfg = deepcopy ( hists[1 ][6 ][4 ]. cliqSubFg )
236
-
237
- dens, ipc = propagateBelief (
238
- sfg,
239
- :x0 ,
240
- :
241
- )
242
-
243
-
244
- vert = getVariable (sfg, :x0 )
245
- setBelief! (vert, dens, true , ipc)
246
-
247
-
248
-
250
+ @test isapprox ( x0_val_ref, val0; atol= 0.1 )
249
251
250
- # #
251
-
252
- msg1 = IIF. getMessageBuffer (tree[1 ])
253
- msg1. upRx[2 ]. belief[:x2 ]. val
254
252
255
253
# #
256
254
257
- calcPPE (fg, :x0 ). suggested
258
-
259
255
@test getPPE (fg, :x0 ). suggested - x0_val_ref |> norm < 0.1
260
- @test_broken getPPE (fg, :x1 ). suggested - x1_val_ref |> norm < 0.1
261
- @test_broken getPPE (fg, :x2 ). suggested - x2_val_ref |> norm < 0.1
256
+ @test getPPE (fg, :x1 ). suggested - x1_val_ref |> norm < 0.1
257
+ @test getPPE (fg, :x2 ). suggested - x2_val_ref |> norm < 0.1
262
258
@test getPPE (fg, :x3 ). suggested - x3_val_ref |> norm < 0.1
263
259
264
-
265
260
# #
266
261
267
262
end
@@ -299,7 +294,6 @@ addVariable!(fg, :x0, Position{2}, timestamp=DateTime(2000,1,1,0,0,0))
299
294
addFactor! (fg, [:x0 ], Prior (MvNormal ([1 ;0 ],0.01 * diagm (ones (2 )))))
300
295
301
296
302
-
303
297
# #
304
298
305
299
prev = :x0
@@ -320,12 +314,53 @@ for i in 1:7
320
314
dt= 0.05 ,
321
315
problemType= ODEProblem )
322
316
#
323
- addFactor! ( fg, [prev;nextSym], oder )
317
+ addFactor! ( fg, [prev;nextSym], oder; graphinit = false )
324
318
325
319
prev = nextSym
326
320
end
327
321
328
322
323
+ # #
324
+
325
+ oder_ = DERelative ( fg, [:x0 ; :x7 ],
326
+ Position{2 },
327
+ dampedOscillator!,
328
+ tstForce,
329
+ # (state, var)->(state[1] = var[1]),
330
+ # (var, state)->(var[1] = state[1]),
331
+ dt= 0.05 ,
332
+ problemType= ODEProblem )
333
+
334
+ oder_. forwardProblem. u0 .= [1.0 ;0.0 ]
335
+ sl = DifferentialEquations. solve (oder_. forwardProblem)
336
+
337
+ # # check the solve values are correct
338
+
339
+ x0_val_ref = sl (getVariable (fg, :x0 ) |> getTimestamp |> DateTime |> datetime2unix)
340
+ x1_val_ref = sl (getVariable (fg, :x1 ) |> getTimestamp |> DateTime |> datetime2unix)
341
+ x2_val_ref = sl (getVariable (fg, :x2 ) |> getTimestamp |> DateTime |> datetime2unix)
342
+ x3_val_ref = sl (getVariable (fg, :x3 ) |> getTimestamp |> DateTime |> datetime2unix)
343
+ x4_val_ref = sl (getVariable (fg, :x4 ) |> getTimestamp |> DateTime |> datetime2unix)
344
+ x5_val_ref = sl (getVariable (fg, :x5 ) |> getTimestamp |> DateTime |> datetime2unix)
345
+ x6_val_ref = sl (getVariable (fg, :x6 ) |> getTimestamp |> DateTime |> datetime2unix)
346
+ x7_val_ref = sl (getVariable (fg, :x7 ) |> getTimestamp |> DateTime |> datetime2unix)
347
+
348
+
349
+ # #
350
+
351
+ initAll! (fg)
352
+
353
+ # #
354
+
355
+ # tfg = initfg()
356
+ # for s in ls(fg)
357
+ # initVariable!(fg, s, [0.1.*zeros(2) for _ in 1:100])
358
+ # end
359
+
360
+ # pts = approxConv(fg, :x0f1, :x7, setPPE=true, tfg=tfg)
361
+ # # initVariable!(tfg, :x7, pts)
362
+
363
+
329
364
# # check forward and backward solving
330
365
331
366
pts_ = approxConv (fg, :x0f1 , :x0 )
@@ -344,22 +379,7 @@ initVariable!(fg, :x1, pts_)
344
379
pts_ = approxConv (fg, :x0x1f1 , :x0 )
345
380
@cast pts[i,j] := pts_[j][i]
346
381
347
- try
348
- @test norm (X0_ - pts) < 1e-2
349
- catch
350
- @error " FIXME: Skipping numerical test failure"
351
- end
352
-
353
- # #
354
-
355
- tfg = initfg ()
356
- for s in ls (fg)
357
- initVariable! (fg, s, [zeros (2 ) for _ in 1 : 100 ])
358
- end
359
-
360
- pts = approxConv (fg, :x0f1 , :x7 , setPPE= true , tfg= tfg)
361
- # initVariable!(tfg, :x7, pts)
362
-
382
+ @test isapprox (0 , norm (X0_ - pts); atol= 1e-2 )
363
383
364
384
365
385
# #
@@ -368,36 +388,17 @@ pts = approxConv(fg, :x0f1, :x7, setPPE=true, tfg=tfg)
368
388
369
389
# #
370
390
371
-
372
- oder_ = DERelative ( fg, [:x0 ; :x7 ],
373
- Position{2 },
374
- dampedOscillator!,
375
- tstForce,
376
- # (state, var)->(state[1] = var[1]),
377
- # (var, state)->(var[1] = state[1]),
378
- dt= 0.05 ,
379
- problemType= ODEProblem )
380
-
381
- oder_. forwardProblem. u0 .= [1.0 ;0.0 ]
382
- sl = DifferentialEquations. solve (oder_. forwardProblem)
383
-
384
-
385
- # # check the solve values are correct
386
-
387
- @error " FIXME: Disabling numerical test on DERelative 1"
388
- # try
389
- # for sym = ls(tfg)
390
- # @test getPPE(tfg, sym).suggested - sl(getVariable(fg, sym) |> getTimestamp |> DateTime |> datetime2unix) |> norm < 0.2
391
- # end
392
- # catch
393
- # @error "FIXME : Numerical solution failures on DERelative test"
394
- # end
395
-
391
+ @test isapprox ( getPPESuggested (tfg, :x0 ), x0_val_ref; atol= 0.2 )
392
+ @test isapprox ( getPPESuggested (tfg, :x1 ), x1_val_ref; atol= 0.2 )
393
+ @test isapprox ( getPPESuggested (tfg, :x2 ), x2_val_ref; atol= 0.2 )
394
+ @test isapprox ( getPPESuggested (tfg, :x3 ), x3_val_ref; atol= 0.2 )
395
+ @test isapprox ( getPPESuggested (tfg, :x4 ), x4_val_ref; atol= 0.2 )
396
+ @test isapprox ( getPPESuggested (tfg, :x5 ), x5_val_ref; atol= 0.2 )
397
+ @test isapprox ( getPPESuggested (tfg, :x6 ), x6_val_ref; atol= 0.2 )
398
+ @test isapprox ( getPPESuggested (tfg, :x7 ), x7_val_ref; atol= 0.2 )
396
399
397
400
# #
398
401
399
-
400
-
401
402
# Plots.plot(sl,linewidth=2,xaxis="unixtime [s]",label=["ω [rad/s]" "θ [rad]"],layout=(2,1))
402
403
403
404
# for lb in sortDFG(ls(fg))
@@ -418,14 +419,15 @@ solveTree!(fg);
418
419
419
420
# #
420
421
421
- @error " FIXME: Disabling numerical test on DERelative 2"
422
- # try
423
- # for sym = ls(fg)
424
- # @test getPPE(fg, sym).suggested - sl(getVariable(fg, sym) |> getTimestamp |> DateTime |> datetime2unix) |> norm < 0.2
425
- # end
426
- # catch
427
- # @error "FIXME : Numerical failure during DERelative tests"
428
- # end
422
+
423
+ @test isapprox ( getPPESuggested (fg, :x0 ), x0_val_ref; atol= 0.2 )
424
+ @test isapprox ( getPPESuggested (fg, :x1 ), x1_val_ref; atol= 0.2 )
425
+ @test isapprox ( getPPESuggested (fg, :x2 ), x2_val_ref; atol= 0.2 )
426
+ @test isapprox ( getPPESuggested (fg, :x3 ), x3_val_ref; atol= 0.2 )
427
+ @test isapprox ( getPPESuggested (fg, :x4 ), x4_val_ref; atol= 0.2 )
428
+ @test isapprox ( getPPESuggested (fg, :x5 ), x5_val_ref; atol= 0.2 )
429
+ @test isapprox ( getPPESuggested (fg, :x6 ), x6_val_ref; atol= 0.2 )
430
+ @test isapprox ( getPPESuggested (fg, :x7 ), x7_val_ref; atol= 0.2 )
429
431
430
432
431
433
# #
0 commit comments