bmild / nerf

Code release for NeRF (Neural Radiance Fields)
http://tancik.com/nerf
MIT License
9.58k stars 1.34k forks source link

sample_pdf function for generating new sample #151

Open ht719 opened 2 years ago

ht719 commented 2 years ago

Can anyone explain the code below? (https://user-images.githubusercontent.com/40779217/169441638-cb24928a-be1c-4e2e-bc05-524e6c9cc5bc.png)

what's the meaning of denom and t?

MoYan1082 commented 1 year ago

I have the same problem:(

cx-tian commented 1 year ago

Hi, did you figure it out? I'm also stucked in this function. Based on my understanding, denom should be the probability of sample points between this corresponding position since it is the difference between 2 CDF values(for example, between 2 uniform distributed sampled points a and b, when we want to sample based on the weights we got from coarse network, the probability of the new sampled points here should be denom).

However, I don't get the meaning of the last 2 lines in the code.

t = (u-cdf_g[..., 0])/denom samples = bins_g[..., 0] + t * (bins_g[..., 1]-bins_g[..., 0])

cx-tian commented 1 year ago

Hi, I have a vague thought. u is the uniform distribution we used to put in places between the CDF. Let's say we have 2 u which are 0.23, 0.34. When find indexes, assume the below and above (in code he set side='right') indexes of the CDF is 4 and 5 which has cdf_g of (0.2, 0.45), then t would be $t=\frac{0.23-0.2}{0.45 - 0.2} = 0.12$. Assume 4th bin is at $t=1.3$, 5th bin is at $t=1.6$, then our sample point(it should be somewhere between the 4th and 5th bins ) would be at $1.3+t(1.6-1.3) = 1.3 + 0.120.3 = 1.336$

tetsu-kikuchi commented 9 months ago

Thanks to tf.searchsorted, we know in which bin the sample point resides. But we still do not know precisely where the sample point is within the bin. t = (u - cdf_g[0])/denom specifies the place. If t=0, the sample point is on the left edge of the bin, while if t=1, the right edge.

The following exaggerated figure may help you. スクリーンショット 2023-10-03 161813