def test_FormationTrack(self): PD=0.7 PFD=1.e-3 NFC=4 NFA=1000 model_factory = models.SimpleModelFactory( model = models.KalmanModel, dT=1.0, q=0.001 ) sensor = sensors.BaseSensor( PD=PD, VC=1.0, PFA=1e-6, BNT=0.03 ) # assign 1 track obs = models.Obs(np.array([1.0, 2.0]), np.eye(2), sensor ) trk = tracks.FormationTrack(obs,model_factory.create(obs)) # assign 2 track obs = models.Obs(np.array([3.0, 4.0]), np.eye(2), sensor ) trk = tracks.FormationTrack(obs,model_factory.create(obs))
def test_TrackerEvaluator(self): eval = trackers.TrackerEvaluator( tracker=trackers.GNN(sensor=sensors.BaseSensor(R=np.diag( [0.001, 0.001]), PD=0.7, VC=1.0, PFA=1e-6, BNT=0.03, y_mins=[-250, -250], y_maxs=[+250, +250], y_stps=[1, 1]), model_factory=models.SimpleModelFactory( model=models.KalmanModel, dT=1.0, q=1.0), track_factory=tracks.BaseTrackFactory( track=tracks.ScoreManagedTrack)), tgt_list=[ models.SimpleTarget(SD=2, x0=[0., 0., +0., +1.], start_time=0.0), models.SimpleTarget(SD=2, x0=[0., 10., +1., -1.], start_time=0.0), models.SimpleTarget(SD=2, x0=[10., 10., -1., -1.], start_time=0.0), models.SimpleTarget(SD=2, x0=[10., 0., +0., +1.], start_time=1.0) ]) # eval.plot_position() eval.estimate_track_statistics()
def test_SimpleManagedTrack(self): ND=3 tracker = MockTracker( sensor=sensors.BaseSensor( PD=0.7, VC=1.0, PFA=1e-6, BNT=0.03 ), model_factory=models.SimpleModelFactory( model=models.KalmanModel, dT=1.0, q=0.001 ) ) tgt = np.array([0.0, 0.0, 1.0, 1.0]) for k in range(200): tracker.count = k if k==0: obs = models.Obs(tgt[:2], np.eye(2), tracker.sensor ) trk = tracks.SimpleManagedTrack( obs, tracker.model_factory.create(obs), ND=ND ) if 0 < k <= 100: tgt[0:2] += tgt[2:] trk.assign(models.Obs( # tgt[:2], np.eye(2), tracker.sensor np.random.multivariate_normal(tgt[:2], np.eye(2)), np.eye(2), tracker.sensor )) if 100 < k: trk.unassign(tracker.sensor) # judge_deletion test if 0 <= k < 100+ND: np.testing.assert_equal(trk.judge_deletion(), False) pass elif 100+ND <= k: np.testing.assert_equal(trk.judge_deletion(), True) pass # after loop if False: # trk.plot_obs_list() # trk.plot_mdl_list() plt.show()
def test_SimpleModelFactory(self): # to_record/from_record check mf = models.SimpleModelFactory(model=models.KalmanModel, dT=1.0, q=1.0) mdl1 = mf.create( models.Obs(y=np.array([1, 0]), R=np.zeros((2, 2)) + 0.1, sensor=sensors.BaseSensor())) series = mdl1.to_record() mdl2 = mf.create_from_record(series)
def test_GNN(self): tracker = trackers.GNN(sensor=sensors.BaseSensor(PD=0.7, VC=1.0, PFA=1e-6, BNT=0.03), model_factory=models.SimpleModelFactory( model=models.KalmanModel, dT=1.0, q=0.001), track_factory=tracks.BaseTrackFactory( track=tracks.ScoreManagedTrack)) tgt_list = [ np.array([-1, 1]), np.array([20, 36]), ] tracker.register_scan([models.Obs(y, np.eye(2) * 5) for y in tgt_list]) tgt_list = [ np.array([0, 0]), np.array([19, 37]), np.array([40, 50]), ] tracker.register_scan([models.Obs(y, np.eye(2) * 5) for y in tgt_list])
def test_ScoreManagedTrack(self): """Track Score Function ref) Design and Analysis of Modern Tracking Systems 6.2 Track Score Function """ PD=0.7 PFD=1.e-3 NFC=4 NFA=1000 tracker = MockTracker( sensor=sensors.BaseSensor( PD=PD, VC=1.0, PFA=1e-6, BNT=0.03 ), model_factory=models.SimpleModelFactory( model=models.KalmanModel, dT=1.0, q=0.001 ) ) tgt = np.array([0.0, 0.0, 1.0, 1.0]) com_list = [] del_list = [] for k in range(200): tracker.count = k if k==0: obs = models.Obs(tgt[:2], np.eye(2), tracker.sensor ) trk = tracks.ScoreManagedTrack( obs, tracker.model_factory.create(obs), PFD=PFD, alpha=NFC/3600/NFA, beta=0.1 ) if 0 < k <= 100: tgt[0:2] += tgt[2:] obs = models.Obs( # tgt[:2], np.eye(2), tracker.sensor np.random.multivariate_normal(tgt[:2], np.eye(2)), np.eye(2), tracker.sensor ) if np.random.choice([True, False], p=[PD, 1-PD]): trk.assign(obs) else: trk.unassign(tracker.sensor) if 100 < k: trk.unassign(tracker.sensor) com_list.append(trk.judge_confirmation()) del_list.append(trk.judge_deletion()) # after loop if False: # trk.plot_obs_list() # trk.plot_mdl_list() # trk.plot_scr_list() plt.plot([i for i in range(200)], np.array(com_list, int) - np.array(del_list, int)) plt.show()
def test_JPDA(self): """Calculate Association of Observations by JPDA Method ref) Design and Analysis of Modern Tracking Systems 6.6.2 Extension to JPDA """ tracker = trackers.JPDA( sensor=sensors.BaseSensor(PD=0.7, VC=1.0, PFA=1e-6, BNT=0.03), model_factory=models.SimpleModelFactory( model=models.PDAKalmanModel, dT=1.0, q=0.0), track_factory=tracks.BaseTrackFactory(track=tracks.PDATrack, gate=8)) a = 2 x1 = (a**2 + 2 - 2.5) / 2 / a x2 = (a**2 + 4 - 3) / 2 / a obs_list = [ models.Obs(y, np.eye(2) * 0.5) for y in [ np.array([0, 0]), np.array([a, 0]), ] ] tracker.register_scan(obs_list) obs_list = [ models.Obs(y, np.eye(2) * 0.5) for y in [ np.array([-1, 0]), np.array([x1, np.sqrt(2 - x1**2)]), np.array([x2, np.sqrt(4 - x2**2)]), ] ] expected = np.array([1.0, 9.0, 2.0, 2.5, 4.0, 3.0]) actual = np.array([ dy @ np.linalg.inv(S) @ dy for dy, S in [ trk.model.residual(obs) for obs in obs_list for trk in tracker.trk_list ] ]) np.testing.assert_almost_equal(actual, expected) tracker.register_scan(obs_list) expected = np.array([ 6.47e-5, 5.04e-5, 3.06e-5, 1.44e-5, 1.82e-5, 1.11e-5, 8.60e-6, 6.70e-6, 4.10e-6, 2.40e-6, ]) actual = tracker.hyp_price_list np.testing.assert_almost_equal(np.sort(actual), np.sort(expected))