Closed bd3dowling closed 5 months ago
Paste from obsidian:
\begin{algorithm}
\caption{Twisted Diffusion Sampler (TDS)}
\begin{algorithmic}
\State Initial proposal and weight
\For{$k = 1$ to $K$}
\State Sample $x^T_k \sim p(x^T)$
\State Compute initial weight $w_k \gets \tilde{p}_T^k = \tilde{p}_\theta(y \mid x^T_k)$
\EndFor
\For{$t = T-1$ to $0$}
\State Resample $\{(x^{t+1}_k, \tilde{p}^{t+1}_k)\}^K_{k=1}$ from Multinomial based on $\{(x^{t+1}_k, \tilde{p}^{t+1}_k)\}^K_{k=1}$ and $\{w_k\}^K_{k=1}$
\For{$k = 1$ to $K$}
\State Calculate conditional score $\tilde{s}_k = (\hat{x}_\theta(x^{t+1}_k) - x^{t+1}_k) / t\sigma^2 + \nabla_{x^{t+1}_k} \log \tilde{p}^{t+1}_k$
\State Propose $x^t_k \sim \tilde{p}_\theta(\cdot \mid x^{t+1}_k, y) = \mathcal{N}(x^{t+1}_k + \sigma^2 \tilde{s}_k, \tilde{\sigma}^2)$
\State Twising function $\tilde{p}_k^t \gets \tilde{p}_\theta(y \mid x^t)$
\State Update weight $w_k \gets p_\theta(x^t_k \mid x^{t+1}_k) \tilde{p}^t_k / (\tilde{p}_\theta(x^t_k \mid x^{t+1}_k, y) \tilde{p}^{t+1}_k)$
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm}
Code: https://github.com/blt2114/twisted_diffusion_sampler?utm_source=catalyzex.com
Essentially fork/mod of DPS (really OpenAI) repo; mods GaussianDiffusion with key code in feynman_kac_image_ddpm.py
Wu, Luhuan, et al. Practical and Asymptotically Exact Conditional Sampling in Diffusion Models. arXiv:2306.17775, arXiv, 30 June 2023. arXiv.org, http://arxiv.org/abs/2306.17775.