def test_jacobian_self_ominus_other_compact(self): """Test that the ``jacobian_self_ominus_other_wrt_self_compact`` and ``jacobian_self_ominus_other_wrt_other_compact`` methods are correctly implemented. """ np.random.seed(0) for _ in range(10): p1 = PoseSE3(np.random.random_sample(3), np.random.random_sample(4)) p2 = PoseSE3(np.random.random_sample(3), np.random.random_sample(4)) p1.normalize() p2.normalize() v1 = Vertex(1, p1) v2 = Vertex(2, p2) e = EdgeOMinusCompact([1, 2], np.eye(7), np.zeros(7), [v1, v2]) numerical_jacobians = BaseEdge.calc_jacobians(e) analytical_jacobians = e.calc_jacobians() self.assertEqual(len(numerical_jacobians), len(analytical_jacobians)) for n, a in zip(numerical_jacobians, analytical_jacobians): self.assertAlmostEqual(np.linalg.norm(n - a), 0., 5)
def test_calc_jacobians(self): """Test that the ``calc_jacobians`` method works as expected. """ p1 = PoseR2([1, 2]) p2 = PoseR2([3, 4]) estimate = PoseR2([0, 0]) v1 = Vertex(1, p1) v2 = Vertex(2, p2) e = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2]) jacobians = e.calc_jacobians() self.assertAlmostEqual(np.linalg.norm(jacobians[0] - np.eye(2)), 0.) self.assertAlmostEqual(np.linalg.norm(jacobians[1] + np.eye(2)), 0.)
def test_plot(self): """Test that the ``plot`` method is not implemented. """ v_none = Vertex(0, None) v_r2 = Vertex(1, PoseR2([1, 2])) v_se2 = Vertex(2, PoseSE2([1, 2], 3)) v_r3 = Vertex(3, PoseR3([1, 2, 3])) v_se3 = Vertex(4, PoseSE3([1, 2, 3], [0.5, 0.5, 0.5, 0.5])) with self.assertRaises(NotImplementedError): e = EdgeOdometry(0, 1, 0, [v_none, v_none]) e.plot() for v in [v_r2, v_se2, v_r3, v_se3]: e = EdgeOdometry(0, 1, 0, [v, v]) e.plot()
def test_calc_chi2(self): """Test that the ``calc_chi2`` method works as expected. """ p = PoseSE2([0, 0], 0) v = Vertex(0, p) e = SimpleEdge(0, 1, 0, [v]) self.assertEqual(e.calc_chi2(), 1)
def test_constructor(self): """Test that a ``Vertex`` object can be created. """ v = Vertex(1, PoseSE2([1, 2], 3)) self.assertEqual(v.id, 1) self.assertAlmostEqual( np.linalg.norm(v.pose.to_array() - np.array([1., 2., 3.])), 0.)
def test_calc_error(self): """Test that the ``calc_error`` method is not implemented. """ p = PoseSE2([0, 0], 0) v = Vertex(0, p) e = BaseEdge(0, 1, 0, [v]) with self.assertRaises(NotImplementedError): _ = e.calc_error()
def test_constructor(self): """Test that a ``BaseEdge`` object can be created. """ p = PoseSE2([0, 0], 0) v = Vertex(0, p) e = BaseEdge(0, 1, 0, [v]) self.assertEqual(e.vertices[0].id, 0) self.assertEqual(e.information, 1)
def test_plot(self): """Test that the ``plot`` method is not implemented. """ p = PoseSE2([0, 0], 0) v = Vertex(0, p) e = BaseEdge(0, 1, 0, [v]) with self.assertRaises(NotImplementedError): e.plot()
def setUp(self): r"""Setup a simple ``Graph`` in :math:`\mathbb{R}^2`. """ np.random.seed(0) p1 = PoseR2(np.random.random_sample(2)) p2 = PoseR2(np.random.random_sample(2)) p3 = PoseR2(np.random.random_sample(2)) estimate = PoseR2([0, 0]) v1 = Vertex(1, p1) v2 = Vertex(2, p2) v3 = Vertex(3, p3) e1 = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2]) e2 = EdgeOdometry([3, 2], 2 * np.eye(2), estimate, [v3, v2]) self.g = Graph([e1, e2], [v1, v2, v3])
def test_jacobian_self_oplus_other(self): """Test that the ``jacobian_self_oplus_other_wrt_self`` and ``jacobian_self_oplus_other_wrt_other`` methods are correctly implemented. """ np.random.seed(0) for _ in range(10): p1 = PoseR2(np.random.random_sample(2)) p2 = PoseR2(np.random.random_sample(2)) v1 = Vertex(1, p1) v2 = Vertex(2, p2) e = EdgeOPlus([1, 2], np.eye(2), np.zeros(2), [v1, v2]) numerical_jacobians = BaseEdge.calc_jacobians(e) analytical_jacobians = e.calc_jacobians() self.assertEqual(len(numerical_jacobians), len(analytical_jacobians)) for n, a in zip(numerical_jacobians, analytical_jacobians): self.assertAlmostEqual(np.linalg.norm(n - a), 0.)
def test_calc_chi2_gradient_hessian(self): """Test that the ``calc_chi2_gradient_hessian`` method works as expected. """ p1 = PoseR2([1, 3]) p2 = PoseR2([2, 4]) estimate = PoseR2([0, 0]) v1 = Vertex(0, p1, 0) v2 = Vertex(1, p2, 1) e = EdgeOdometry([0, 1], np.eye(2), estimate, [v1, v2]) chi2, gradient, hessian = e.calc_chi2_gradient_hessian() self.assertEqual(chi2, 2.) self.assertAlmostEqual(np.linalg.norm(gradient[0] + np.ones(2)), 0.) self.assertAlmostEqual(np.linalg.norm(gradient[1] - np.ones(2)), 0.) self.assertAlmostEqual(np.linalg.norm(hessian[(0, 0)] - np.eye(2)), 0.) self.assertAlmostEqual(np.linalg.norm(hessian[(0, 1)] + np.eye(2)), 0.) self.assertAlmostEqual(np.linalg.norm(hessian[(1, 1)] - np.eye(2)), 0.)
def setUp(self): r"""Setup a simple ``Graph`` in :math:`SE(3)`. """ np.random.seed(0) p1 = PoseSE3(np.random.random_sample(3), np.random.random_sample(4)) p2 = PoseSE3(np.random.random_sample(3), np.random.random_sample(4)) p3 = PoseSE3(np.random.random_sample(3), np.random.random_sample(4)) estimate = PoseSE3([0, 0, 0], [0, 0, 0, 1]) p1.normalize() p2.normalize() p3.normalize() v1 = Vertex(1, p1) v2 = Vertex(2, p2) v3 = Vertex(3, p3) e1 = EdgeOdometry([1, 2], np.eye(6), estimate, [v1, v2]) e2 = EdgeOdometry([3, 2], 2 * np.eye(6), estimate, [v3, v2]) self.g = Graph([e1, e2], [v1, v2, v3])
def test_plot(self): """Test that a ``Vertex`` can be plotted. """ v_none = Vertex(0, None) v_r2 = Vertex(1, PoseR2([1, 2])) v_se2 = Vertex(2, PoseSE2([1, 2], 3)) v_r3 = Vertex(3, PoseR3([1, 2, 3])) v_se3 = Vertex(4, PoseSE3([1, 2, 3], [0.5, 0.5, 0.5, 0.5])) with self.assertRaises(NotImplementedError): v_none.plot() for v in [v_r2, v_se2, v_r3, v_se3]: fig = plt.figure() if len(v.pose.position) == 3: fig.add_subplot(111, projection='3d') v.plot()