didriknielsen / survae_flows

Code for paper "SurVAE Flows: Surjections to Bridge the Gap between VAEs and Flows"
MIT License
283 stars 34 forks source link

question about SimpleAbsSurjection function #17

Open Fangwq opened 3 years ago

Fangwq commented 3 years ago

I read the code recently and feel confused about the class SimpleAbsSurjection. The part of code is following:

    def forward(self, x):
        z = x.abs()         
        ldj = - x.new_ones(x.shape[0]) * math.log(2) * x.shape[1:].numel()
        return z, ldj

why should we multiply this term x.shape[1:].numel()? where does it come from? Any clues does I miss ?

didriknielsen commented 3 years ago

Hi, thanks for your question!

This is the number of dimensions in your data. By default, this layer applies the abs transformation to every element in the data, hence you need to scale by log(2) once per element.

Fangwq commented 3 years ago

Thank you for your clarification!