\renewcommand{\algorithmicindent}{.75em}  % Reduce indent for algorithms
\begin{algorithm}[!ht]
    \caption{Stein Variational CMA-ES. Differences to the parallel CMA-ES algorithm are highlighted in \bblue{\textbf{blue}}.
    }
    \label{alg:sv-cmaes}
    
    \textbf{Input:} Kernel $k(\cdot, \cdot)$; num.\ particles $\varrho$; subpop.\ size $n$; num.\ elites $m$; elite weights $w_{i=1\dots m}$; learning rates $\epsilon, \alpha_\sigma, \alpha_1, \alpha_m, \alpha_c$; damping hyperparam.\ $d_\sigma$; dimension $d$; num.\ iterations $T$
    \begin{algorithmic}[1]
        \setlength{\itemsep}{2pt}
        \State Initialize population parameters $\vx_i, \sigma_i, \vC_i$ for particles $i = 1, \dots, \varrho$
        \For{iteration $t = 1, \dots, T$}
            \For{particle $i = 1, \dots, \varrho$}
                % Input iteration: t, elite size \lambda, 
                \State \textbf{Sample \& evaluate new population}: %\vspace{-3mm}
                \Statex $\displaystyle \begin{aligned}
                    \hspace{1.5em}&\vxi_{ij} \sim \NN (\vx_i, \sigma_i^2 \vC_i)\text{, for $j = 1, \dots, n$}\\
                    &\vy_{ij} = (\vxi_{ij} - \vx_i) / \sigma_i
                \end{aligned}$
                \Statex
                
                \State \textbf{\bblue{Estimate gradient \& shift particle (Eq.~\ref{eq:asv-cma-final})}}:
                \Statex \hspace{1.3em} Sort samples by $f_{ij} = f(\vxi_{ij})$ in ascending order %\vspace{-3mm}
                \Statex $\displaystyle \begin{aligned}
                    \hspace{1.5em}&\bblue{
                    \phi(\vx_i) = \sum_{\ell=1}^m w_{i\ell}(\vxi_{i\ell} - \vx_i) + \frac{\gamma(t)}{\varrho}\sum_{j=1}^\varrho \N_{\vx_j} k(\vx_j, \vx_i) 
                    }\hspace{-.5em}\\
                    %
                    &\bblue{\vx_i \gets \vx_i + \epsilon \phi(\vx_i)}&
                \end{aligned}$
                \Statex
        
                \State \textbf{Cumulative step-size adaptation}: %\vspace{-2.5mm}
                \Statex $\displaystyle \begin{aligned}
                    \hspace{1.5em}&m_{\text{eff}, i} = (\tsum_{\ell=1}^m w_{i\ell}^2)^{-1}\\
                    %
                    %\begin{split}
                        &\vp_{\sigma_i} \gets (1 - \alpha_{\sigma}) \vp_{\sigma_i}\\
                        &\qquad + \sqrt{\alpha_\sigma (2 - \alpha_\sigma)~ m_{\text{eff}, i}}~\vC_i^{-\frac{1}{2}} \bblue{\phi(\vx_i) / \sigma_i}\\
                    %\end{split}\\
                    %
                    &\sigma_i \gets \sigma_i \times \exp\Bigl(\frac{\alpha_{\sigma}}{d_{\sigma}} \Bigl(\frac{\lVert \vp_{\sigma_i}\rVert}{\EEE \lVert \NN (0, \Id) \rVert} - 1\Bigr)\Bigr)&
                \end{aligned}$
                \Statex
        
                \State \textbf{Covariance matrix adaptation}: %\vspace{-3mm}
                \Statex $\displaystyle \begin{aligned}
                    \hspace{1.5em}&\bar{h} = \lVert \vp_{\sigma_i} \rVert / \sqrt{1 - (1-\alpha_\sigma)^{2(t+1)}}&\\
                    &h_{\sigma_i} = 1 \text{ if } \bar{h} < (1.4 + \tfrac{2}{d+1})\EEE \lVert \NN (0, \Id) \rVert \text{ else } 0 \hspace{-2em}&\\
                    %
                    &d(h_{\sigma_i}) = 1 \text{ if } \alpha_c (1 - h_\sigma)(2-\alpha_c) \leq 1 \text{ else } 0&\\
                    %
                    &\bar{w}_{ij} = w_{ij} \text{ if } w_{ij} \geq 0 \text{ else } d / \lVert \vC_i^{-\frac{1}{2}} \vy_{ij} \rVert^2 \hspace{-2em}&\\
                    &\vp_{c_i}\!\gets\!(1 - \alpha_c) \vp_{c_i}\!+\!h_{\sigma_i} \sqrt{\alpha_c (2\!-\!\alpha_c) m_{\text{eff}, i}}~ \bblue{\phi(\vx_i) / \sigma_i}  \hspace{-2em}&\\
                    %
                    %\begin{split}
                        &\vC_i \gets (1 + d(h_{\sigma_i}) - \alpha_1 - \alpha_m \tsum_{j=1}^n w_{ij}) \vC_i\\
                        &\qquad + \alpha_1 \vp_{c_i} \vp_{c_i}^T + \alpha_m \tsum_{j=1}^n \bar{w}_{ij} \vy_{ij} \vy_{ij}^T
                    %\end{split}
                \end{aligned}$
                \Statex
            \EndFor
        \EndFor
    \end{algorithmic}
\end{algorithm}
