YiyanXu / DiffRec

Diffusion Recommender Model
168 stars 23 forks source link

A Question about Implementation of Eq.4 #7

Closed FengxinLee closed 1 year ago

FengxinLee commented 1 year ago

Thanks for sharing your codes. And I have a question about implementation of eq.4.

For function betas_from_linear_variance in gaussian_diffusion.py, let argument variance be $\gamma$ (right part of the eq.4), and alpha_bar $= 1-\gamma$. Thus, the function aims to solve $\beta$ using $\gamma$.

For eq.4, $1-\bar{\alpha}_{t} =1- \alpha_1\alpha_2\cdots\alpha_t=1-(1-\beta_1)(1-\beta_2)\cdots(1-\beta_t)=\gamma_t$

For $t=1$ in eq.4: $1-\bar{\alpha}_1 = 1-\alpha_1 = 1-(1-\beta_1) = \beta_1=\gamma_1$ (third line of the function),

For $t=2$ in eq.4: $1-\bar{\alpha}_2 = 1-\alpha_1\alpha_2 = 1-(1-\beta_1)(1-\beta_2) = \gamma_2$ ,

thus $\beta_2=1-(1-\gamma_2)/(1-\beta_1) = 1-(1-\gamma_2)/(1-\gamma_1)$ (first execution of the for loop)

For $t=3$ in eq.4: $1-\bar{\alpha}_3 = 1-\alpha_1\alpha_2\alpha_3 = 1-(1-\beta_1)(1-\beta_2)(1-\beta_3) = \gamma_3$ ,

thus $\beta_3=1-(1-\gamma_3)/[(1-\beta_1)(1-\beta_2)] = 1-(1-\gamma_3)/[(1-\beta_1)(1-\beta_2)]$

However $(1-\beta_1)(1-\beta_2) \neq 1-\gamma_2$ , is a cumprod operation neglected?