def test_register_scan(self): """Test the generation of global hypotheses.""" self.tracker.register_scan( mht.Scan(mht.sensors.EyeOfMordor(3, 12), [ mht.Report(np.array([8.0, 8.0]), np.eye(2), mht.models.position_measurement), mht.Report(np.array([2.0, 2.0]), np.eye(2), mht.models.position_measurement) ]))
def test_correct(self): """Correction step.""" z = np.array([2.0] * 2) R = np.eye(2) m = mht.Report(z, R, mht.models.velocity_measurement) self.target.correct(m) self.assertAlmostEqual(self.target.x[1], 0.0) self.assertAlmostEqual(self.target.x[2], 1.0) self.assertAlmostEqual(self.target.x[3], 1.0)
def test_icetracking(self): """Icetracking.""" pos = run_kmeans(image('grd')) scan = [ mht.Report( np.matrix([[plat], [plon]]), np.eye(2) * 1e-4, mht.models.position_measurement) for plat, plon in zip(pos[0], pos[1]) ] for t in range(2): t0 = time.time() self.tracker.register_scan( mht.Scan(mht.sensors.EyeOfMordor(5, 10, 12), scan)) t1 = time.time() print(t, ': Ran tracker in', t1 - t0, 'seconds to generate', len(self.tracker.global_hypotheses), 'hypotheses')
def test_track(self): """Test repeated updates from moving targets.""" targets = [ np.array([0.0, 0.0, 1.0, 1.0]), np.array([0.0, 10.0, 1.0, -1.0]) ] for t in range(3): if t > 0: self.tracker.predict(1) for t in targets: t[0:2] += t[2:] reports = { mht.Report( np.random.multivariate_normal(t[0:2], np.diag([0.1, 0.1])), # noqa # t[0:2], np.eye(2) * 0.001, mht.models.position_measurement, i) for i, t in enumerate(targets) } self.tracker.register_scan( mht.Scan(mht.sensors.EyeOfMordor(3, 12), reports))
def draw(): """Create plot.""" tracker = mht.MHT(cparams=mht.ClusterParameters(k_max=100, nll_limit=4, hp_limit=5), matching_algorithm="naive") targets = [ np.array([0.0, 0.0, 1.0, 1.0]), np.array([0.0, 10.0, 1.0, -1.0]), ] hyps = None nclusters = [] ntargets_true = [] ntargets = [] nhyps = [] for k in range(25): if k > 0: tracker.predict(1) for t in targets: t[0:2] += t[2:] if k == 5: targets.append(np.array([5.0, 5.0, 1.0, 0.0])) if k % 7 == 0: targets.append( np.random.multivariate_normal(np.array([k, 7.0, 0.0, 0.0]), np.diag([0.5] * 4))) if k % 7 == 1: del targets[-1] if k == 10: targets.append(np.array([10.0, -30.0, 1.0, -0.5])) if k == 20: targets.append(np.array([k, 0.0, 1.0, 4.0])) reports = { mht.Report( np.random.multivariate_normal(t[0:2], np.diag([0.1, 0.1])), # noqa # t[0:2], np.eye(2) * 0.001, mht.models.position_measurement, i) for i, t in enumerate(targets) } this_scan = mht.Scan(mht.sensors.EyeOfMordor(10, 3), reports) tracker.register_scan(this_scan) hyps = list(tracker.global_hypotheses()) nclusters.append(len(tracker.active_clusters)) ntargets.append(len(hyps[0].targets)) ntargets_true.append(len(targets)) nhyps.append(len(hyps)) mht.plot.plot_scan(this_scan) plt.plot([t[0] for t in targets], [t[1] for t in targets], marker='D', color='y', alpha=.5, linestyle='None') mht.plot.plot_hyptrace(hyps[0], covellipse=True) mht.plot.plt.axis([-1, k + 1, -k - 1, k + 1 + 10]) mht.plot.plt.ylabel('Tracks') mht.plot.plt.figure() mht.plot.plt.subplot(3, 1, 1) mht.plot.plt.plot(nclusters) mht.plot.plt.axis([-1, k + 1, min(nclusters) - 0.1, max(nclusters) + 0.1]) mht.plot.plt.ylabel('# Clusters') mht.plot.plt.subplot(3, 1, 2) mht.plot.plt.plot(ntargets, label='Estimate') mht.plot.plt.plot(ntargets_true, label='True') mht.plot.plt.ylabel('# Targets') mht.plot.plt.legend() mht.plot.plt.axis([ -1, k + 1, min(ntargets + ntargets_true) - 0.1, max(ntargets + ntargets_true) + 0.1 ]) mht.plot.plt.subplot(3, 1, 3) mht.plot.plt.plot(nhyps) mht.plot.plt.axis([-1, k + 1, min(nhyps) - 0.1, max(nhyps) + 0.1]) mht.plot.plt.ylabel('# Hyps')
def draw(): """Create plot.""" tracker = mht.MHT(cparams=mht.ClusterParameters(k_max=100, hp_limit=5), matching_algorithm="naive") target_centroids = [ ([0.0, 0.0, 1.0, 1.0], np.diag([1, 1, 0.3, 0.3]), 15), ([100.0, 100.0, -1.0, -1.0], np.diag([1, 1, 0.3, 0.3]), 5), # noqa ([0.0, 70.0, 1.0, 0.0], np.diag([1, 1, 0.3, 0.3]), 0), ([50.0, 50.0, 0.0, 0.0], np.diag([4, 4, 0.3, 0.3]), 0), # noqa ] clutter_centroids = [ ([0.0, 0.0, 50.0, 50.0], np.diag([70, 70, 1, 1]), 1), ] sensors = [ mht.sensors.Satellite((-10, 40, -10, 40), 3, 3), mht.sensors.Satellite((45, 120, 0, 40), 3, 3), mht.sensors.Satellite((35, 120, 45, 120), 3, 3), mht.sensors.Satellite((-10, 30, 55, 120), 3, 3), ] targets = [ np.random.multivariate_normal(c[0], c[1]) for c in target_centroids for _ in range(c[2]) ] mlhyp = None nclusters = [] ntargets_true = [] ntargets = [] nhyps = [] for k in range(35): # print() # print() print("k:", k) if k > 0: tracker.predict(1) for t in targets: t[0:2] += t[2:] clutter = [ np.random.multivariate_normal(c[0], c[1]) for c in clutter_centroids for _ in range(c[2]) ] reports = { mht.Report( np.random.multivariate_normal(t[0:2], np.diag([0.1, 0.1])), # noqa # t[0:2], np.eye(2) * 0.001, mht.models.position_measurement, i) for i, t in enumerate(targets) } false_reports = { mht.Report( np.random.multivariate_normal(t[0:2], np.diag([0.1, 0.1])), # noqa np.eye(2) * 0.3, mht.models.position_measurement) for t in clutter } ntt = 0 for s in sensors: sr = {r for r in reports if s.in_fov(r.z[0:2])} fsr = {r for r in false_reports if s.in_fov(r.z[0:2])} ntt += len(sr) reports -= sr this_scan = mht.Scan(s, list(sr | fsr)) # mht.plot.plot_scan(this_scan) tracker.register_scan(this_scan) tracker._load_clusters() mlhyp = next(tracker.global_hypotheses()) nclusters.append(len(tracker.active_clusters)) ntargets.append(len(mlhyp.targets)) ntargets_true.append(len(targets)) nhyps.append( reduce(operator.mul, (len(c.hypotheses) for c in tracker.active_clusters))) plt.plot([t[0] for t in targets], [t[1] for t in targets], marker='D', color='y', alpha=.5, linestyle='None') plt.plot([t[0] for t in targets], [t[1] for t in targets], marker='D', color='y', alpha=.5, linestyle='None') mht.plot.plot_hyptrace(mlhyp, covellipse=False) mht.plot.plot_hypothesis(mlhyp, cseed=2) mht.plot.plt.axis([-30, 150, -30, 150]) mht.plot.plt.ylabel('Tracks') for s in sensors: mht.plot.plot_bbox(s) tracker._load_clusters() print("Clusters:", len(tracker.active_clusters)) for c in tracker.active_clusters: mht.plot.plot_bbox(c)