Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about GaussianCriterion.lua #4

Closed
xcyan opened this issue Aug 29, 2015 · 1 comment
Closed

Questions about GaussianCriterion.lua #4

xcyan opened this issue Aug 29, 2015 · 1 comment

Comments

@xcyan
Copy link

xcyan commented Aug 29, 2015

self.gradInput[2] = torch.exp(-input[2]):cmul(torch.add(target,-1,input[1]):pow(2)):add(-0.5)

It seems to me that gradient updating step should be:

self.gradInput[2] = torch.exp(-input[2]):cmul(torch.add(target,-1,input[1]):pow(2)):mul(0.5):add(-0.5)

@y0ast y0ast closed this as completed in c074ffa Aug 30, 2015
@y0ast
Copy link
Owner

y0ast commented Aug 30, 2015

Hmm, there is definitely something wrong but your solution is not correct.

input[1] = mu
input[2] = log(sigma^2)

The forward is:
-0.5 * (log(sigma) + log(2pi)) - 0.5 * (x - mu)^2/sigma^2

The backward for log(sigma^2) is:

  • 0.25 + 0.5 * (x - mu)^2 / sigma^2

derivative of 1/sigma^2 with respect to log(sigma^2) is:
-exp(-log(sigma^2)) (using: 1/sigma^2 = exp(-log(sigma^2)))

The minus cancels the minus of - 0.5 * (x - mu)^2 and you reach the above mentioned backward.

See the commit for further details :). Thanks for pointing it out!

y0ast pushed a commit that referenced this issue Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants