latex-算法

#.latex安装:sudo apt-get install texlive-full;
#.latex字体安装:https://blog.csdn.net/u010238520/article/details/78972969;

latex 算法

algorithm例子

前期准备

\usepackage{algorithm}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm  
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm  

代码

  \begin{algorithm}[htb]
  \caption{ Framework of ensemble learning for our system.}
  \label{alg:Framwork}
  \begin{algorithmic}[1]
    \Require
      The set of positive samples for current batch, $P_n$;
      The set of unlabelled samples for current batch, $U_n$;
      Ensemble of classifiers on former batches, $E_{n-1}$;
    \Ensure
      Ensemble of classifiers on the current batch, $E_n$;
    \State Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;
    \label{code:fram:extract}
    \State Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches;
    \label{code:fram:trainbase}
    \State $E_n=E_{n-1}cup E$;
    \label{code:fram:add}
    \State Classifying samples in $U_n-T_n$ by $E_n$;
    \label{code:fram:classify}
    \State Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;
    \label{code:fram:select} \\
    \Return $E_n$;
  \end{algorithmic}
\end{algorithm}

效果
在这里插入图片描述

\documentclass[11pt]{ctexart}  
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}  
\usepackage{algorithm}  
\usepackage{algorithmicx}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  
  
\floatname{algorithm}{算法}  
\renewcommand{\algorithmicrequire}{\textbf{输入:}}  
\renewcommand{\algorithmicensure}{\textbf{输出:}}  
  
\begin{document}  
    \begin{algorithm}  
        \caption{用归并排序求逆序数}  
        \begin{algorithmic}[1] %每行显示行号  
            \Require $Array$数组,$n$数组大小  
            \Ensure 逆序数  
            \Function {MergerSort}{$Array, left, right$}  
                \State $result \gets 0$  
                \If {$left < right$}  
                    \State $middle \gets (left + right) / 2$  
                    \State $result \gets result +$ \Call{MergerSort}{$Array, left, middle$}  
                    \State $result \gets result +$ \Call{MergerSort}{$Array, middle, right$}  
                    \State $result \gets result +$ \Call{Merger}{$Array,left,middle,right$}  
                \EndIf  
                \State \Return{$result$}  
            \EndFunction  
            \State  
            \Function{Merger}{$Array, left, middle, right$}  
                \State $i\gets left$  
                \State $j\gets middle$  
                \State $k\gets 0$  
                \State $result \gets 0$  
                \While{$i<middle$ \textbf{and} $j<right$}  
                    \If{$Array[i]<Array[j]$}  
                        \State $B[k++]\gets Array[i++]$  
                    \Else  
                        \State $B[k++] \gets Array[j++]$  
                        \State $result \gets result + (middle - i)$  
                    \EndIf  
                \EndWhile  
                \While{$i<middle$}  
                    \State $B[k++] \gets Array[i++]$  
                \EndWhile  
                \While{$j<right$}  
                    \State $B[k++] \gets Array[j++]$  
                \EndWhile  
                \For{$i = 0 \to k-1$}  
                    \State $Array[left + i] \gets B[i]$  
                \EndFor  
                \State \Return{$result$}  
            \EndFunction  
        \end{algorithmic}  
    \end{algorithm}  
\end{document}  

效果
在这里插入图片描述

{
// Latex workshop
“latex-workshop.latex.tools”: [
{
“name”: “latexmk”,
“command”: “latexmk”,
“args”: [
“-synctex=1”,
“-interaction=nonstopmode”,
“-file-line-error”,
“-pdf”,
“%DOC%”
]
},
{
“name”: “xelatex”,
“command”: “xelatex”,
“args”: [
“-synctex=1”,
“-interaction=nonstopmode”,
“-file-line-error”,
“%DOC%”
]
},
{
“name”: “pdflatex”,
“command”: “pdflatex”,
“args”: [
“-synctex=1”,
“-interaction=nonstopmode”,
“-file-line-error”,
“%DOC%”
]
},
{
“name”: “bibtex”,
“command”: “bibtex”,
“args”: [
“%DOCFILE%”
]
}
],
“latex-workshop.latex.recipes”: [
{
“name”: “xelatex”,
“tools”: [
“xelatex”
]
},
{
“name”: “latexmk”,
“tools”: [
“latexmk”
]
},

      {
        "name": "pdflatex -> bibtex -> pdflatex*2",
        "tools": [
        "pdflatex",
        "bibtex",
        "pdflatex",
        "pdflatex"
                    ]
      }
    ],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.clean.enabled": true,
"latex-workshop.latex.clean.fileTypes": [
    "*.aux",
    "*.bbl",
    "*.blg",
    "*.idx",
    "*.ind",
    "*.lof",
    "*.lot",
    "*.out",
    "*.toc",
    "*.acn",
    "*.acr",
    "*.alg",
    "*.glg",
    "*.glo",
    "*.gls",
    "*.ist",
    "*.fls",
    "*.log",
    "*.fdb_latexmk"
  ],
  "explorer.confirmDelete": false,

“fileheader.customMade”: {
“Copyright”: “Copyright 2018 Baidu Inc. All Rights Reserved.”,
“Author”: “Xiaotao Li ([email protected])”,
“Date”: “Do not edit”,
“LastEditors”: “Xiaotao Li ([email protected])”,
“LastEditTime”: “Do not edit”,
“”:"",
“Description”: “”,

},
“workbench.colorTheme”: “Monokai”,
“window.zoomLevel”: 0
}

链接:https://blog.csdn.net/lwb102063/article/details/53046265

发布了21 篇原创文章 · 获赞 0 · 访问量 9507

猜你喜欢

转载自blog.csdn.net/qq_40230900/article/details/82775206
今日推荐