LaTeX의 스타일 의사 코드

LaTeX의 스타일 의사 코드

저는 'The Elements of Statistical Learning'에서 가져온 다음 의사코드의 스타일을 복제하려고 합니다.

알고리즘, 알고리즘 및 열거(항목에 대해)를 시도했지만 아래 결과에 도달하지 못했습니다...

의사코드

답변1

이는 환경 enumerate내에 중첩된 것일 뿐입니다 algorithm.

여기에 이미지 설명을 입력하세요

\documentclass{report}

\usepackage{algorithm,amsmath,lipsum,xcolor,caption}
\DeclareMathOperator{\sgn}{sign}
\DeclareCaptionFont{lightblue}{\color{blue}}
\captionsetup[algorithm]{labelfont={bf,lightblue}, textfont={it}}
\renewcommand{\thealgorithm}{\thechapter.\arabic{algorithm}}

\begin{document}

\setcounter{chapter}{10}% Just for this example
\lipsum[1]

\begin{algorithm}[htb]
  \caption{AdaBoost.M1.}
  \begin{enumerate}
    \item
    Initialize the observation weights $w_i = 1/N$, $i = 1, 2, \dots, N$

    \item
    For $m = 1$ to $M$:
    \begin{enumerate}
      \item
      Fit a classifier $G_m(x)$ to the training data using weights $w_i$.

      \item
      Compute
      \[
        \text{err}_m = \frac{\sum_{i=1}^N w_i I(y_i \neq G_m(x_i))}{\sum_{i=1}^N w_i}.
      \]

      \item
      Compute $\alpha_m = \log((1 - \text{err}_m) / \text{err}_m)$.

      \item
      Set $w_i \leftarrow w_i \cdot \exp [\alpha_m \cdot I(y_i \neq G_m(x_i))]$, $i = 1, 2, \dots, N$.
    \end{enumerate}

  \item
  Output $G(x) = \sgn \bigl[ \sum_{m = 1}^M \alpha_m G_m(x) \bigr]$.
  \end{enumerate}
\end{algorithm}

\lipsum[2]

\end{document}

관련 정보