def test_joint_feature_discrete():
    '\n    Testing with a single type of nodes. Must de aw well as EdgeFeatureGraphCRF\n    '
    (X, Y) = generate_blocks_multinomial(noise=2, n_samples=1, seed=1)
    (x, y) = (X[0], Y[0])
    edge_list = make_grid_edges(x, 4, return_lists=True)
    edges = np.vstack(edge_list)
    edge_features = edge_list_to_features(edge_list)
    x = ([x.reshape((- 1), 3)], [edges], [edge_features])
    y_flat = y.ravel()
    if True:
        crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]])
        joint_feature_y = crf.joint_feature(x, y_flat)
        assert_equal(joint_feature_y.shape, (crf.size_joint_feature,))
        n_states = crf.l_n_states[0]
        n_features = crf.l_n_features[0]
        (pw_joint_feature_horz, pw_joint_feature_vert) = joint_feature_y[(n_states * n_features):].reshape(2, n_states, n_states)
        assert_array_equal(pw_joint_feature_vert, np.diag([(9 * 4), (9 * 4), (9 * 4)]))
        vert_joint_feature = np.diag([(10 * 3), (10 * 3), (10 * 3)])
        vert_joint_feature[(0, 1)] = 10
        vert_joint_feature[(1, 2)] = 10
        assert_array_equal(pw_joint_feature_horz, vert_joint_feature)
Testing with a single type of nodes. Must de aw well as EdgeFeatureGraphCRF
def test_joint_feature_discrete():
    '\n    \n    '
    (X, Y) = generate_blocks_multinomial(noise=2, n_samples=1, seed=1)
    (x, y) = (X[0], Y[0])
    edge_list = make_grid_edges(x, 4, return_lists=True)
    edges = np.vstack(edge_list)
    edge_features = edge_list_to_features(edge_list)
    x = ([x.reshape((- 1), 3)], [edges], [edge_features])
    y_flat = y.ravel()
    if True:
        crf = NodeTypeEdgeFeatureGraphCRF(1, [3], [3], [[2]])
        joint_feature_y = crf.joint_feature(x, y_flat)
        assert_equal(joint_feature_y.shape, (crf.size_joint_feature,))
        n_states = crf.l_n_states[0]
        n_features = crf.l_n_features[0]
        (pw_joint_feature_horz, pw_joint_feature_vert) = joint_feature_y[(n_states * n_features):].reshape(2, n_states, n_states)
        assert_array_equal(pw_joint_feature_vert, np.diag([(9 * 4), (9 * 4), (9 * 4)]))
        vert_joint_feature = np.diag([(10 * 3), (10 * 3), (10 * 3)])
        vert_joint_feature[(0, 1)] = 10
        vert_joint_feature[(1, 2)] = 10
        assert_array_equal(pw_joint_feature_horz, vert_joint_feature)