
\begin{algorithm}[!hbt]

\caption{Forward Pass of Straight-through Estimator}
\label{alg:ste_forward}
\KwInput{Rescaled Probability  $\vec{p} = (p^1, \cdots, p^{n_f})  \in \mathbb{R}^{n_f\times n_a } $, Tolerance $\texttt{tol}=1e-3$
% such that $\mathbb{E}(p^t) = \frac{1}{N \times R}$
}
\KwOutput{Binarized pattern $\vec{r}$}
\For{$t \gets 1$ to $n_f$}
    { 
    \For{each $p_i^t$ in $p^t$}
    {
            Initialize $\pi_i \sim U(0, 1)$ \tcp*{Generate random uniform probability for $\pi_i$}
            $r_i^t \gets \mathbb{I}(p_i^t > \pi_i)$ \tcp*{Binarize $p_i^t$: Set $r_i^t = 1$ if $p_i^t > \pi_i$, otherwise $r_i^t = 0$}
    }
    \While{$|\mathbb{E}[r^t] - \mathbb{E}[p^t]| \geq \texttt{tol}$}
    {
        \For{each $p_i^t$ in $p^t$}
        {
            $\pi_i \sim U(0, 1)$ \tcp*{Regenerate random uniform probability for $\pi_i$}
            $r_i^t \gets \mathbb{I}(p_i^t > \pi_i)$ \tcp*{Re-binarize $p_i^t$ with the new $\pi_i$}
        }
    }
    }
$\vec{r} = (r^1, \cdots, r^t)$\\
\textbf{store} $\boldsymbol{\pi}$ \tcp*{Store $\boldsymbol{\pi}$ for backward pass}
\KwRet{$\vec{r}$}\\
\tcp*[h]{Note: For unified sampling set $n_f=1$}
\end{algorithm}
\vspace{20pt}