\begin{algorithm}[!htb]
\caption{ Adaptive Dynamic Sampling for Unified Patterns}
\label{alg:ads_unified}
\KwInput{Initial data $\tilde{\vec{y}}_0 \in \mathbb{C}^{n \times n_c \times n_f}$, Acceleration $R$, Sample Space $\Omega$}
\KwOutput{Acquired $k$-space data $\tilde{\vec{y}}$ for $R$}
$n_a \gets |\Omega|$;\\
$ n_b  \gets \frac{n_a}{R} - |\Lambda_0|$ \tcp*{   Calculate total budget}
\For{$m \gets 1$ to $N$}
{
    % $n_b^{m} \gets n_b / N$ \tcp*{ Calculate layer budget}
    $\vec{p}_{m} \gets \mathcal{M}_{\boldsymbol{\psi}_{m}} \circ \mathcal{E}_{\boldsymbol{\theta}_{m}}(\tilde{\vec{y}}_{m-1})$ \tcp*{Produce adaptive probabilities $\vec{p}_m \in \mathbb{R}^{n_a}$}
    
       
    \For{\textit{each} $i \in \left(\bigcup_{j=0}^{m-1}\Lambda_{j}\right)$}
    {
        $(\vec{p}_{m})_i \gets 0$  \tcp*{Zero-out already sampled indices}
    }
    $\vec{p}_{m} \gets \text{Softplus} (\vec{p}_{m})$ \tcp*{ Apply Softplus}
    $\vec{p}_{m} \gets \text{Rescale}(\vec{p}_{m}; \texttt{budget} = n_b/N)$ \tcp*{Rescale such that $\mathbb{E}(\vec{p}_{m})=\frac{n_b}{N \times n_a}$}
    $\Lambda_{m} \gets \text{STE}(\vec{p}_{m})$
    % such that $\Lambda_{m-1}\cap\Lambda_{m} = \emptyset$ and $|\Lambda_{m}| = |\Lambda_0| + \frac{m \times n_b}{N}$ 
    \tcp*{Produce adaptive sampling}
    $\Lambda_m \gets (\Lambda_m, \cdots, \Lambda_m) $ \tcp*{Apply same pattern across frames}
    $\vec{z}_m \gets \vec{U}_{\Lambda_m} {\vec{y}}$ \tcp*{Acquire new $k$-space on $\Lambda_m$}
    $\tilde{\vec{y}}_{m} \gets \tilde{\vec{y}}_{m-1} +  \vec{z}_m = \vec{U}_{\cup_{j=0}^{m}\Lambda_{j}}  {\vec{y}}$ \tcp*{Aggregate with previous data $ \tilde{\vec{y}}_{m-1}$}
}
$\tilde{\vec{y}} \gets \tilde{\vec{y}}_N$;\\
\KwRet{$\tilde{\vec{y}}$}\\
\tcp*[h]{Note: Lines \textbf{5-6} ensure $\Lambda_{m-1}\cap\Lambda_{m} = \emptyset$ and line \textbf{8} $|\Lambda_{m}| = |\Lambda_0| + \frac{m \times n_b}{N}$}
\end{algorithm}

