我用 LaTeX 编码的这个算法步骤如下:
\begin{algorithm}
\caption{Deep Q-Learning with Experience Replay}
\label{alg:DQN}
\begin{algorithmic}
\State Initialize replay memory $\mathcal{D}$ to capacity $N$
\State Initialize action-value function $Q$ with two random sets of weights $\theta, \theta'$
\For{$episode = 1,M$}
\For{$t = 1,T$}
\State
Select a random action $a_t$ with probability $\varepsilon$.
\State
Otherwise, select $a_t = {\arg\max}_a Q(s_t, a; \theta)$
\State Execute action $a_t$, collect reward $r_{t+1}$ and observe next state $s_{t+1}$
\State Store the transition $(s_t, a_t, r_{t+1}, s_{t+1})$ in $\mathcal{D}$
\State Sample mini-batch of transitions $(s_j, a_j, r_{j+1}, s_{j+1})$ from $\mathcal{D}$
\State Set $ y_j = \begin{cases}
r_{j+1}, & \mbox{if } s_{j+1}\mbox{ is terminal} \\
r_{j+1} + \gamma \max_{a'} Q(s_{j+1}, a'; \theta'), & \mbox{otherwise}
\end{cases}$
\State Perform a gradient descent step using targets $y_j$ with respect to the online parameters $\theta$
\State Every $C$ steps, set $\theta' \leftarrow \theta$
\EndFor
\EndFor
\end{algorithmic}
\end{algorithm}
有没有办法将这张照片或算法转换为 word 文档,而无需使用 latex 文档的图像?我尝试在 MS word 中插入方程式,但没有成功。
答案1
这是我经常使用的方法。(5分钟就能搞定)
(1)准备好包含要转换内容的 LaTeX 文件。在此示例中,名为Test2WORD.tex
。您可以使用系统中已有的系统字体。这里我使用的是calibri
,这是我将在主 Word 文档中使用的字体。
文件 Test2WORD.tex
%%% File Test2WORD.tex
\documentclass{article}
\usepackage{caption}
\usepackage{algorithm, algorithmic}%
\usepackage{fontspec}
\setmainfont{calibri} % a system font <<<<
\begin{document}
Some text.
\begin{algorithm}
\caption{Deep Q-Learning with Experience Replay} \label{alg:DQN}
\begin{algorithmic}
\STATE Initialize replay memory $\mathcal{D}$ to capacity $N$
\STATE Initialize action-value function $Q$ with two random sets of weights $\theta, \theta'$
\FOR{$episode = 1,M$}
\FOR{$t = 1,T$}
\STATE
Select a random action $a_t$ with probability $\varepsilon$.
\STATE
Otherwise, select $a_t = {\arg\max}_a Q(s_t, a; \theta)$
\STATE Execute action $a_t$, collect reward $r_{t+1}$ and observe next state $s_{t+1}$
\STATE Store the transition $(s_t, a_t, r_{t+1}, s_{t+1})$ in $\mathcal{D}$
\STATE Sample mini-batch of transitions $(s_j, a_j, r_{j+1}, s_{j+1})$ from $\mathcal{D}$
\STATE Perform a gradient descent step using targets $y_j$ with respect to the online parameters $\theta$
\STATE Every $C$ steps, set $\theta' \leftarrow \theta$
\ENDFOR
\ENDFOR
\end{algorithmic}
\end{algorithm}
See Algorithm \ref{alg:DQN}.
\end{document}
(2)编译生成Test2WORD.pdf
输出
(3)Test2WORD.pdf
使用ms-word打开(我使用的是word 2013)。
Word 文档采用所选字体,并且完全可编辑。请参阅我制作的黄色突出显示。
我发现两个需要更正的地方(红色)。
答案2
我尝试了这个并且有效,但是它扭曲了格式并且变得极难修复。没有其他办法了吗?