// Evaluate the Bethe free energy, adapting [4] Eqn 4 to one-two
// matchings.
b = b.clamp(min=finfo.tiny ** 0.5)
b_ = (1 - b).clamp(min=finfo.tiny ** 0.5)
internal_energy = -(b * p.log()).sum()
// Let h be the entropy of matching each destin to one source.
z = b / 2
After Change
for _ in range(self.bp_iters):
s = (logits - d).logsumexp(-1, True)
d = (logits - s).logsumexp(0) - math.log(2)
b = (logits - (d + s)).exp()
def log(x):
return x.clamp(min=finfo.tiny).log()