def test_edge_type_graph_crf(): # create two samples with different graphs # two states only, pairwise smoothing # all edges are of the first type. should do the same as GraphCRF # if we make w symmetric for inference_method in get_installed(['qpbo', 'lp', 'ad3', 'dai', 'ogm']): crf = EdgeTypeGraphCRF(n_states=2, inference_method=inference_method, n_edge_types=1) assert_array_equal(crf.inference((x_1, [g_1]), w_sym), y_1) assert_array_equal(crf.inference((x_2, [g_2]), w_sym), y_2) # same, only with two edge types and no edges of second type w_sym_ = np.array([1, 0, # unary 0, 1, .22, 0, # pairwise 0, .22, 2, -1, # second edge type, doesn't exist -1, 3]) for inference_method in get_installed(['qpbo', 'lp', 'ad3', 'dai', 'ogm']): crf = EdgeTypeGraphCRF(n_states=2, inference_method=inference_method, n_edge_types=2) assert_array_equal(crf.inference((x_1, [g_1, np.zeros((0, 2), dtype=np.int)]), w_sym_), y_1) assert_array_equal(crf.inference((x_2, [g_2, np.zeros((0, 2), dtype=np.int)]), w_sym_), y_2) print crf.get_pairwise_potentials((x_2, [g_2, np.zeros((0, 2), dtype=np.int)]), w_sym_)