
上記の疑似コードを生成するために、次のコードを使用しました。
\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
問題は、 for all を使用し、それらを行列またはベクトルとして表す必要があることですD
。これらの変数を 1 回定義し、 for all を使用する必要がない他の方法はあります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}
上記でいくつか定義しました変数ただし、アルゴリズム内の関数でも同じことができます。