
위의 의사코드를 생성하기 위해 다음 코드를 사용했습니다.
\begin{algorithm}
\caption{sample}\label{sample}
\begin{algorithmic}[1]
\Require $\mathbf{D} \in \mathbb{R}^{M \times N}$
\State $\mathbf{V}^{(0)} \in \mathbb{R}^{K \times N} \gets $ random matrix
\For {$t= 1:T$}
\State $\mathbf{U}^{(t)} \gets Update\mathbf{U}(\mathbf{D},\mathbf{V}^{t-1})$
\State $\mathbf{V}^{(t)} \gets Update\mathbf{V}(\mathbf{D},\mathbf{U}^{t})$
\EndFor
\State \Return $\mathbf{U}^{(T)},\mathbf{V}^{(T)}$
\end{algorithmic}
\end{algorithm}
\mathbf
문제는 all 을 사용해야 D
하고 이를 행렬이나 벡터로 표현해야 한다는 것입니다 U
. 이러한 변수를 한 번 정의하고 모두 V
사용할 필요가 없는 다른 방법이 있습니까 ?\mathbf
답변1
예, 여기서 일반적인 접근 방식은 다음의 조언을 따르는 것입니다.일관된 타이포그래피. 즉, 개념을 정의하는 매크로를 만들어 문서 전체에서 사용하세요.
\documentclass{article}
\usepackage{algorithm,algpseudocode,amsfonts}
\newcommand{\sampleset}{\mathbf{D}}
\newcommand{\universe}[1]{\mathbb{R}^{#1}}
\newcommand{\setA}{\mathbf{U}}
\newcommand{\setB}{\mathbf{V}}
\begin{document}
\begin{algorithm}
\caption{sample}\label{sample}
\begin{algorithmic}[1]
\Require $\sampleset \in \universe{M \times N}$
\State $\setB^{(0)} \in \universe{K \times N} \gets $ random matrix
\For {$t= 1:T$}
\State $\setA^{(t)} \gets Update\setA(\mathbf{D},\setA^{t-1})$
\State $\setB^{(t)} \gets Update\setB(\mathbf{D},\setB^{t})$
\EndFor
\State \Return $\setA^{(T)},\setB^{(T)}$
\end{algorithmic}
\end{algorithm}
\end{document}
위에서 나는 몇 가지를 정의했습니다.변수, 그러나 알고리즘 내부의 함수로도 동일한 작업을 수행할 수 있습니다.