Ejemplo n.º 1
0
def test_se2_g_inv_null_element():
    angle = 0
    tx = 0
    ty = 0

    element = se2.Se2G(angle, tx, ty)
    inverse_element = element.inv()
    expected_inverse_element = se2.Se2G(-angle, -tx, -ty)

    assert_array_almost_equal(inverse_element.get,
                              expected_inverse_element.get)
Ejemplo n.º 2
0
def test_se2_g_comparing_product_restricted_form_and_matrix_form():
    any_angle_1 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx_1 = uniform(-10, 10)
    any_ty_1 = uniform(-10, 10)
    any_angle_2 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx_2 = uniform(-10, 10)
    any_ty_2 = uniform(-10, 10)
    get_matrix_output = \
        (se2.Se2G(any_angle_1, any_tx_1, any_ty_1) * se2.Se2G(any_angle_2, any_tx_2, any_ty_2)).get_matrix
    matrix_product_output = \
        se2.Se2G(any_angle_1, any_tx_1, any_ty_1).get_matrix.dot(
            se2.Se2G(any_angle_2, any_tx_2, any_ty_2).get_matrix)
    assert_array_almost_equal(get_matrix_output, matrix_product_output)
Ejemplo n.º 3
0
def test_se2_g_mul_0_translation():
    any_angle_1 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx_1 = 0
    ty_1 = 0
    any_angle_2 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx_2 = 0
    ty_2 = 0
    expected_output_angle = angles.mod_pipi(any_angle_1 + any_angle_2)
    expected_output_tx = 0
    expected_output_ty = 0
    expected_output = [
        expected_output_angle, expected_output_tx, expected_output_ty
    ]
    given_output = (se2.Se2G(any_angle_1, tx_1, ty_1) *
                    se2.Se2G(any_angle_2, tx_2, ty_2)).get
    assert_array_equal(given_output, expected_output)
Ejemplo n.º 4
0
def test_init_se2_g_random_input():
    any_angle_in_pi_pi = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx = uniform(-10, 10)
    any_ty = uniform(-10, 10)
    assert_array_equal(
        se2.Se2G(any_angle_in_pi_pi, any_tx, any_ty).get,
        [any_angle_in_pi_pi, any_tx, any_ty])
Ejemplo n.º 5
0
def test_theory_inverse_exp_log():
    any_angle_1 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx_1 = uniform(-10, 10)
    any_ty_1 = uniform(-10, 10)
    a = se2.Se2G(any_angle_1, any_tx_1, any_ty_1)
    ans = se2.se2a_exp(se2.se2g_log(a))
    assert_array_almost_equal(a.get, ans.get)
Ejemplo n.º 6
0
def test_se2_g_mul_0_rotation():
    angle_1 = 0
    any_tx_1 = uniform(-10, 10)
    any_ty_1 = uniform(-10, 10)
    angle_2 = 0
    any_tx_2 = uniform(-10, 10)
    any_ty_2 = uniform(-10, 10)
    expected_output_angle = 0
    expected_output_tx = any_tx_1 + any_tx_2
    expected_output_ty = any_ty_1 + any_ty_2
    expected_output = [
        expected_output_angle, expected_output_tx, expected_output_ty
    ]
    given_output = (se2.Se2G(angle_1, any_tx_1, any_ty_1) *
                    se2.Se2G(angle_2, any_tx_2, any_ty_2)).get
    assert_array_equal(given_output, expected_output)
Ejemplo n.º 7
0
def test_se2_g_get_matrix():
    any_angle_in_pi_pi = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx = uniform(-10, 10)
    any_ty = uniform(-10, 10)
    m = se2.Se2G(any_angle_in_pi_pi, any_tx, any_ty).get_matrix
    assert m[0, 0] == m[1, 1] == np.cos(any_angle_in_pi_pi) \
        and -m[0, 1] == m[1, 0] == np.sin(any_angle_in_pi_pi) \
        and m[2, 2] == 1 and m[0, 2] == any_tx and m[1, 2] == any_ty
Ejemplo n.º 8
0
def test_se2_g_log_pade_approx_comparison():
    theta = uniform(-np.pi, np.pi)
    tx = uniform(-5, 5)
    ty = uniform(-5, 5)
    element = se2.Se2G(theta, tx, ty)
    ans_log = se2.se2g_log(element).get_matrix
    ans_pade = lin.logm(element.get_matrix)
    assert_array_almost_equal(ans_log, ans_pade)
