教科书统计学习简介使用类似算法的环境,其中会写出完整的句子。这些环境似乎使用嵌套的枚举环境。我想在我正在编写的文档中使用类似的东西。以下是一个例子:
我无法独自重现这样的环境,任何帮助都将不胜感激。感谢您花时间考虑我的问题!
答案1
只需使用algorithm
环境:
\documentclass{article}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{Bayesian Additive Regression Trees}
\begin{enumerate}
\item Let $\hat{f}_1^1(x)=\hat{f}_2^1(x)=\cdots=\hat{f}_K^1(x)=\frac{1}{n K} \sum_{i=1}^n y_i$.
\item Compute $\hat{f}^1(x)=\sum_{k=1}^K \hat{f}_k^1(x)=\frac{1}{n} \sum_{i=1}^n y_i$.
\item For $b = 2,\ldots, B$:
\begin{enumerate}
\item For $k = 1, 2, \ldots, K$:
\begin{enumerate}
\item For $i = 1, \ldots, n$, compute the current partial residual
\[
r_i=y_i-\sum_{k^{\prime}<k} \hat{f}_{k^{\prime}}^b\left(x_i\right)-\sum_{k^{\prime}>k} \hat{f}_{k^{\prime}}^{b-1}\left(x_i\right)
\]
\item Fit a new tree, $\hat{f}_k^b(x)$, to $r_i$, by randomly perturbing the $k$ th tree from the previous iteration, $\hat{f}_k^{b-1}(x)$. Perturbations that improve the fit are favored.
\end{enumerate}
\item Compute $\hat{f}^b(x)=\sum_{k=1}^K \hat{f}_k^b(x)$.
\end{enumerate}
\item Compute the mean after $L$ burn-in samples,
\[
\hat{f}(x)=\frac{1}{B-L} \sum_{b=L+1}^B \hat{f}^b(x)
\]
\end{enumerate}
\end{algorithm}
\end{document}