pydecode.binarize¶
Examples¶
import pydecode
import numpy as np
items = np.arange(10)
chart = pydecode.ChartBuilder(items)
chart.init(items[:4])
chart.set(items[5], [items[:4]], labels=[10])
graph = chart.finish()
pydecode.draw(graph, graph.labeling, vertex_labels=None)
new_graph = pydecode.binarize(graph)
pydecode.draw(new_graph, new_graph.labeling, vertex_labels=None)
Invariants¶
import numpy.testing as test
import pydecode.test.utils as test_utils
graph, _, weight_type = test_utils.random_setup()
binary_graph = pydecode.binarize(graph)
size = np.max(graph.labeling) + 1
label_weights = test_utils.random_weights(weight_type, size)
Binarizing does not change best path score.
weights = pydecode.transform(graph, label_weights, weight_type=weight_type)
score1 = pydecode.inside(graph, weights, weight_type=weight_type)[graph.root.id]
weights2 = pydecode.transform(binary_graph, label_weights, weight_type=weight_type)
score2 = pydecode.inside(binary_graph, weights2, weight_type=weight_type)[graph.root.id]
test.assert_almost_equal(score1, score2)