• Latex使用:在latex中添加算法模块


    在Miktex下有三个latex algorithm包,分别为:algorithm,algorithmic,algorithm2e三个,其中algorithm,algorithmic经常成套使用:

    latex中algorithm模板为:

    latex文件中顶端加入的package:

    usepackage{algorithm}
    usepackage{algorithmic}
    usepackage{setspace}

    算法块代码:

    egin{algorithm}[htb]
    setstretch{1.35} %设置具有指定弹力的橡皮长度(原行宽的1.35倍)
    caption{}
    label{alg:Framwork}
    egin{algorithmic}
    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$;
    Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;\
    label{ code:fram:extract }
    
    Training ensemble of classifiers $E$ on $T_n cup P_n$, with help of data in former batches;\
    label{code:fram:trainbase}
    
    $E_n=E_{n-1}cup E$;\
    label{code:fram:add}
    
    Classifying samples in $U_n-T_n$ by $E_n$;\
    label{code:fram:classify}
    
    Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;\
    label{code:fram:select}
    
    $E_n$;\
    end{algorithmic}
    end{algorithm}

    实际算法结果图示为:

    第二种用法:

    使用algorithm2e包进行处理

    documentclass{article}
    usepackage{algorithm2e,setspace}
    
    egin{document}
    
    egin{algorithm}
    setstretch{1.35}
    SetAlgoLined
    KwData{this text}
    KwResult{how to write algorithm with LaTeX2e }
    initialization;
    While{not at end of this document}{
    read current;
    eIf{understand}{
    go to next section;
    current section becomes this one;
    }{
    go back to the beginning of current section;
    }
    }
    caption{How to write algorithms}
    end{algorithm}
    
    igskip
    
    egin{algorithm}
    SetAlgoLined
    KwData{this text}
    KwResult{how to write algorithm with LaTeX2e }
    initialization;
    While{not at end of this document}{
    read current;
    eIf{understand}{
    go to next section;
    current section becomes this one;
    }{
    go back to the beginning of current section;
    }
    }
    caption{How to write algorithms}
    end{algorithm}
    
    end{document} 

    上述代码分别对应两个算法,所获得的算法块分别为:

    Latex中的常用算法块如上所述,使用过程中其它技巧可查询之后进行设置。

    上述记录仅用来对latex使用过程中的心得体会进行总结。

    个人感悟:写latex一定要静下心,要不然很容易出现低级错误。遇到不会的格式或方法,勤用搜索引擎去寻找答案。

    其实在这里自己是被行距问题卡了很长时间,遇到的问题是因为算法的行距太小:

    行距问题的设置网络搜索就可以解决,查阅刘海洋的《latex入门》也可以得到很好解决。

  • 相关阅读:
    洛谷P2504 [HAOI2006]聪明的猴子
    洛谷P1516 青蛙的约会
    洛谷P1991 无线通讯网
    洛谷P1265 公路修建
    可展开的列表组件
    网格视图(GridView)功能和用法
    自动完成文本框的功能和用法
    扩展BaseAdapter实现不存储列表项的ListView
    使用SimpleAdapter创建ListView
    实例:基于ListActivity实现列表
  • 原文地址:https://www.cnblogs.com/empty16/p/6222885.html
Copyright © 2020-2023  润新知