Can someone explain what this log_normal_pdf term means for the tensorflow VAE demo code?

Viewed 326
2 Answers

This is the logarithm of the probability according to a normal distribution. I.e. log(p(x)) where p is a normal/Gaussian distribution. The naming is a little confusing though.

In case anyone else wanders down this rabbit hole, the previous answer checks out: "the logarithm of the pdf according to a normal distribution". Here's a simple check that you can run based on the gaussian function definition from wiki:

import numpy as np

def log_normal_pdf(sample, mean, std):
    """Function from tensorflow VAE example"""
    logvar = np.log(std**2)
    log2pi = np.log(2*np.pi)
    return -.5 * ((sample - mean) ** 2. * np.exp(-logvar) + logvar + log2pi)

def test(sample, mean, std):
    """Alternate calc taking the log of the wiki gaussian function"""
    out = (1 / (std * np.sqrt(2*np.pi))) * np.exp(-0.5 * (sample-mean)**2 / std**2)
    return np.log(out)

print(log_normal_pdf(9, 10, 1))
print(test(9, 10, 1))
Related