42dc18f2a13441eefdfceed905843a3d19b27072,pyro/distributions/one_two_matching.py,OneTwoMatching,log_partition_function,#OneTwoMatching#,101

Before Change


        finfo = torch.finfo(self.logits.dtype)
        shift = self.logits.data.max(1, True).values
        shift.clamp_(min=finfo.min, max=finfo.max)
        p = (self.logits - shift).exp().clamp(min=finfo.tiny ** 0.5)
        d = 2 / p.sum(0)
        for _ in range(self.bp_iters):
            s = 1 / (p @ d)
            d = 2 / (s @ p)
        b = s[:, None] * d * p

        // Evaluate the Bethe free energy, adapting [4] Eqn 4 to one-two
        // matchings.
        b = b.clamp(min=finfo.tiny ** 0.5)

After Change


        logits = self.logits - shift
        d = logits.logsumexp(0) - math.log(2)
        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()

        // Evaluate the Bethe free energy, adapting [4] Eqn 4 to one-two
        // matchings.
        b_ = (1 - b).clamp(min=0)
        internal_energy = -(b * logits.clamp(min=-1 / finfo.eps)).sum()
        // Let h be the entropy of matching each destin to one source.
        z = b / 2
        h = -(z * log(z)).sum(0)
        // Then h2 is the entropy of the distribution mapping each destin to an
        // unordered pair of sources, equal to the log of the binomial
        // coefficient: perplexity * (perplexity - 1) / 2.
        h2 = h + log(h.expm1()) - math.log(2)
        free_energy = internal_energy - h2.sum() - (b_ * log(b_)).sum()
        log_Z = shift.sum() - free_energy
        assert torch.isfinite(log_Z)
        return log_Z

    def log_prob(self, value):
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 10

Instances


Project Name: uber/pyro
Commit Name: 42dc18f2a13441eefdfceed905843a3d19b27072
Time: 2020-12-07
Author: fritz.obermeyer@gmail.com
File Name: pyro/distributions/one_two_matching.py
Class Name: OneTwoMatching
Method Name: log_partition_function


Project Name: HyperGAN/HyperGAN
Commit Name: 00da5ce05b39dbe0a5933e65df6e689b0782a174
Time: 2020-03-05
Author: mikkel@255bits.com
File Name: hypergan/losses/wasserstein_loss.py
Class Name: WassersteinLoss
Method Name: _forward


Project Name: uber/pyro
Commit Name: 42dc18f2a13441eefdfceed905843a3d19b27072
Time: 2020-12-07
Author: fritz.obermeyer@gmail.com
File Name: pyro/distributions/one_one_matching.py
Class Name: OneOneMatching
Method Name: log_partition_function