def test_joint_feature3():
    g = NodeTypeEdgeFeatureGraphCRF(2, [2, 3], [3, 4], np.array([[0, 2], [2, 3]]))
    node_f = [np.array([[1, 1, 1], [2, 2, 2]]), np.array([[0.11, 0.12, 0.13, 0.14], [0.21, 0.22, 0.23, 0.24], [0.31, 0.32, 0.33, 0.34]])]
    edges = [None, np.array([[0, 1]]), None, np.array([[0, 1], [1, 2]])]
    edge_f = [None, np.array([[0.221, 0.222]]), None, np.array([[0.01, 0.02, 0.03], [0.001, 0.002, 0.003]])]
    x = (node_f, edges, edge_f)
    y = np.hstack([np.array([0, 0]), (2 + np.array([0, 0, 0]))])
    g.initialize(x, y)
    jf = g.joint_feature(x, y)
    assert_array_equal(jf, jf)
    assert_array_almost_equal(jf, np.array([3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.63, 0.66, 0.69, 0.72, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.221, 0.0, 0.0, 0.0, 0.0, 0.0, 0.222, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.011, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.022, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.033, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    y = np.hstack([np.array([0, 1]), (2 + np.array([1, 1, 0]))])
    g.initialize(x, y)
    jf = g.joint_feature(x, y)
    assert_array_equal(jf, jf)
    assert_array_almost_equal(jf, np.array([1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.31, 0.32, 0.33, 0.34, 0.32, 0.34, 0.36, 0.38, 0.0, 0.0, 0.0, 0.0, 0.0, 0.221, 0.0, 0.0, 0.0, 0.0, 0.0, 0.222, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.002, 0.02, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.003, 0.03, 0.0, 0.0, 0.0, 0.0]))
    w = np.array(([1, 1, 1, 2, 2, 2, 10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30] + ([1.0] * 51)), dtype=np.float64)
    ret_u = g._get_unary_potentials(x, w)
    assert (len(ret_u) == 2)
    assert_array_almost_equal(ret_u[0], np.array([[3, 6], [6, 12]]))
    assert_array_almost_equal(ret_u[1], np.array([[5, 10, 15], [9, 18, 27], [13, 26, 39]]))
    assert (len(w) == g.size_joint_feature)
    ret_pw = g._get_pairwise_potentials(x, w)
    (pw00, pw01, pw10, pw11) = ret_pw
    assert (len(pw00) == 0)
    assert_array_almost_equal(pw01, np.array([[[0.443, 0.443, 0.443], [0.443, 0.443, 0.443]]]))
    assert (len(pw10) == 0)
    assert_array_almost_equal(pw11, np.array([[[0.06, 0.06, 0.06], [0.06, 0.06, 0.06], [0.06, 0.06, 0.06]], [[0.006, 0.006, 0.006], [0.006, 0.006, 0.006], [0.006, 0.006, 0.006]]]))
def test_joint_feature3():
    g = NodeTypeEdgeFeatureGraphCRF(2, [2, 3], [3, 4], np.array([[0, 2], [2, 3]]))
    node_f = [np.array([[1, 1, 1], [2, 2, 2]]), np.array([[0.11, 0.12, 0.13, 0.14], [0.21, 0.22, 0.23, 0.24], [0.31, 0.32, 0.33, 0.34]])]
    edges = [None, np.array([[0, 1]]), None, np.array([[0, 1], [1, 2]])]
    edge_f = [None, np.array([[0.221, 0.222]]), None, np.array([[0.01, 0.02, 0.03], [0.001, 0.002, 0.003]])]
    x = (node_f, edges, edge_f)
    y = np.hstack([np.array([0, 0]), (2 + np.array([0, 0, 0]))])
    g.initialize(x, y)
    jf = g.joint_feature(x, y)
    assert_array_equal(jf, jf)
    assert_array_almost_equal(jf, np.array([3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.63, 0.66, 0.69, 0.72, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.221, 0.0, 0.0, 0.0, 0.0, 0.0, 0.222, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.011, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.022, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.033, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    y = np.hstack([np.array([0, 1]), (2 + np.array([1, 1, 0]))])
    g.initialize(x, y)
    jf = g.joint_feature(x, y)
    assert_array_equal(jf, jf)
    assert_array_almost_equal(jf, np.array([1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.31, 0.32, 0.33, 0.34, 0.32, 0.34, 0.36, 0.38, 0.0, 0.0, 0.0, 0.0, 0.0, 0.221, 0.0, 0.0, 0.0, 0.0, 0.0, 0.222, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.002, 0.02, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.003, 0.03, 0.0, 0.0, 0.0, 0.0]))
    w = np.array(([1, 1, 1, 2, 2, 2, 10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30] + ([1.0] * 51)), dtype=np.float64)
    ret_u = g._get_unary_potentials(x, w)
    assert (len(ret_u) == 2)
    assert_array_almost_equal(ret_u[0], np.array([[3, 6], [6, 12]]))
    assert_array_almost_equal(ret_u[1], np.array([[5, 10, 15], [9, 18, 27], [13, 26, 39]]))
    assert (len(w) == g.size_joint_feature)
    ret_pw = g._get_pairwise_potentials(x, w)
    (pw00, pw01, pw10, pw11) = ret_pw
    assert (len(pw00) == 0)
    assert_array_almost_equal(pw01, np.array([[[0.443, 0.443, 0.443], [0.443, 0.443, 0.443]]]))
    assert (len(pw10) == 0)
    assert_array_almost_equal(pw11, np.array([[[0.06, 0.06, 0.06], [0.06, 0.06, 0.06], [0.06, 0.06, 0.06]], [[0.006, 0.006, 0.006], [0.006, 0.006, 0.006], [0.006, 0.006, 0.006]]]))