forked from yanping/r-spring-camp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.tex
316 lines (260 loc) · 8.51 KB
/
demo.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
\documentclass[ignorenonframetext,]{beamer}
\usepackage{amssymb,amsmath}
\usepackage[boldfont,slantfont,CJKsetspaces,CJKchecksingle]{xeCJK}
\newcommand{\hurl}[1]{\href{#1}{\color{blue}#1}} %自定义的命令\hurl
\usepackage{ifxetex,ifluatex}
% 表格环境
\usepackage{longtable}
% 下面三行是表格脚注的定义
\makeatletter
\def\fnum@table{\tablename~\thetable}
\makeatother
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setCJKmainfont{文泉驿微米黑}
\setCJKsansfont{Kaiti}
\setCJKmonofont{SimSun}
\punctstyle{quanjiao}
\else
\ifluatex
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\else
\usepackage[utf8]{inputenc}
\fi
\fi
\usepackage{color}
\usepackage{fancyvrb}
\DefineShortVerb[commandchars=\\\{\}]{\|}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
% Redefine labelwidth for lists; otherwise, the enumerate package will cause
% markers to extend beyond the left margin.
% \makeatletter\AtBeginDocument{%
% \renewcommand{\@listi}
% {\setlength{\labelwidth}{4em}}
% }\makeatother
\usepackage{enumerate}
\usepackage{ctable}
\usepackage{float} % provides the H option for float placement
\usepackage{url}
% Comment these out if you don't want a slide with just the
% part/section/subsection/subsubsection title:
\AtBeginPart{\frame{\partpage}}
\AtBeginSection{\frame{\sectionpage}}
\AtBeginSubsection{\frame{\subsectionpage}}
\AtBeginSubsubsection{\frame{\subsubsectionpage}}
% \setlength{\parindent}{0pt}
% \setlength{\parskip}{6pt plus 2pt minus 1pt}
% \setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{0}
\title{R语言春令营(1):导论}
\author{\href{mailto:[email protected]}{陈堰平}}
\date{April 14, 2013}
\institute[统计之都]{
统计之都\\
\hurl{http://cos.name}
}
\setbeamertemplate{navigation symbols}{}
\begin{document}
\frame{\titlepage}
\section{R的安装}
\begin{frame}\frametitle{Reproducibility}
\begin{itemize}
\item
Same script
\item
Same results
\item
Anywhere
\begin{itemize}
\item
Single thread
\item
Multi-core
\item
Cloud Scale
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Everything starts with a seed.}
Simulation is based off Pseudo-random number generation (PRNG).
\begin{itemize}
\item
PRNG is sequential, next number depends on the last state.
\item
Seeds are used to store the state of a random number generator
\item
by `Setting a seed' one can place a PRNG into any exact state.
\end{itemize}
\end{frame}
\begin{frame}\frametitle{Parallel Random Number Generation}
Simulation is complicated in new parallel environments.
\begin{itemize}
\item
PRNG is sequential,
\item
parallel execution is not,
\item
and order of execution is not guaranteed.
\end{itemize}
\textbar{} Right \textbar{} Left \textbar{} Default \textbar{} Center
\textbar{}
\textbar{}------:\textbar{}:-----\textbar{}---------\textbar{}:------:\textbar{}
\textbar{} 12 \textbar{} 12 \textbar{} 12 \textbar{} 12 \textbar{}
\textbar{} 123 \textbar{} 123 \textbar{} 123 \textbar{} 123 \textbar{}
\textbar{} 1 \textbar{} 1 \textbar{} 1 \textbar{} 1 \textbar{}
: Demonstration of simple table syntax.
This is where parallel pseudo-random number generators help out.
\end{frame}
\begin{frame}\frametitle{Parallel PRNG}
Parallel pseudo-random number generators start with a singe state that
can spawn additional streams as well as streams of random numbers.
\begin{enumerate}[1.]
\item
SPRNG
\item
L'Ecuyer combined multiple-recursive generator
\end{enumerate}
\ctable[caption = Here's the caption., pos = H, center, botcap]{clrl}
{% notes
}
{% rows
\FL
\parbox[b]{0.17\columnwidth}{\centering
Centered Header
} & \parbox[b]{0.11\columnwidth}{\raggedright
Default Aligned
} & \parbox[b]{0.22\columnwidth}{\raggedleft
Right Aligned
} & \parbox[b]{0.35\columnwidth}{\raggedright
Left Aligned
}
\ML
\parbox[t]{0.17\columnwidth}{\centering
First
} & \parbox[t]{0.11\columnwidth}{\raggedright
row
} & \parbox[t]{0.22\columnwidth}{\raggedleft
12.0
} & \parbox[t]{0.35\columnwidth}{\raggedright
Example of a row that spans multiple lines.
}
\\\noalign{\medskip}
\parbox[t]{0.17\columnwidth}{\centering
Second
} & \parbox[t]{0.11\columnwidth}{\raggedright
row
} & \parbox[t]{0.22\columnwidth}{\raggedleft
5.0
} & \parbox[t]{0.35\columnwidth}{\raggedright
Here's another one. Note the blank line between rows.
}
\LL
}
\end{frame}
\section{R包的使用}
\begin{frame}[fragile]\frametitle{R package \texttt{harvestr}}
\url{https://github.com/halpo/harvestr}
What \texttt{harvestr} does:
\begin{itemize}
\item
Reproducibility
\item
Caching
\item
Under parallelized environments.
\end{itemize}
\end{frame}
\begin{frame}\frametitle{How \texttt{harvestr} works}
\begin{itemize}
\item
Analytical elements are separated into work-flows of dependent
elements.
\begin{itemize}
\item
Set up environment/seed
\item
Generate Data
\item
Perform analysis
\begin{itemize}
\item
Stochastic
\item
Non-Stochastic
\end{itemize}
\item
Summarize
\end{itemize}
\item
Results from one step carry to another by carrying the seed with the
results.
\end{itemize}
\end{frame}
\begin{frame}[fragile]\frametitle{\textbf{Primary work-flow} for
\texttt{harvestr}}
\begin{itemize}
\item
\texttt{gather(n)} - generate \texttt{n} random number streams.
\item
\texttt{farm(seeds, expr)} - evaluate \texttt{expr} with each seed in
\texttt{seeds}.
\item
\texttt{harvest(x, fun)} - for each data in \texttt{x} call the
function \texttt{fun}
\end{itemize}
\end{frame}
\section{数据管理}
\begin{frame}[fragile]\frametitle{Building blocks}
Some building blocks that might \emph{might} be helpful.
\begin{itemize}
\item
\texttt{plant}- for setting up copies of an object with given seeds.
\item
\texttt{sprout} - for obtaining the sub-streams used with graft.
\item
\texttt{reap} - single object version of \texttt{harvest}
\end{itemize}
\end{frame}
\begin{frame}[fragile]\frametitle{In case you are wondering}
\begin{itemize}
\item
Yes it works with \texttt{Rcpp} code,
\item
provided the compiled code uses the RNGScope for RNG in C++.
\item
\textbf{But} take care to not carry C++ reference objects across
parallel calls.
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{seeds <- }\KeywordTok{gather}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DataTypeTok{seed=}\DecValTok{20120614}\NormalTok{)}
\NormalTok{data <- }\KeywordTok{farm}\NormalTok{(seeds, \{}
\NormalTok{x1 <- }\KeywordTok{rnorm}\NormalTok{(}\DecValTok{400}\NormalTok{)}
\NormalTok{x2 <- }\KeywordTok{rnorm}\NormalTok{(}\DecValTok{400}\NormalTok{)}
\NormalTok{g <- }\KeywordTok{rep}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{4}\NormalTok{), }\DataTypeTok{each=}\DecValTok{100}\NormalTok{)}
\NormalTok{trt <- }\KeywordTok{rep}\NormalTok{(}\DecValTok{1}\NormalTok{:}\DecValTok{4}\NormalTok{, }\DataTypeTok{each=}\DecValTok{100}\NormalTok{)}
\NormalTok{y <- }\KeywordTok{rnorm}\NormalTok{(}\DataTypeTok{n=}\DecValTok{400}\NormalTok{, }\DataTypeTok{mean=}\DecValTok{3}\NormalTok{*x1 + x2 + g)}
\KeywordTok{data.frame}\NormalTok{(y, x1, x2, trt)}
\NormalTok{\})}
\end{Highlighting}
\end{Shaded}
\end{frame}
\end{document}