\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}

\begin{document}

\begin{algorithm}
\caption{Bayesian Ridge Regression with Sign Entropy Regularization}
\label{alg:bayesian_ridge_fit}
\begin{algorithmic}[1]
\Require $X, y, \text{sample\_weight}$ (Optional)
\State Initialize feature selection mask $\mathbf{m} \gets \mathbf{0}$ (all features active)
\State Initialize $\alpha, \lambda$ if not provided
\State Preprocess $X, y$ and apply rescaling if sample weights exist
\State Compute $X^T y$
\State Initialize $\text{skip\_counter} \gets \text{skip\_iters}$, $\text{tol\_counter} \gets 0$
\State $\mathbf{\beta}_{\text{old}} \gets \mathbf{0}$, $\mathbf{\beta}_{\text{full}} \gets \mathbf{0}$
\For{$\text{iter} = 1$ to $\text{max\_iter}$}
    \State $X_{\text{selected}} \gets X[:, \mathbf{m} == 0]$ \Comment{Select non-eliminated features}
    \If{$\text{use\_sign\_entropy\_elimination}$ and $\text{iter} \geq \text{skip\_counter}$ and $\text{tol\_counter} < \text{tol}$}
        \State Compute SVD: $U, S, V^T = \text{SVD}(X_{\text{selected}})$
        \State Compute coefficients: $\mathbf{\beta}, \text{rmse} \gets \text{UpdateCoef}(X_{\text{selected}}, y)$
        \State Compute covariance: $\sigma \gets \frac{1}{\alpha} V^T (V / (S^2 + \lambda / \alpha))$
        \State Compute sign entropy for each feature
        \State Identify high-entropy features: $\mathcal{F}_{\text{elim}} \gets \{ j | H(\beta_j) > \zeta \}$
        \If{$\mathcal{F}_{\text{elim}} = \emptyset$}
            \State $\text{tol\_counter} \gets \text{tol\_counter} + 1$
        \Else
            \State $\text{tol\_counter} \gets 0$
            \State Mark eliminated features: $\mathbf{m}[\mathcal{F}_{\text{elim}}] \gets 1$
            \State Update $\text{skip\_counter} \gets \text{iter} + \text{skip\_iters} + 1$
        \EndIf
        \State $X_{\text{selected}} \gets X[:, \mathbf{m} == 0]$ \Comment{Update feature set}
    \EndIf
    \State Compute SVD and update coefficients $\mathbf{\beta}$
    \State Store full coefficient vector: $\mathbf{\beta}_{\text{full}}[\mathbf{m} == 0] \gets \mathbf{\beta}$
    \State Set eliminated coefficients: $\mathbf{\beta}_{\text{full}}[\mathbf{m} == 1] \gets -0.0$
    \If{converged}
        \State \textbf{break}
    \EndIf
    \State Compute marginal likelihood score if required
    \State Update $\alpha$ and $\lambda$
\EndFor
\State \Return $\mathbf{\beta}_{\text{full}}, \alpha, \lambda$
\end{algorithmic}
\end{algorithm}

\end{document}
