-
Notifications
You must be signed in to change notification settings - Fork 25
/
lsbooktest.tex
350 lines (288 loc) · 13.4 KB
/
lsbooktest.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
% !TeX document-id = {96b7c153-3a28-4e93-b6cb-e11439734af4}
% !TeX TXS-program:compile = txs:///latexmk/{}[-xelatex -synctex=1 -interaction=nonstopmode -shell-escape]
\documentclass[green]{lsbook}
\tcbuselibrary{listings}
\title{一个中文书籍的\LaTeX{}模板}
\DedicatedTo{需要一个书籍模板的人}
\subtitle{这里可以放一个副标题}
\author{张三}% 默认值
\BookSeries{计算机应用技术丛书}% 可取消
\BookIntroduction{这个图书模板是在群主网站上的一个封面模板的基础上改写而成的,设定了一些图书出版要素,设计了封面、扉页及版权页和封底的样式,修改了chapter的样式,并提供了几个选项可切换色彩风格,其余则维持book基本文档类的设定。\par 图书模板部分代码的完成得到了林莲枝大神的帮助,在此表示感谢。由于作者水平有限,模板代码编写不恰当之处还请用户提出批评和指正。\par 感谢造字工坊提供了刻宋、郎宋和黄金时代三种非商业可免费下载使用的字体。\par 感谢谷歌提供自由使用的思源宋体、思源黑体。\par 感谢文泉驿提供的开源的文泉驿等宽微米黑字体。}
\Publisher{\LaTeX Studio 出版社} %默认值
\Designer{张三丰}
\Editor{张三丰}
\edition{2}% 可取消
\Price{26.5}
\isbn{978-80-7340-097-2}
% 自己所有的设置都放到settings.tex里面
\input{settings.tex}
\begin{document}
\maketitle
\makeflypage
\frontmatter
\tableofcontents
\mainmatter
\chapter{模板使用说明}
\mybox{关于代码排版盒子中使用listings和minted的说明}
由于使用minted对于初学者来说比较难以配置,所以,这里根据用户编译选项中是否使用\\
\verb|--shell-escape|来自动切换使用listings还是minted。不用担心,命令使用上没有任何不同,只是输出效果上有差别。
首先我们简要说明一下目前已经开发出来的模板功能,包括字体选择和颜色选择。
\section{颜色选择}
目前颜色选择共三种,\texttt{green},\texttt{orange}和\texttt{violet},默认为\texttt{green}。你也可以自己设置 \texttt{cvprimary}, \texttt{cvsecondary} 以及 \texttt{cvtext},定制你自己喜欢的色盘。
\begin{tcblisting}{listing only,applelight,title={自己来设定颜色吧!},
listing options={numbers=none,basicstyle=\ttfamily,columns=fullflexible,
language={[LaTeX]TeX},moretexcs={colorlet,definecolor,PassOptionsToPackage}}
}
% 如果想要用 xcolor 宏包已定义的颜色,记得要在 \documentclass 之前
% 传递相应的 xcolor 选项。
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass{lsbook}
% cvprimary 为封面、标题盒子最外围的颜色
\colorlet{cvprimary}{SkyBlue}
% cvsecondary 为封面、标题盒子主要填充的颜色
\colorlet{cvsecondary}{RoyalBlue}
% cvtext 为封面、标题盒子里文字的颜色,也可以自己给出
% 特定的色值。
\definecolor{cvtext}{HTML}{EEEEFF}
\end{tcblisting}
\section{字体选择}
目前字体选择共两种,\texttt{customfont}和\texttt{systemfont},默认为\texttt{systemfont}。
若要使用\texttt{customfont},需要安装相应的字体。
若要使用\texttt{systemfont},则模板直接调用系统内部字体。
\section{几个可有可无的 tcolorbox 设置}
现有 \texttt{appledark}, \texttt{applelight}, \texttt{win10dark}, \texttt{win10light} 四个选项。
如果是供荧幕阅读的还好;如果是要打印出来的,除非您就是打印店的老板,不然还是不要多用 \texttt{*dark} 选项。
\begin{tcolorbox}[appledark,title={世界你好!}]
天气好吗?吃饱了吗?
\end{tcolorbox}
\begin{tcolorbox}[applelight,title={世界你好!}]
天气好吗?吃饱了吗?
\end{tcolorbox}
\subsection{Ubuntu Terminal}
\begin{GitExampla}{TensorFlow@xubuntu:$\sim$}
TensorFlow@xubuntu:~$
---------- TRAINING -------------
Epoch: 004/020 cost: 1.41867 train_accuray:0.63000 test_accuray:0.62820
Epoch: 008/020 cost: 0.98922 train_accuray:0.71000 test_accuray:0.72040
Epoch: 012/020 cost: 0.81536 train_accuray:0.70000 test_accuray:0.76270
Epoch: 016/020 cost: 0.71605 train_accuray:0.83000 test_accuray:0.78570
Epoch: 020/020 cost: 0.65017 train_accuray:0.82000 test_accuray:0.80130
\end{GitExampla}
\mybox{灰色主题的盒子}
\begin{tcolorbox}[win10dark,title={世界你好!}]
天气好吗?吃饱了吗?
\end{tcolorbox}
\begin{tcolorbox}[win10light,title={世界你好!}]
天气好吗?吃饱了吗?
\end{tcolorbox}
\chapter{代码盒子}
\begin{langCVOne}{SIFT算法}
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 22 19:22:10 2014
@author: duan
"""
import cv2
import numpy as np
img = cv2.imread('home.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT()
kp = sift.detect(gray,None)
img=cv2.drawKeypoints(gray,kp)
cv2.imwrite('sift_keypoints.jpg',img)
\end{langCVOne}
\begin{langCVOne}[matlab][m:2]{Matlab求解}
b1 = [-6;0];
a1 = [-3 -2;1 0];
d1 = [0;5/2];
format rat;
alpha1 = b1\(a1*d1) % 右乘a1
\end{langCVOne}
\begin{langPyOne}{Haar cascading detection in OpenCV}
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 30 11:06:23 2014
@author: duan
"""
import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('sachin.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detects objects of different sizes in the input image.
# The detected objects are returned as a list of rectangles.
# cv2.CascadeClassifier.detectMultiScale(image, scaleFactor, minNeighbors, flags, minSize, maxSize)
# scaleFactor – Parameter specifying how much the image size is reduced at each image
# scale.
# minNeighbors – Parameter specifying how many neighbors each candidate rectangle should
# have to retain it.
# minSize – Minimum possible object size. Objects smaller than that are ignored.
# maxSize – Maximum possible object size. Objects larger than that are ignored.
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
\end{langPyOne}
\begin{langPyTwo}[python]{Single GPU computation time: 0:00:11.833497\\Multi GPU computation time: 0:00:07.085913}{Multi-GPU Basics}
import numpy as np
import tensorflow as tf
import datetime
#Processing Units logs
log_device_placement = True
#num of multiplications to perform
n = 10
# Example: compute A^n + B^n on 2 GPUs
# Create random large matrix
A = np.random.rand(1e4, 1e4).astype('float32')
B = np.random.rand(1e4, 1e4).astype('float32')
# Creates a graph to store results
c1 = []
c2 = []
# Define matrix power
def matpow(M, n):
if n < 1: #Abstract cases where n < 1
return M
else:
return tf.matmul(M, matpow(M, n-1))
# Single GPU computing
with tf.device('/gpu:0'):
a = tf.constant(A)
b = tf.constant(B)
#compute A^n and B^n and store results in c1
c1.append(matpow(a, n))
c1.append(matpow(b, n))
with tf.device('/cpu:0'):
sum = tf.add_n(c1) #Addition of all elements in c1, i.e. A^n + B^n
t1_1 = datetime.datetime.now()
with tf.Session(config=tf.ConfigProto(log_device_placement=log_device_placement)) as sess:
# Runs the op.
sess.run(sum)
t2_1 = datetime.datetime.now()
# Multi GPU computing
# GPU:0 computes A^n
with tf.device('/gpu:0'):
#compute A^n and store result in c2
a = tf.constant(A)
c2.append(matpow(a, n))
#GPU:1 computes B^n
with tf.device('/gpu:1'):
#compute B^n and store result in c2
b = tf.constant(B)
c2.append(matpow(b, n))
with tf.device('/cpu:0'):
sum = tf.add_n(c2) #Addition of all elements in c2, i.e. A^n + B^n
t1_2 = datetime.datetime.now()
with tf.Session(config=tf.ConfigProto(log_device_placement=log_device_placement)) as sess:
# Runs the op.
sess.run(sum)
t2_2 = datetime.datetime.now()
print "Single GPU computation time: " + str(t2_1-t1_1)
print "Multi GPU computation time: " + str(t2_2-t1_2)
\end{langPyTwo}
\begin{GitExample}{Output Data}{TensorFlow@xubuntu:$\sim$}
TensorFlow@xubuntu:~$ python3 test.py
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
train shape: (55000, 784) (55000, 10)
test shape: (10000, 784) (10000, 10)
----------MNIST loaded----------------
NeuralNetwork Ready!
2018-08-02 00:11:15.818190: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-08-02 00:11:16.044897: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:0a:00.0
totalMemory: 10.92GiB freeMemory: 3.04GiB
2018-08-02 00:11:16.044948: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:0a:00.0, compute capability: 6.1)
---------- TRAINING -------------
Epoch: 004/020 cost: 1.41867 train_accuray:0.63000 test_accuray:0.62820
Epoch: 008/020 cost: 0.98922 train_accuray:0.71000 test_accuray:0.72040
Epoch: 012/020 cost: 0.81536 train_accuray:0.70000 test_accuray:0.76270
Epoch: 016/020 cost: 0.71605 train_accuray:0.83000 test_accuray:0.78570
Epoch: 020/020 cost: 0.65017 train_accuray:0.82000 test_accuray:0.80130
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
train shape: (55000, 784) (55000, 10)
test shape: (10000, 784) (10000, 10)
----------MNIST loaded----------------
NeuralNetwork Ready!
2018-08-02 00:11:15.818190: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-08-02 00:11:16.044897: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:0a:00.0
totalMemory: 10.92GiB freeMemory: 3.04GiB
2018-08-02 00:11:16.044948: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:0a:00.0, compute capability: 6.1)
\end{GitExample}
\section{settings.sty的一些设置和宏包的使用}
得$\hat{a}_k=\dfrac{6}{5}$
$\succeq\succ\prec\preceq$$xyz\textsl{x}\text{x}$
\begin{align*}
\nabla_xL(x,\nu) = 2x + A^T\nu = 0,
\end{align*}
\subsection{线性规划问题}
\mybox{考虑标准形式的线性规划问题}
\begin{align*}
b^T &= \begin{bmatrix}
b_1 & b_2 & \cdots & b_n
\end{bmatrix}\\
x^T &= \begin{bmatrix}
x_1 & x_2 & \cdots & x_n
\end{bmatrix}\\
b^T\nu &= \nu^Tb
\end{align*}
如果我们猜测$x$的值为$\hat{x}$,也就是隐含地猜测$v$的值为$y-A\hat{x}$。假设$v$(在$\|\cdot\|$度量下)越小越可信,那么对于$x$的最有可信的猜测是
\begin{align}
\hat{x} = \argmin_z \|Az - y\|
\end{align}
考虑子空间$\symcal{A} = \symcal{R}(A)\subseteq\symbf{R}^m$和一个点$b\in\symbf{R}^m$。点$b$向子空间$\symcal{A}$的\textsf{投影}是$\symcal{A}$中在$\|\cdot\|$下最靠近$b$的点,也就是说,它是下列问题的任意最优解
将$\symcal{R}(A)$中的元素参数化为$u=Ax$,我们可以看出求解范数逼近问题(6.1)等价于计算$b$向$\symcal{A}$的投影。
Newton方法是求解无约束优化问题的有效算法,干净优化问题的一个特例就是经常遇到的最小二乘问题
其最优性条件
\[
A^TAx^\ast = A^Tb
\]
被称为最小二乘问题的\textsf{正规方程}
\mbox{无约束几何规划}
作为第二个盒子,我们考虑凸的无线事几何规划问题
其最优性条件为
\[
\nabla f(x^\ast) = \frac{1}{\sum\limits_{j=1}^m\exp(a^T_jx^\ast + b_j)}\sum_{i=1}^{m}\exp(a^T_ix^\ast+b_i)a_i=0.
\]
一般情况下该方程组没有解析解,因此我们必须采用迭代算法。由于$\symbf{dom}f=\symbf{R}^n$,斜体点都可以用作初始点$x^{(0)}$。
\begin{align}\label{eq:3}
f(y) \leqslant f(x) + \nabla f(x)^T(y-x) + \frac{m}{2}\|y-x\|^2
\end{align}
对任意固定的$x$,\cref{eq:3}的右边是$y$的二次凸函数。令其关于$y$的层数等于零,即
\begin{align}\label{eq:4}
\frac{\partial\bigl[f(x) + \nabla f(x)^T(y-x) + \frac{m}{2}\|y-x\|_2^2\bigr]}{\partial y} &= 0\\
0 + \nabla f(x) + m(y-x) &=0\label{eq:5}
\end{align}
其中$y>x$,可以得到该二次函数的最优解$\tilde{y}=x-(1/m)\nabla f(x)$。
二次型函数极点
\[\left(-\frac{b}{2a},\frac{4ac-b^2}{4a}\right)\]
\mybox{unicode-math的一些说明}
这里使用的数学宏包是unicode-math,但是两个命令可能通用,效果是一样的。
\includegraphics[width=0.7\linewidth]{unimath}
\mybox{直接引入文件来排版代码}
有些语言的名称调用在listings和minted里面是有区别的,现在发现的有latex,lisings是\verb|[LaTeX]TeX|,而minted是\verb|TeX|。
\begin{langCVOne}{使用方法}
\langCVfile[代码语言][盒子标签][语言名显示]{标题}{文件名} # 中文注释
\gitfile[代码语言]{标题}{文件名}
\langPyfile[代码语言]{标题}{文件名}
\end{langCVOne}
\langCVfile{testInput}{helloworld.py}
\gitfile{testInput}{helloworld.py}
\langPyfile{testInput}{helloworld.py}
\makebackcover
\end{document}