LaTeX-Templates-LabReport-02-or-ShortNotes-02

A nice templates for notes in both Chinese and English.

Code

main.tex

%!TEX program = xelatex
% 完整编译方法 1 pdflatex -> bibtex -> pdflatex -> pdflatex
% 完整编译方法 2: xelatex -> bibtex -> xelatex -> xelatex

\documentclass[lang=cn,11pt]{elegantpaper}
\usepackage{float}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{lfonts}{
	basicstyle = \footnotesize\ttfamily,
	stringstyle = \color{purple},
	keywordstyle = \color{blue!60!black}\bfseries,
	commentstyle = \color{olive}\scshape,
}
\lstdefinestyle{lnumbers}{
	numbers = left,
	numberstyle = \tiny,
	numbersep = 1em,
	firstnumber = 1,
	stepnumber = 1,
}
\lstdefinestyle{llayout}{
	breaklines = true,
	tabsize = 2,
	columns = flexible,
}
\lstdefinestyle{lgeometry}{
	xleftmargin = 20pt,
	xrightmargin = 0pt,
	frame = tb,
	framesep = \fboxsep,
	framexleftmargin = 20pt,
}
\lstdefinestyle{lgeneral}{
	style = lfonts,
	style = lnumbers,
	style = llayout,
	style = lgeometry,
}
\lstdefinestyle{python}{
	language = {Python},
	style = lgeneral,
}

\newcommand{\dis}{\displaystyle}
\newcommand{\dd}{{\rm d}}
\title{Report on SVM}
\author{朱家乐 2018011070}

\institute{THU EE82}

% 不需要版本信息,直接注释即可
%\version{0.07}
% 不需要时间信息的话,需要把 \today 删除。
\date{\today}


% 如果想修改参考文献样式,请把这行注释掉
% \usepackage[authoryear]{gbt7714}  % 国标

\begin{document}

\maketitle

