Adding function "decode" to belief propagation