About log operator in LMC equation
Hi,
Thanks for your contribution.
I am wondering that why there is not log operator in the codebase?
Here is code in lmc.py:
net_grad.mul_(self.a).add_(self.noise, alpha=self.b)
self.prev_samples.add_(net_grad)
But the equation(10) in paper is:
Hello @zwxdxcm, Thank you for your interest in this work. Great question. The gradient of log Q is equal to the gradient of Q divided by Q. I perform this division in line 280 of "examples/train_ngp_nerf_prop.py".
Thank you! but I still have a question... in line 280, the code is:
net_grad = data['points_2d'].grad.detach()
loss_per_pix = loss_per_pix.detach()
net_grad = net_grad / ((grad_scaler._scale * (correction * loss_per_pix).unsqueeze(1))+ torch.finfo(net_grad.dtype).eps)
here we ignore scale * eps. correction = 1/[Q(x)]^\alpha. netgrad is the gradiant of total loss. How does it equal to grad(Q(x)) / Q(x)? It seems like grad(L)/[1/[Q(x)]^\alpha * L]. Is there anything i ignored? Thank you again !
Here is my understanding:
- approximate correction(x) = Q(x)
thus → ▽log(Q(x)) = ▽Q(x)/Q(x) = ▽correction(x)/correction(x)
I dont know why to multiply loss_per_pix again given that there is
loss_per_pix.mul_(correction)in line 267
Hello, I have the same question about the code in line 280 of "examples/train_ngp_nerf_prop.py".
According to the previous code, the correction and loss_per_pix are respectively:
$$correction = \frac{1}{sg(Q(\mathbf{x}))^{\alpha}}$$
$$loss\_per\_pix=\frac{Q(\mathbf{x})^{2}}{sg(Q(\mathbf{x}))^{\alpha}}$$
Then the net_grad should be:
$$\begin{align} {netgrad} &= \frac{\partial loss\_per\_pix}{\partial\mathbf{x}} = \frac{2Q(\mathbf{x})}{sg(Q(\mathbf{x}))^{\alpha}} \nabla Q(\mathbf{x}) \ \end{align}$$
$$\begin{align}\nabla\log Q(\mathbf{x}) &= \frac{1}{Q(\mathbf{x})} \nabla Q(\mathbf{x}) \ &=\frac{1}{Q(\mathbf{x})} \frac{netgrad \cdot sg(Q(\mathbf{x}))^{\alpha}}{2Q(\mathbf{x})} \ &=\frac{netgrad}{2\cdot loss\_per\_pix}\end{align}$$
I don't know why net_grad in the code is need to divide by correction again.
net_grad = net_grad / ((grad_scaler._scale * (correction * loss_per_pix).unsqueeze(1))+ torch.finfo(net_grad.dtype).eps)
Maybe my understanding about the partial of loss_per_pix is wrong... Could u give me some advice about that? Thank u very much.
Thank you for catching this mismatch. There was an incorrect correction term in the denominator, which I’ve now fixed. This must have happened when I was cleaning up the code.