Ejemplo n.º 9
0
def test_se2_g_inv_random_element():
    angle = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx = uniform(-10, 10)
    ty = uniform(-10, 10)
    element = se2.Se2G(angle, tx, ty)
    inverse_element = element.inv().get_matrix
    expected = np.linalg.inv(element.get_matrix)
    assert_array_almost_equal(inverse_element, expected)
Ejemplo n.º 10
0
def test_se2_g_inv_in_matrix_product():
    angle = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx = uniform(-10, 10)
    ty = uniform(-10, 10)
    element = se2.Se2G(angle, tx, ty)
    matr = element.get_matrix
    matri_inv = element.inv().get_matrix
    assert_array_almost_equal(matr.dot(matri_inv), np.identity(3))
Ejemplo n.º 11
0
def test_se2_g_norm_standard_random_input():
    angle = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx = uniform(-10, 10)
    ty = uniform(-10, 10)
    lamb = 1.4
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('standard', lamb),
                 np.sqrt(angle**2 + lamb * (tx**2 + ty**2)))
Ejemplo n.º 12
0
def test_se2_g_matrix2se2_g_sane_input():
    theta = uniform(-np.pi, np.pi)
    tx = uniform(-5, 5)
    ty = uniform(-5, 5)
    m = np.array([[np.cos(theta), -np.sin(theta), tx],
                  [np.sin(theta), np.cos(theta), ty], [0, 0, 1]])
    ans = se2.matrix2se2g(m)
    exp_ans = se2.Se2G(theta, tx, ty)
    assert_array_almost_equal(ans.get, exp_ans.get)
Ejemplo n.º 13
0
def test_se2_g_mul_random_input():
    any_angle_1 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx_1 = uniform(-10, 10)
    any_ty_1 = uniform(-10, 10)
    any_angle_2 = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx_2 = uniform(-10, 10)
    any_ty_2 = uniform(-10, 10)
    expected_output_angle = angles.mod_pipi(any_angle_1 + any_angle_2)
    expected_output_tx = any_tx_1 + any_tx_2 * np.cos(
        any_angle_1) - any_ty_2 * np.sin(any_angle_1)
    expected_output_ty = any_ty_1 + any_tx_2 * np.sin(
        any_angle_1) + any_ty_2 * np.cos(any_angle_1)
    expected_output = [
        expected_output_angle, expected_output_tx, expected_output_ty
    ]
    given_output = (se2.Se2G(any_angle_1, any_tx_1, any_ty_1) *
                    se2.Se2G(any_angle_2, any_tx_2, any_ty_2)).get
    assert_array_equal(given_output, expected_output)
Ejemplo n.º 14
0
def test_se2_g_norm_fro_random_input_comparing_matrix_numpy_norm():
    # comparing frobenius with frobenius norm matrix (random matrix
    angle = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx = uniform(-10, 10)
    ty = uniform(-10, 10)
    element = se2.Se2G(angle, tx, ty)
    output_norm = element.norm('fro')
    linalg_norm = np.linalg.norm(element.get_matrix, 'fro')
    global meaningful_decimals
    assert round(np.abs(output_norm - linalg_norm), meaningful_decimals) == 0.0
Ejemplo n.º 15
0
def test_se2_g_log_0_angle():
    theta = 0
    tx = uniform(-5, 5)
    ty = uniform(-5, 5)
    element = se2.Se2G(theta, tx, ty)
    ans_log = se2.se2g_log(element)
    if ans_log.rotation_angle == 0 and ans_log.tx == tx and ans_log.ty == ty:
        assert True
    else:
        assert False
Ejemplo n.º 16
0
def test_se2_g_get_matrix_det():
    any_angle_in_pi_pi = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    any_tx = uniform(-10, 10)
    any_ty = uniform(-10, 10)
    m = se2.Se2G(any_angle_in_pi_pi, any_tx, any_ty).get_matrix
    given_output = np.linalg.det(m)
    expected_output = 1.0
    global meaningful_decimals
    assert round(np.abs(given_output - expected_output),
                 meaningful_decimals) == 0.0
Ejemplo n.º 17
0
def randomgen_linear_by_taste(sigma, taste, center=(0, 0)):
    """
    To create a linear (2D) stationary tangent vector field according to the proposed taste
    classification:
    + Taste 1 : real eigenvalues with positive signs. UNSTABLE NODE
    + Taste 2 : real eigenvalues with negative signs. STABLE NODE
    + Taste 3 : real eigenvalues with opposite signs. SADDLE
    + Taste 4 : complex conjugate with positive real part. OUTWARD SPIRAL
    + Taste 5 : complex conjugate with negative real part. INWARD SPIRAL
    + Taste 6 : complex conjugate with 0 real parts. CIRCLES, Based on se2.Se2G
    :param sigma: how further away going from identity.
    :param taste: int between 1 and 6 as in the classification.
    :param center: (float, float) center of the transformation.
    :return: 3x3 tangent space linear transformation matrix of the shape
            | R | t |
            | - - - |
            | 0 | 0 |
    """
    if taste not in range(1, 7):
        raise IOError('taste must be an integer number between 1 and 6.')

    if taste == 6:
        x_c, y_c = center
        theta = sigma * np.random.randn() + 2 * sigma

        tx = (1 - np.cos(theta)) * x_c + np.sin(theta) * y_c
        ty = -np.sin(theta) * x_c + (1 - np.cos(theta)) * y_c

        m0 = se2.Se2G(theta, tx, ty)
        dm0 = se2.se2g_log(m0)
        return dm0.get_matrix

    else:
        found = False
        rot = np.zeros([2, 2])
        while not found:
            rot = np.random.randn(2, 2)
            if get_taste(rot - np.eye(2)) == taste:
                found = True

        dm = np.zeros([3, 3])
        dm[:2, :2] = (1 / sigma) * rot

        tx = (1 - dm[0, 0]) * center[0] - dm[0, 1] * center[1]
        ty = -dm[1, 0] * center[0] + (1 - dm[1, 1]) * center[1]

        dm[:2, 2] = np.array([tx, ty])

        dm = dm - np.eye(3)
        dm[2, 2] = 0

        return dm
Ejemplo n.º 18
0
def test_se2_g_norm_fro_invariance_for_angle():
    angle_1, tx, ty = 4, 5, 6
    angle_2 = angle_1 + uniform(-np.pi, np.pi)
    element_1 = se2.Se2G(angle_1, tx, ty)
    element_2 = se2.Se2G(angle_2, tx, ty)
    assert_equal(element_1.norm('fro'), element_2.norm('fro'))
Ejemplo n.º 19
0
def test_se2_g_norm_spam_input():
    angle, tx, ty = 4, 5, 6
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('spam'), -1)
Ejemplo n.º 20
0
def test_se2_g_norm_fro_random_input():
    angle = uniform(-np.pi + np.abs(np.spacing(-np.pi)), np.pi)
    tx = uniform(-10, 10)
    ty = uniform(-10, 10)
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('fro'), np.sqrt(3 + tx**2 + ty**2))
Ejemplo n.º 21
0
def test_se2_g_norm_fro_fixed_input_non0():
    angle, tx, ty = 4, 5, 6
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('fro'), np.sqrt(3 + 61.0))
Ejemplo n.º 22
0
def test_se2_g_norm_translation_fixed_input_non0():
    angle, tx, ty = 4, 5, 6
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('translation'), np.sqrt(61.0))
Ejemplo n.º 23
0
def test_se2_g_norm_standard_fixed_input_non0():
    angle, tx, ty = 4, 5, 6
    lamb = 1
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('standard', lamb),
                 np.sqrt(angles.mod_pipi(angle)**2 + lamb * (tx**2 + ty**2)))
Ejemplo n.º 24
0
def test_se2_g_norm_fro_fixed_input_0():
    angle, tx, ty = 0, 0, 0
    element = se2.Se2G(angle, tx, ty)
    print(element.get)
    assert_equal(element.norm('fro'), np.sqrt(3))
Ejemplo n.º 25
0
def test_se2_g_norm_translation_fixed_input_0():
    angle, tx, ty = 0, 0, 0
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('translation'), 0)
Ejemplo n.º 26
0
def test_se2_g_norm_standard_fixed_input_0():
    angle, tx, ty = 0, 0, 0
    element = se2.Se2G(angle, tx, ty)
    assert_equal(element.norm('standard', 1), 0)
