mengchaoheng / SCUT_thesis

华南理工大学硕博士学位论文模板(LaTeX)。Latex templates for the thesis of South China University of Technology
GNU General Public License v3.0
306 stars 59 forks source link

不支持伪代码 algorithm algorithmic 吗 #29

Closed Droliven closed 8 months ago

Droliven commented 1 year ago

现在好像不支持 伪代码吧,类似这种 image

\begin{algorithm}[!t]
\caption{Diverse sampling from a complex distribution by randomly Gumbel-Softmax sampling from an auxiliary space}\label{alg:our-sampling-process}
\begin{algorithmic}[1]
\Require Observed pose sequence $\mathbf{x}$, number of samples $K$, auxiliary space generation network $\mathcal{N}_{\bm{\beta}}$, Gaussian distribution generation network $\mathcal{N}_{\bm{\gamma}}$, CVAE decoder network $\mathcal{G}_{\bm{\theta}}$
\Ensure A set of samples $\{\mathbf{\tilde{y}}_k\}_{k=1}^{K}$
\State $\mathbf{B} = \mathcal{N}_{\bm{\beta}}(\mathbf{x})$ // \textit{generate an auxiliary space given input poses}
\State $\mathbf{W} \leftarrow \text{Gumbel-Softmax sampling}$ // \textit{see \rm{Algorithm} \ref{alg:gumbel-softmax}}
\State $\mathbf{P}=\mathbf{W}\mathbf{B}$ // \textit{Multiply $\mathbf{W}$ and $\mathbf{B}$ to obtain a point matrix $\mathbf{P}$}
\State $\left\{\mathbf{A}_k,\mathbf{b}_k\right\}_{k=1}^K = \mathcal{N}_{\bm{\gamma}}(\mathbf{P})$ // \textit{convert points into means and variances}
\State $\bm{\epsilon}  \sim \mathcal{N}(0,1)$ // \textit{sampling an $\bm{\epsilon}$ from the normal distribution}
\For{$k=1$ to $K$}
    \State $\mathbf{z}_k  = \mathbf{A}_k \mathbf{\bm{\epsilon}} + \mathbf{b}_k$ // \textit{reparameterization trick}
    \State $\mathbf{\tilde{y}}_k  = \mathcal{G}_{\bm{\theta}}(\mathbf{x},\mathbf{z}_k)$ // \textit{decode $\mathbf{z}_k$ and $\mathbf{x}$ into a result $\mathbf{\tilde{y}}_k$}
\EndFor 
\end{algorithmic}
\end{algorithm}
mengchaoheng commented 1 year ago

这是个好想法,需要这个东西的专业不多,然后需要写这些的同学都有实力去开发一下,如果您能添加这个功能可以推pr给我,谢谢。

mengchaoheng commented 1 year ago

我GitHub消息和邮件同步,可以实时收到消息

mengchaoheng commented 1 year ago

然后这个模版有很多祖传代码,我一直找机会重构它,推翻重来,加上大部分专业需要使用的功能。可惜暂时没合适的机会。

Droliven commented 1 year ago
  1. 首先在主要文件入口 头部添加:

    \usepackage{algorithm}
    \usepackage{algpseudocode}
    \renewcommand{\algorithmicrequire}{ \textbf{输入:}} 
    \renewcommand{\algorithmicensure}{ \textbf{输出:}}
    % \renewcommand{\algorithmicname}{算法}
    \makeatletter
    \renewcommand*{\ALG@name}{算法}
    \makeatother
  2. 然后在需要引入伪代码的正文其他地方写:

    \begin{algorithm}[!t]
    \caption{增强多样化变分自编码器 d-CVAE 的训练过程}
    \label{alg:rank_train}
    \begin{algorithmic}[1]
    \Require Observed pose sequence $\mathbf{x}$, number of samples $K$, auxiliary space generation network $\mathcal{N}_{\bm{\beta}}$, Gaussian distribution generation network $\mathcal{N}_{\bm{\gamma}}$, CVAE decoder network $\mathcal{G}_{\bm{\theta}}$
    \Ensure A set of samples $\{\mathbf{\tilde{y}}_k\}_{k=1}^{K}$
    \State $\mathbf{B} = \mathcal{N}_{\bm{\beta}}(\mathbf{x})$ // \textit{generate an auxiliary space given input poses}
    \State $\mathbf{W} \leftarrow \text{Gumbel-Softmax sampling}$ // \textit{see \rm{Algorithm} \ref{alg:gumbel-softmax}}
    \State $\mathbf{P}=\mathbf{W}\mathbf{B}$ // \textit{Multiply $\mathbf{W}$ and $\mathbf{B}$ to obtain a point matrix $\mathbf{P}$}
    \State $\left\{\mathbf{A}_k,\mathbf{b}_k\right\}_{k=1}^K = \mathcal{N}_{\bm{\gamma}}(\mathbf{P})$ // \textit{convert points into means and variances}
    \State $\bm{\epsilon}  \sim \mathcal{N}(0,1)$ // \textit{sampling an $\bm{\epsilon}$ from the normal distribution}
    \For{$k=1$ to $K$}
    \State $\mathbf{z}_k  = \mathbf{A}_k \mathbf{\bm{\epsilon}} + \mathbf{b}_k$ // \textit{reparameterization trick}
    \State $\mathbf{\tilde{y}}_k  = \mathcal{G}_{\bm{\theta}}(\mathbf{x},\mathbf{z}_k)$ // \textit{decode $\mathbf{z}_k$ and $\mathbf{x}$ into a result $\mathbf{\tilde{y}}_k$}
    \EndFor 
    \end{algorithmic}
    \end{algorithm}
  3. 最后就可以了:

image

mengchaoheng commented 1 year ago

好的我加上,然后标注您为贡献者,特别感谢🙏

Droliven commented 1 year ago

好的呀