Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Tarea

Project: Test 2
Views: 179
1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
% KOMA-Script Presentation
3
% LaTeX Template
4
% Version 1.0 (3/3/13)
5
%
6
% This template has been downloaded from:
7
% http://www.LaTeXTemplates.com
8
%
9
% Original Authors:
10
% Marius Hofert ([email protected])
11
% Markus Kohm ([email protected])
12
% Described in the PracTeX Journal, 2010, No. 2
13
%
14
% Modified for a talk about RPy2 and IPython's Rmagic extension
15
% It's also a demo about SMC's capabilities to write a presentation.
16
% Written by Harald Schilly ([email protected]), 2013-12-03
17
%
18
% License:
19
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
20
%
21
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23
%----------------------------------------------------------------------------------------
24
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
25
%----------------------------------------------------------------------------------------
26
27
\documentclass[
28
paper=128mm:96mm, % The same paper size as used in the beamer class
29
fontsize=11pt, % Font size
30
pagesize, % Write page size to dvi or pdf
31
parskip=half-, % Paragraphs separated by half a line
32
]{scrartcl} % KOMA script (article)
33
34
\linespread{1.12} % Increase line spacing for readability
35
36
%------------------------------------------------
37
% Colors
38
\usepackage{xcolor} % Required for custom colors
39
% Define a few colors for making text stand out within the presentation
40
\definecolor{mygreen}{RGB}{44,85,17}
41
\definecolor{myblue}{RGB}{60,60,204}
42
\definecolor{mybrown}{RGB}{194,164,113}
43
\definecolor{myred}{RGB}{255,66,56}
44
% Use these colors within the presentation by enclosing text in the commands below
45
\newcommand*{\mygreen}[1]{\textcolor{mygreen}{#1}}
46
\newcommand*{\myblue}[1]{\textcolor{myblue}{#1}}
47
\newcommand*{\mybrown}[1]{\textcolor{mybrown}{#1}}
48
\newcommand*{\myred}[1]{\textcolor{myred}{#1}}
49
%------------------------------------------------
50
51
%------------------------------------------------
52
% Margins
53
\usepackage[ % Page margins settings
54
includeheadfoot,
55
top=3.5mm,
56
bottom=3.5mm,
57
left=5.5mm,
58
right=5.5mm,
59
headsep=6.5mm,
60
footskip=8.5mm
61
]{geometry}
62
%------------------------------------------------
63
64
%------------------------------------------------
65
% Fonts
66
\usepackage[T1]{fontenc} % For correct hyphenation and T1 encoding
67
\usepackage{lmodern} % Default font: latin modern font
68
\usepackage{utopia} % Alternative font: utopia
69
%\usepackage{charter} % Alternative font: low-resolution roman font
70
\renewcommand{\familydefault}{\sfdefault} % Sans serif - this may need to be commented to see the alternative fonts
71
%------------------------------------------------
72
73
%------------------------------------------------
74
% Various required packages
75
\usepackage{amsthm} % Required for theorem environments
76
\usepackage{amsmath}
77
\usepackage{bm} % Required for bold math symbols (used in the footer of the slides)
78
\usepackage{graphicx} % Required for including images in figures
79
\usepackage{tikz} % Required for colored boxes
80
\usepackage{booktabs} % Required for horizontal rules in tables
81
\usepackage{multicol} % Required for creating multiple columns in slides
82
\usepackage{lastpage} % For printing the total number of pages at the bottom of each slide
83
\usepackage[english]{babel} % Document language - required for customizing section titles
84
\usepackage{microtype} % Better typography
85
\usepackage{tocstyle} % Required for customizing the table of contents
86
\usepackage{ulem}
87
\usepackage{verbatim}
88
\usepackage[]{hyperref}
89
\hypersetup{
90
colorlinks = true, %Colours links instead of ugly boxes
91
urlcolor = myblue, %Colour for external hyperlinks
92
linkcolor = myblue, %Colour of internal links
93
citecolor = myblue %Colour of citations
94
}
95
\usepackage{listings}
96
\usepackage{wasysym} % for emoticons
97
%------------------------------------------------
98
99
%------------------------------------------------
100
% Slide layout configuration
101
\usepackage{scrpage2} % Required for customization of the header and footer
102
\pagestyle{scrheadings} % Activates the pagestyle from scrpage2 for custom headers and footers
103
\clearscrheadfoot % Remove the default header and footer
104
\setkomafont{pageheadfoot}{\normalfont\color{black}\sffamily} % Font settings for the header and footer
105
106
% Sets vertical centering of slide contents with increased space between paragraphs/lists
107
\makeatletter
108
\renewcommand*{\@textbottom}{\vskip \z@ \@plus 1fil}
109
\newcommand*{\@texttop}{\vskip \z@ \@plus .5fil}
110
\addtolength{\parskip}{\z@\@plus .25fil}
111
\makeatother
112
113
% Remove page numbers and the dots leading to them from the outline slide
114
\makeatletter
115
\newtocstyle[noonewithdot]{nodotnopagenumber}{\settocfeature{pagenumberbox}{\@gobble}}
116
\makeatother
117
\usetocstyle{nodotnopagenumber}
118
119
\AtBeginDocument{\renewcaptionname{english}{\contentsname}{\Large Outline}} % Change the name of the table of contents
120
%------------------------------------------------
121
122
%------------------------------------------------
123
% Header configuration - if you don't want a header remove this block
124
\ihead{\hspace{-2mm}\begin{tikzpicture}[remember picture,overlay]\node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=myblue!81,bottom color=myblue]{}; % Colored bar\node[below of=mybar,yshift=3.3mm,rectangle,shade,inner sep=0pt,minimum width=128mm,minimum height =1.5mm,top color=black!50,bottom color=white]{}; % Shadow under the colored barshadow
125
\end{tikzpicture}\color{white}\runninghead} % Header text defined by the \runninghead command below and colored white for contrast
126
%------------------------------------------------
127
128
%------------------------------------------------
129
% Footer configuration
130
\newlength{\footheight}
131
\setlength{\footheight}{8mm} % Height of the footer
132
\addtokomafont{pagefoot}{\footnotesize} % Small font size for the footnote
133
134
\ifoot{% Left side
135
\hspace{-2mm}
136
\begin{tikzpicture}[remember picture,overlay]
137
\node [xshift=\paperwidth/2,yshift=\footheight] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=3pt,top color=myblue,bottom color=mygreen]{}; % Green bar
138
\end{tikzpicture}
139
\myauthor\ \raisebox{0.2mm}{$\bm{\vert}$}\ \myuni % Left side text
140
}
141
142
\ofoot[\pagemark/\pageref{LastPage}\hspace{-2mm}]{\pagemark/\pageref{LastPage}\hspace{-2mm}} % Right side
143
%------------------------------------------------
144
145
%------------------------------------------------
146
% Section spacing - deeper section titles are given less space due to lesser importance
147
\usepackage{titlesec} % Required for customizing section spacing
148
\titlespacing{\section}{0mm}{0mm}{0mm} % Lengths are: left, before, after
149
\titlespacing{\subsection}{0mm}{0mm}{-1mm} % Lengths are: left, before, after
150
\titlespacing{\subsubsection}{0mm}{0mm}{-2mm} % Lengths are: left, before, after
151
\setcounter{secnumdepth}{0} % How deep sections are numbered, set to no numbering by default - change to 1 for numbering sections, 2 for numbering sections and subsections, etc
152
%------------------------------------------------
153
154
%------------------------------------------------
155
% Theorem style
156
\newtheoremstyle{mythmstyle} % Defines a new theorem style used in this template
157
{0.5em} % Space above
158
{0.5em} % Space below
159
{} % Body font
160
{} % Indent amount
161
{\sffamily\bfseries} % Head font
162
{} % Punctuation after head
163
{\newline} % Space after head
164
{\thmname{#1}\ \thmnote{(#3)}} % Head spec
165
166
\theoremstyle{mythmstyle} % Change the default style of the theorem to the one defined above
167
\newtheorem{theorem}{Theorem}[section] % Label for theorems
168
\newtheorem{remark}[theorem]{Remark} % Label for remarks
169
\newtheorem{algorithm}[theorem]{Algorithm} % Label for algorithms
170
\makeatletter % Correct qed adjustment
171
%------------------------------------------------
172
173
%------------------------------------------------
174
% The code for the box which can be used to highlight an element of a slide (such as a theorem)
175
\newcommand*{\mybox}[2]{ % The box takes two arguments: width and content
176
\par\noindent
177
\begin{tikzpicture}[mynodestyle/.style={rectangle,draw=myblue,thick,inner sep=2mm,text justified,top color=white,bottom color=white,above}]\node[mynodestyle,at={(0.5*#1+2mm+0.4pt,0)}]{ % Box formatting
178
\begin{minipage}[t]{#1}
179
#2
180
\end{minipage}
181
};
182
\end{tikzpicture}
183
\par\vspace{-1.3em}}
184
%------------------------------------------------
185
186
%----------------------------------------------------------------------------------------
187
% PRESENTATION INFORMATION
188
%----------------------------------------------------------------------------------------
189
190
\newcommand*{\mytitle}{R meets Python in the Cloud} % Title
191
\def\shorttitle{R meets Python}
192
\newcommand*{\runninghead}{\shorttitle} % Running head displayed on almost all slides
193
\newcommand*{\newhead}[1]{\renewcommand*{\runninghead}{\shorttitle: #1}}
194
\newcommand*{\myauthor}{Harald Schilly} % Presenters name(s)
195
\newcommand*{\mydate}{2013-12-03} % Presentation date
196
\newcommand*{\myuni}{University of Vienna
197
\raisebox{0.2mm}{$\bm{\vert}$}\
198
$\text{Vienna} \leftarrow \text{R Meetup}$} % University or department
199
200
%----------------------------------------------------------------------------------------
201
202
\begin{document}
203
204
%----------------------------------------------------------------------------------------
205
% TITLE SLIDE
206
%----------------------------------------------------------------------------------------
207
208
% Title slide - you may have to tweak a few of the numbers if you wish to make changes to the layout
209
\thispagestyle{empty} % No slide header and footer
210
\begin{tikzpicture}[remember picture,overlay] % Background box
211
\node [xshift=\paperwidth/2,yshift=\paperheight/2] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=\paperheight/3,top color=myblue,bottom color=myblue]{}; % Change the height of the box, its colors and position on the page here
212
\end{tikzpicture}
213
% Text within the box
214
\begin{flushright}
215
\vspace{0.65cm}
216
\color{white}\sffamily
217
{\bfseries\Large\mytitle\par} % Title
218
\vspace{0.4cm}
219
\normalsize
220
\myauthor\par % Author name
221
\mydate\par % Date
222
\vfill
223
\end{flushright}
224
225
\clearpage
226
227
%----------------------------------------------------------------------------------------
228
% TABLE OF CONTENTS
229
%----------------------------------------------------------------------------------------
230
231
%\thispagestyle{empty} % No slide header and footer
232
233
%\small\tableofcontents % Change the font size and print the table of contents - it may be useful to shrink the font size further if the presentation is full of sections
234
% To exclude sections/subsections from the table of contents, put an asterisk after \(sub)section like so: \section*{Section Name}
235
236
%\clearpage
237
238
%----------------------------------------------------------------------------------------
239
% PRESENTATION SLIDES
240
%----------------------------------------------------------------------------------------
241
242
\newhead{Motivation}
243
\section{R vs. Python}
244
245
\href{http://www.r-project.org}{\textbf{R}}
246
is a \uline{vertically specialized} environment for statistics.
247
It is based on the domain specific \textbf{S} language (mid 70-ties),
248
has a lot of packages for statistics and supporting functionalities.
249
250
\href{http://www.python.org}{\textbf{Python}} is a general purpose language,
251
designed for beginners (clear syntax, easy to start),
252
very popular (Class A, Tiboe Index),
253
excellent support for extensions and
254
also generally accepted in engineering and scientific areas.
255
256
Remarkably, the latest incarnation of S
257
(``\texttt{\~}''--formulas and \texttt{data.frame})
258
and the first version of Python appeared both in 1991.
259
260
\clearpage
261
262
%------------------------------------------------
263
264
\newhead{Common Ground}
265
\subsection{Common Ground}
266
267
R is primarily an REPL command-line interpreter,
268
which can also run scripts.
269
It manages its own ``world'' of objects.
270
271
In order to interface with R:
272
\begin{itemize}
273
\item{data-structures:} need to be passed in and out.
274
\item{functions:} need to be called from the ``outside''
275
in order to change R's internal state on the ``inside''.
276
\item{plots:} are created in R and need to be made available.
277
\item{speed\&reliability:} everything should happen fast and reliably.
278
\end{itemize}
279
280
281
\clearpage
282
\newhead{RPy2}
283
\section{RPy2}
284
285
There is one famous Python library to accomplish this:
286
\href{http://rpy.sourceforge.net/rpy2.html}{\textbf{RPy2}}
287
288
It is a Python module and it is compiled against R's C Code.
289
That makes it a robust low-level interface.
290
291
R's environment for variable states, the functions, operators,
292
libraries/packages, and other elements are
293
\uline{exposed as Python objects}.
294
295
Exchanging data from and to R is based on
296
converting basic data types, ordered lists, strings,
297
and most notably
298
\href{http://wiki.scipy.org/Tentative_NumPy_Tutorial}{\uline{NumPy Arrays}}.
299
300
\clearpage
301
\newhead{RPy2: Example}
302
303
\begin{lstlisting}[language=python]
304
# evaluate arbitrary code
305
>>> summary = rpy2.robjects.r("...") # .reval(...)
306
307
# a function reference
308
>>> summary = rpy2.robjects.r['summary']
309
310
# calling `seq` directly
311
>>> rpy2.robjects.r.seq(1,10)
312
313
# after activating NumPy Array conversion:
314
>>> xx = np.array([5,4,2.2,-1,-5.5])
315
>>> summary(xx)
316
\end{lstlisting}
317
318
319
\clearpage
320
\newhead{IPython}
321
\section{IPython}
322
323
\href{http://www.ipython.org}{\textbf{IPython}} is probably the most
324
widely used interface to Python for scientific purposes.
325
It's excellent for rapid prototyping, exchanging ideas and results,
326
and publishing: e.~g. \href{http://nbviewer.ipython.org/}{NBViewer} renders them on-line.
327
328
Relevant here: a so called
329
\href{http://ipython.org/ipython-doc/dev/config/extensions/rmagic.html}
330
{\textbf{R-``magic''-extension}} exists,
331
based on RPy2, which helps to conveniently talk to R.
332
333
\clearpage
334
\newhead{IPython: Commands}
335
\subsection{IPython: Commands}
336
337
\begin{itemize}
338
\item{\texttt{\%R}} runs a line of R code: \texttt{result = \%R ...}
339
\item{\texttt{\%\%R -i <invar> -o <outvar> ...}}
340
runs the entire cell in R while converting the given input and output variables.
341
\item{\texttt{\%Rpush <var>}} sends the data of a given variable to R
342
\item{\texttt{\%Rpull <var>}} gets the variable and Python's namespace is populated
343
\item{\texttt{\%Rget <var>}} is similar, only retrieves the actual data.
344
\end{itemize}
345
346
\clearpage
347
\newhead{IPython: Example}
348
\subsection{IPython: Example}
349
350
Simple example:
351
\begin{verbatim}
352
%%R
353
a <- seq(10) + 5.5
354
print(summary(a))
355
\end{verbatim}
356
gives
357
\begin{verbatim}
358
Min. 1st Qu. Median Mean 3rd Qu. Max.
359
6.50 8.75 11.00 11.00 13.25 15.50
360
\end{verbatim}
361
362
\mygreen{$\Rightarrow{}$ All examples shown as part of this talk are
363
\href{http://nbviewer.ipython.org/urls/github.com/sagemath/cloud-examples/raw/master/r/rmagic.ipynb}{\uline{here}}}
364
365
\clearpage
366
\newhead{Sagemath Cloud}
367
\section{Sagemath Cloud}
368
369
\href{https://cloud.sagemath.org}{The Sagemath Cloud} is a web-based online
370
environment for all sorts of computations.
371
It's not only running
372
\href{http://www.sagemath.org}{the Sage mathematical software system},
373
but also R, LaTeX, IPython and much more.
374
Just open a Linux terminal and explore its capabilities \smiley
375
376
All projects can be \textit{shared with collaborators},
377
edits in files are \textit{synchronized} in real-time,
378
and your work is \textit{continuously backed-up}.
379
380
This talk and the examples are part of the
381
\href{https://github.com/sagemath/cloud-examples}{Sagemath Cloud examples repository}.
382
383
\clearpage
384
\newhead{Links}
385
\section{Links}
386
387
\begin{itemize}
388
\item \href{http://rpy.sourceforge.net/rpy2.html}{\textbf{RPy2}}
389
\item \href{http://www.ipython.org}{IPython}
390
\begin{itemize}
391
\item \href{http://ipython.org/ipython-doc/dev/config/extensions/rmagic.html}{R-``magic''-extension}
392
\item \href{http://nbviewer.ipython.org/urls/github.com/sagemath/cloud-examples/raw/master/r/rmagic.ipynb}{IPython Rmagic example}
393
\item \href{http://nbviewer.ipython.org/urls/github.com/ipython/ipython/raw/master/examples/notebooks/R Magics.ipynb}{IPython Documentation Example}
394
\end{itemize}
395
\item \href{https://cloud.sagemath.org}{Sagemath Cloud}
396
\end{itemize}
397
398
399
%------------------------------------------------
400
%------------------------------------------------
401
402
\begin{comment}
403
\begin{multicols}{2} % Divide text into multiple columns
404
\mygreen{Sed diam enim, sagittis nec} condimentum sit amet, ullamcorper sit amet libero. \mybrown{Aliquam vel dui orci}, a porta odio. \myred{Nullam id suscipit} ipsum. \myblue{Aenean lobortis} commodo sem, ut commodo leo gravida vitae. Pellentesque vehicula ante iaculis arcu pretium rutrum eget sit amet purus. Integer ornare nulla quis neque ultrices lobortis. Vestibulum ultrices tincidunt libero, quis commodo erat ullamcorper id.
405
\end{multicols}
406
407
\clearpage
408
409
%------------------------------------------------
410
411
\subsection{Bullet Points and Numbered Lists}
412
413
\begin{itemize}
414
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit
415
\item Aliquam blandit faucibus nisi, sit amet dapibus enim tempus eu
416
\end{itemize}
417
418
\begin{enumerate}
419
\item Nulla commodo, erat quis gravida posuere, elit lacus lobortis est, quis porttitor odio mauris at libero
420
\item Nam cursus est eget velit posuere pellentesque
421
\item Vestibulum faucibus velit a augue condimentum quis convallis nulla gravida
422
\end{enumerate}
423
424
\clearpage
425
426
%------------------------------------------------
427
428
\subsection{Verbatim}
429
430
How to include a theorem in this presentation:
431
\begin{verbatim}
432
\mybox{0.8\textwidth}{
433
\begin{theorem}[Murphy (1949)]
434
Anything that can go wrong, will go wrong.
435
\end{theorem}
436
}
437
\end{verbatim}
438
439
\clearpage
440
441
%------------------------------------------------
442
443
444
\section{Displaying Information}
445
446
\clearpage
447
448
%------------------------------------------------
449
450
\subsection{Table}
451
452
\begin{table}[h]
453
\centering
454
\begin{tabular}{l l l}
455
\toprule
456
\textbf{Treatments} & \textbf{Response 1} & \textbf{Response 2}\\
457
\midrule
458
Treatment 1 & 0.0003262 & 0.562 \\
459
Treatment 2 & 0.0015681 & 0.910 \\
460
Treatment 3 & 0.0009271 & 0.296 \\
461
\bottomrule
462
\end{tabular}
463
\caption{Table caption}
464
\end{table}
465
466
\clearpage
467
468
%------------------------------------------------
469
470
\subsection{Figure}
471
472
\begin{figure}[h]
473
\centering\includegraphics[width=0.4\linewidth]{placeholder}
474
\end{figure}
475
476
\clearpage
477
478
%------------------------------------------------
479
480
\subsection{Theorem}
481
482
The most common definition of \mygreen{Murphy's Law} is as follows.
483
484
\mybox{0.8\textwidth}{ % Example of encapsulating text in a colored box
485
\begin{theorem}[Murphy (1949)]
486
Anything that can go wrong, will go wrong.
487
\end{theorem}
488
}
489
490
\begin{proof}
491
A special case of this theorem is proven in the textbook.
492
\end{proof}
493
494
\begin{remark}
495
This is a remark.
496
\end{remark}
497
498
\begin{algorithm}
499
This is an algorithm.
500
\end{algorithm}
501
502
\clearpage
503
504
505
506
%------------------------------------------------
507
508
\thispagestyle{empty} % No slide header and footer
509
510
\bibliographystyle{unsrt}
511
\bibliography{sample}
512
513
\clearpage
514
515
%------------------------------------------------
516
517
%------------------------------------------------
518
519
\begin{comment}
520
521
\section{Citations}
522
523
An example of the \texttt{\textbackslash cite} command to cite within the presentation:
524
525
This statement requires citation \cite{Smith:2012qr}.
526
527
\clearpage
528
529
530
\thispagestyle{empty} % No slide header and footer
531
532
\begin{tikzpicture}[remember picture,overlay] % Background box
533
\node [xshift=\paperwidth/2,yshift=\paperheight/2] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=\paperheight/3,top color=mygreen,bottom color=mygreen]{}; % Change the height of the box, its colors and position on the page here
534
\end{tikzpicture}
535
% Text within the box
536
\begin{flushright}
537
\vspace{0.6cm}
538
\color{white}\sffamily
539
{\bfseries\LARGE Questions?\par} % Request for questions text
540
\vfill
541
\end{flushright}
542
\end{comment}
543
544
%----------------------------------------------------------------------------------------
545
546
\end{document}
547
%sagemathcloud={"zoom_width":100}
548