Ejemplo n.º 27
0
        # -> transformation model <- #
        if params['deformation_model'] == 'translation':
            svf_0 = np.zeros(list(omega)[::-1] + [1, 1, 2])
            svf_0[..., 0] = 10
            svf_0[..., 1] = 20

        elif params['deformation_model'] == 'rotation':

            x_c, y_c = [c / 2 for c in omega]

            theta = np.pi / 8

            tx = (1 - np.cos(theta)) * x_c + np.sin(theta) * y_c
            ty = -np.sin(theta) * x_c + (1 - np.cos(theta)) * y_c

            m_0 = se2.Se2G(theta, tx, ty)
            dm_0 = se2.se2g_log(m_0)

            print(m_0.get_matrix)
            print('')
            print(dm_0.get_matrix)

            # Generate subsequent vector fields
            flow = gen.generate_from_matrix(list(omega)[::-1], m_0.get_matrix, structure='group')
            svf_0 = gen.generate_from_matrix(list(omega)[::-1], dm_0.get_matrix, structure='algebra')

        elif params['deformation_model'] == 'linear':

            taste = 1
            beta = 0.5
Ejemplo n.º 28
0
def test_visual_assessment_method_one_se2(show=False):
    """
    :param show: to add the visualisation of a figure.

    This test is for visual assessment. Please put show to True.

    Aimed to test the prototyping of the computation of the exponential map
    with some methods.

    (Nothing is saved in external folder.)
    """

    ##############
    # controller #
    ##############

    domain = (20, 20)

    x_c = 10
    y_c = 10
    theta = np.pi / 8

    tx = (1 - np.cos(theta)) * x_c + np.sin(theta) * y_c
    ty = -np.sin(theta) * x_c + (1 - np.cos(theta)) * y_c

    passepartout = 5
    spline_interpolation_order = 3

    l_exp = lie_exp.LieExp()
    l_exp.s_i_o = spline_interpolation_order

    methods_list = [
        l_exp.scaling_and_squaring, l_exp.gss_ei, l_exp.gss_ei_mod,
        l_exp.gss_aei, l_exp.midpoint, l_exp.series, l_exp.euler,
        l_exp.euler_aei, l_exp.euler_mod, l_exp.heun, l_exp.heun_mod,
        l_exp.rk4, l_exp.gss_rk4, l_exp.trapeziod_euler,
        l_exp.trapezoid_midpoint, l_exp.gss_trapezoid_euler,
        l_exp.gss_trapezoid_midpoint
    ]

    # -----
    # model
    # -----

    m_0 = se2.Se2G(theta, tx, ty)
    dm_0 = se2.se2g_log(m_0)

    # -- generate subsequent vector fields

    svf_0 = gen.generate_from_matrix(domain,
                                     dm_0.get_matrix,
                                     structure='algebra')
    sdisp_0 = gen.generate_from_matrix(domain,
                                       m_0.get_matrix,
                                       structure='group')

    # -- compute exponential with different available methods:

    sdisp_list = []
    res_time = np.zeros(len(methods_list))

    for num_met, met in enumerate(methods_list):
        start = time.time()
        sdisp_list.append(met(svf_0, input_num_steps=10))
        res_time[num_met] = (time.time() - start)

    # ----
    # view
    # ----

    print('--------------------')
    print('Norm of the svf: ')
    print(qr.norm(svf_0, passe_partout_size=4))

    print('--------------------')
    print("Norm of the displacement field:")
    print(qr.norm(sdisp_0, passe_partout_size=4))

    print('--------------------')
    print('Norm of the errors: ')
    print('--------------------')

    for num_met in range(len(methods_list)):
        err = qr.norm(sdisp_list[num_met] - sdisp_0,
                      passe_partout_size=passepartout)
        print('|{0:>22} - disp|  = {1}'.format(methods_list[num_met].__name__,
                                               err))

        if methods_list[num_met].__name__ == 'euler':
            assert err < 3
        else:
            assert err < 0.5

    print('---------------------')
    print('Computational Times: ')
    print('---------------------')

    if show:
        title_input_l = ['Sfv Input', 'Ground Output'] + methods_list
        fields_list = [svf_0, sdisp_0] + sdisp_list

        list_fields_of_field = [[svf_0], [sdisp_0]]
        list_colors = ['r', 'b']
        for third_field in fields_list[2:]:
            list_fields_of_field += [[svf_0, sdisp_0, third_field]]
            list_colors += ['r', 'b', 'm']

        fields_comparisons.see_n_fields_special(
            list_fields_of_field,
            fig_tag=50,
            row_fig=5,
            col_fig=5,
            input_figsize=(14, 7),
            colors_input=list_colors,
            titles_input=title_input_l,
            sample=(1, 1),
            zoom_input=[0, 20, 0, 20],
            window_title_input='matrix generated svf')

        plt.show()