Giter VIP home page Giter VIP logo

Comments (1)

jeff-regier avatar jeff-regier commented on July 17, 2024

Comment by jeff-regier
Thursday Apr 12, 2018 at 20:58 GMT


This code I wrote for another project may be useful for this issue:

    def iwae_loss(self, ys, k=10):
        tall_shape = [ys.size(0) * k] + list(ys.size()[1:])
        ys_tall = ys.unsqueeze(1).repeat(1, k, 1, 1).view(tall_shape)

        wide_shape = [ys.size(0), k]
        vae_losses = self.vae_losses(ys_tall).view(wide_shape)

        iwae_gains = logsumexp(-1 * vae_losses, dim=1) - np.log(k)
        return -1 * iwae_gains.sum()

Above ys are the data/observations and self.vae_losses is a method that returns a vector of vae losses, one for each observation in the minibatch. (VAE loss approximates -1 * E_q p(x, z, l) / q(z, l) ).

For some reason PyTorch doesn't have an logsumexp function yet, so I use

def logsumexp(inputs, dim=None, keepdim=False):
    return (inputs - f.log_softmax(inputs, dim=dim)).mean(dim, keepdim=keepdim)

from scvi-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.