%\begin{abstract}
%\noindent 本文为 \href{https://github.com/ElegantLaTeX/ElegantPaper/}{ElegantPaper} 的说明文档(中文)。此模板基于 \LaTeX{} 的 article 类,专为工作论文写作而设计。设计这个模板的初衷是让作者不用关心工作论文的格式,专心写作,从而有更加舒适,简便的写作体验。如果你有其他问题、建议或者报告 bug,可以在 \href{https://github.com/ElegantLaTeX/ElegantPaper/issues}{ElegantPaper/issues} 留言。如果你想了解更多由 Elegant\LaTeX{} 项目组设计的模板,请访问 \href{https://github.com/ElegantLaTeX/}{https://github.com/ElegantLaTeX/}。
%\keywords{Elegant\LaTeX{},工作论文,模板}
%\end{abstract}

\textsl{利用支持向量机实现图像分类。附件中是利用VGG深度神经网络提取到的Caltech256数据集中10类目标的特征,
试基于SVM结合上述深度学习特征对图像进行分类。}
\section{二分类SVM}

\textsl{随机选取10类中某一个类别为主类别,判定某一类别是否为相应类别,利用二分类线性SVM在学习模型参数进行预测,统计训练集和测试集上的分类准确率。}

\subsection{实现思路}

选择类别标号"1"为主类别,查看 \lstinline|sklearn| 文档后发现直接调用 \lstinline|LinearSVC| 即可完成相应功能。之后我选择利用\lstinline|sklearn.manifold|
里的\lstinline|TSNE|对4096维数据进行降维,可视化结果。

核心代码:
\begin{lstlisting}[style = python]
	clf = svm.LinearSVC() #设置参数
	clf.fit(x_train,y_train_binary) #训练
	####
	X_embedded = TSNE(n_components=2).fit_transform(X)
\end{lstlisting}

其中参数都选为默认,即:
\begin{lstlisting}[style = python]
	class LinearSVC(self, penalty='l2', loss='squared_hinge', dual=True, tol=1e-4, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, class_weight=None, verbose=0, random_state=None, max_iter=1000)
\end{lstlisting}

\begin{thebibliography}{99}
	
	\bibitem{ref1}
	H.~Kopka and P.~W. Daly, \emph{A Guide to \LaTeX}, 3rd~ed.\hskip 1em plus
	0.5em minus 0.4em\relax Harlow, England: Addison-Wesley, 1999.
\end{thebibliography}
\end{document}

elegantpaper.cls

% Author: Dongsheng Deng
% Homepage: https://ddswhu.me/
% Email: elegantlatex2e@gmail.com
% Lastest Version: https://github.com/ElegantLaTeX/ElegantPaper

% --- Class structure: identification part
\ProvidesClass{elegantpaper}[2019/04/01 v0.07 ElegantLaTeX Paper class]
\NeedsTeXFormat{LaTeX2e} 


\RequirePackage{kvoptions}
\RequirePackage{ifthen}
\RequirePackage{ifxetex}
\RequirePackage{etoolbox}
\RequirePackage{calc}

\SetupKeyvalOptions{family=ELEGANT, prefix=ELEGANT@, setkeys=\kvsetkeys}
\newcommand{\ekv}[1]{\kvsetkeys{ELEGANT}{#1}}

\DeclareStringOption[en]{lang}
\DeclareVoidOption{cn}{\ekv{lang = cn}}
\DeclareVoidOption{en}{\ekv{lang = en}}

% \PassOptionsToClass{11pt}{article}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\ProcessKeyvalOptions*\relax
\LoadClass{article}



\RequirePackage{amsthm}
\RequirePackage{amsmath,amssymb}

\linespread{1.35}


% indentation, table and figure package
\RequirePackage{indentfirst}
\RequirePackage{booktabs}
\RequirePackage{multicol}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{fancyvrb}
\RequirePackage{abstract}

\graphicspath{{image/}{figure/}{fig/}{img/}}

% caption settings 
\RequirePackage[font=small,labelfont={bf}]{caption} 
\captionsetup[table]{skip=3pt}
\captionsetup[figure]{skip=3pt}

% list/itemize/enumerate setting
\RequirePackage[shortlabels,inline]{enumitem}
\setlist{nolistsep}

% define the hyperref color 
\RequirePackage{xcolor}
\definecolor{winered}{rgb}{0.5,0,0}

% bib-settings
%\RequirePackage{natbib}
%\setlength{\bibsep}{0.0pt}
%\def\bibfont{\footnotesize}

% settings for the geometry
\RequirePackage{hyperref}
\hypersetup{
  pdfborder={0 0 0},
  colorlinks=true,
  linkcolor={winered},
  urlcolor={winered},
  filecolor={winered},
  citecolor={winered},
  linktoc=all,
}
\RequirePackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}

% add the \email cmd 
\newcommand\email[1]{\href{mailto:#1}{\nolinkurl{#1}}}

\PassOptionsToPackage{no-math}{fontspec}
\RequirePackage[UTF8, scheme=plain]{ctex}
\RequirePackage[T1]{fontenc}
\RequirePackage{newtxtext}
\RequirePackage{newtxmath}


\ifdefstring{\ELEGANT@lang}{cn}{
    \theoremstyle{plain}% default
	\newtheorem{theorem}{定理}[section] %
	\newtheorem{lemma}[theorem]{引理} %
	\newtheorem{proposition}[theorem]{性质} %
	\newtheorem*{corollary}{推论} %
	\theoremstyle{definition} %
	\newtheorem{definition}{定义}[section] %
	\newtheorem{conjecture}{猜想}[section] %
	\newtheorem{example}{}[section] %
	\theoremstyle{remark} %
	\newtheorem*{remark}{\normalfont\bfseries 评论} %
	\newtheorem*{note}{\normalfont\bfseries} %
	\newtheorem{case}{\normalfont\bfseries 案例} %
	\renewcommand*{\proofname}{\normalfont\bfseries 证明} %
	\renewcommand\contentsname{目录}
	\renewcommand\refname{参考文献} %
	\renewcommand\figurename{} %
	\renewcommand\tablename{}%
	\newcommand\versiontext{\itshape 版本:}%
	\newcommand\updatetext{\itshape Time:}%
	\renewcommand\abstractname{\hspace{2em}}
	\setlength{\parindent}{2em}
	\renewcommand{\abstracttextfont}{\small\sffamily\kaishu}
	\newcommand{\keywords}[1]{\vskip2ex\par\noindent\normalfont{\bfseries 关键词: } #1}
	\newcommand\figref[1]{{\bfseries 图~\ref{#1}}}
	\newcommand\tabref[1]{{\bfseries 表~\ref{#1}}}
}{\relax}
\ifdefstring{\ELEGANT@lang}{en}{
  \theoremstyle{plain}% default
	\newtheorem{theorem}{Theorem}[section] %
	\newtheorem{lemma}[theorem]{Lemma} %
	\newtheorem{proposition}[theorem]{Proposition} %
	\newtheorem*{corollary}{Corollary} %
	\theoremstyle{definition} %
	\newtheorem{definition}{Definition}[section] %
	\newtheorem{conjecture}{Conjecture}[section] %
	\newtheorem{example}{Example}[section] %
	\theoremstyle{remark} %
	\newtheorem*{remark}{Remark} %
	\newtheorem*{note}{Note} %
	\newtheorem{case}{Case} %
	\renewcommand*{\proofname}{\normalfont\bfseries Proof}%
	\newcommand\versiontext{\itshape Version: }%
	\newcommand\updatetext{\itshape Update: }%
	\renewcommand{\abstracttextfont}{\sffamily\small\kaishu}
	\newcommand{\keywords}[1]{\vskip2ex\par\noindent\normalfont{\bfseries Keywords: } #1}
	\newcommand\figref[1]{{\bfseries Figure~\ref{#1}}}
	\newcommand\tabref[1]{{\bfseries Table~\ref{#1}}}
}{\relax}

\AtBeginEnvironment{verbatim}{\microtypesetup{activate=false}}

\def\IfEmpty#1{%
  \edef\1{\the#1}
  \ifx\1\empty
}
\newtoks\version
\newtoks\institute
\def \ifempty#1{\def\temp{#1} \ifx\temp\empty }
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@ELEGANT@version\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  \global\let\ELEGANT@version\relax
}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE\bfseries \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author\\
        \the\institute
      \end{tabular}\par}%
\vskip 1.5em%
\IfEmpty\version
\else 
{\small \normalfont\kaishu \versiontext \itshape\the\version}
\fi
\ifx\@date\empty
\else
\vskip 0.1em%
 	{\small\normalfont\kaishu \updatetext \itshape \@date}%
\fi
  \end{center}%
  \par
}
  



\DeclareSymbolFont{CMletters}     {OML}{cmm} {m}{it}%
\DeclareSymbolFont{CMsymbols}     {OMS}{cmsy}{m}{n}%
\DeclareSymbolFont{CMlargesymbols}{OMX}{cmex}{m}{n}%

% \let\sum\relax
% \DeclareMathSymbol{\sum}{\mathop}{CMlargesymbols}{"50}%
% \let\int\relax
% \DeclareMathSymbol{\int}{\mathop}{CMlargesymbols}{"5A}%

\let\intop\relax\let\sumop\relax\let\ointop\relax\let\prodop\relax
\DeclareMathSymbol{\sumop}{\mathop}{CMlargesymbols}{"50}
\DeclareMathSymbol{\intop}{\mathop}{CMlargesymbols}{"52}
\DeclareMathSymbol{\ointop}{\mathop}{CMlargesymbols}{"49}
\DeclareMathSymbol{\prodop}{\mathop}{CMlargesymbols}{"59}

% \let\partial\relax
% \DeclareMathSymbol{\partial}{\mathord}{CMletters}{"40}%
% \let\in\relax
%\DeclareMathSymbol{\in}{\mathrel}{CMsymbols}{"32}%
% \let\pi\relax
% \DeclareMathSymbol{\pi}{\mathord}{CMletters}{"19}

Style