Some Sample L TEX Code
Some Sample L TEX Code
Note on
A L TEX
by Jim Peterson
Contents
Note on
A L TEX
by Jim Peterson
List of Figures
Note on
A L TEX
by Jim Peterson
A In this short document, we will setup a sample short article in L TEX which could be used for A a paper or a Masters project. We will show raw L TEX code using a Verbatim command. This
\begin{Verbatim}[frame=single,framerule=0mm,fontsize=\small]
\end{Verbatim}
A A You create a pdf document from your L TEX source as follows. Assume your raw L TEX le is
called MyNotes.tex. The steps to create the pdf le MyNotes.pdf are these:
pdflatex MyNotes pdflatex MyNotes % often to resolve references etc you compile % source 2 - 3 times acroread MyNotes.pdf % note you need the extension here.
A We can use the Verbatim command to show you how the raw L TEX is used to create a document. A This le starts with many commands that set up how the le is to processed by L TEX. These lines
are shown below. Following each line is a percent symbol. This symbol indicates that the rest of the line is a comment. Ill try to explain briey what each line does after the percent symbol.
\documentclass[11pt]{article} \usepackage{amsmath} \usepackage{fancyheadings} \usepackage{setspace} \usepackage{fancyvrb} \usepackage{color} \usepackage[hyper]{listings} \usepackage{graphicx} \usepackage{geometry} \usepackage{wrapfig} \usepackage{subfigure}
% % % % % % % % % % % % %
sets up document using 12 pt font as an article using ams fonts uses a package to let us put comments in the headers at the top of each page lets us toggle single and double spacing when we wish lets us set up our own \verb type commands sets up some colors generates hyper links [hyper] to formatted source code {listings} lets us use graphics files package to help us set up the margins of the document lets us wrap text around a figure lets us do a figure with subfigures within it
Note on
A L TEX
by Jim Peterson
\newcommand{\goodgap}{ % special command to set up spacing between subfigures \hspace{\subfigtopskip} \hspace{\subfigbottomskip}} \usepackage{algorithm} % lets us format algorithms nicely \usepackage{algorithmic} % part of algorithms \usepackage[pdftex]{hyperref} % generate hyperlinks in the pdf file \pagestyle{fancy} % fancy headings -- comments at top or bottom of each page %\pagestyle{plain} % a simple heading style \geometry{lmargin=1.0in,rmargin=1.0in,top=0.75in,bottom=0.75in} % package that sets up our margins \rhead{by Jim Peterson} % puts a string at the right side of the top of each page \lhead{{\bfseries Note on}} % puts a string at the left side of the top of each page \chead{\LaTeX} % puts a string in the center of the top of each page \lfoot{} % puts a string at the left side of the bottom of each page \rfoot{} % puts a string at the right side of the bottom of each page \cfoot{\thepage} % puts a string in the center of the bottom of each page % here the page number \addtolength{\headwidth}{0.55in} % makes sure the line printed at top and % bottom of each page is same size as text. \setlength{\headrulewidth}{0.4pt} \setlength{\footrulewidth}{0.4pt} \setcounter{secnumdepth}{3} \setcounter{tocdepth}{3} % %these commands set up pdf hyperlink styles \hypersetup{letterpaper=true,% breaklinks=true,% colorlinks=true,% anchorcolor=blue,% pdfstartpage=1,% bookmarks=true,% bookmarksnumbered=true,% hyperindex=true,% pdfhighlight=/P} \title{Some Sample ~\LaTeX~ Code} % this is our title \author{Jim Peterson\\ % author email: {\tt [email protected]} } \date{\today} % date \include{setup} % includes a file of LaTeX macros \begin{document} % now we start document
A in the preamble of the document. This is the L TEX code that is typed prior to the line that begins
with \begin{document}.
Note on
A L TEX
by Jim Peterson
If we want to add table of contents for sections, gures and so forth, we use the code below placed right after the \maketitle command.
\newpage \tableofcontents % starts a new page % sets up table of contents
\addcontentsline{toc}{part}{Table Of Contents} % adds the TOC to the pdf hyperrefs \newpage \listoffigures % sets up a list of figures
\lstlistoflistings
Next, we can layout a simple document using the article style. If you want to center and underline the section title, do this:
%\begin{center} %\section{\underline{INTRODUCTION}} %\end{center}
If you dont want to center the titles of the sections, just do this:
%No centering \section{\underline{INTRODUCTION}} \label{intro}
INTRODUCTION
Here you introduce the problem. What you are doing for this project.
Note on
A L TEX
by Jim Peterson
BACKGROUND
Here you talk about your problem, introduce whatever science and math are necessary to understand what is going on. Sort of like a tutorial or a lecture to bright, yet untrained in this area, colleagues. This can be split over several sections if required.
What your task was and how you accomplished it. This can include theoretical development, algorithm development and software issues. This can be spread over several sections if necessary.
YOUR RESULTS
Discuss your accomplishments. Here is how you do a subsection: note we can move heading around using the \hspace command. \noindent \subsection{\hspace{.3in} Your Title Goes Here} \label{basic}
4.1
CONCLUSIONS
Your conclusions.
REFERENCES
1. D. Nguyen and Widrow, B., 1990, Neural Networks for Self-Learning Control Systems, IEEE Control Sys. Mag., Vol. 10, No. 3, pp. 18 23. 2. J. Peterson, 1992, On-line Estimation of Optimal Control Sequences: Pontryagin Estimators, in Intelligent Engineering Systems Through Articial Neural Networks, Pro-
Note on
A L TEX
by Jim Peterson
ceedings of the Articial Neural Networks in Engineering (ANNIE 92) Conference November, 1992, ed. C. Dagli, L. Burke and Y. Shin, ASME Press, pp. 579 584. 3. J. Peterson, 1993a, On-line Estimation of the Optimal Value Function: HJB Estimators, in Advances in Neural Information Processing Systems, 5, ed. S. Hanson, J. Cowan and C. Giles, Morgan Kaufmann Publishers, pp. 319 326.
APPENDICES
Note on
A L TEX
by Jim Peterson
8
8.1
A SAMPLE L TEX
Referencing A Paper:
According to ( Peterson ~\ref{peterson92a}), Dewey and Dagmar are doing a great job on their projects!
According to ( Peterson ??), Dewey and Dagmar are doing a great job on their projects!
8.2
\noindent where
\begin{eqnarray} \hat{J}(x,u,t) + \label{con11b} \end{eqnarray} &=& dist(y(t_f),\Gamma) \int_t^{t_f} \: {\cal L}( y(s),u(s),s) \: ds
Note on
A L TEX
by Jim Peterson
\begin{eqnarray} \label{con12} y^{\prime}(s) &=& f(y(s),u(s),s), \: \: \label{con13} y(t) \label{con14} y(s) &\in& {\cal Y}(s) \subseteq R^N, \: \: t \leq \: s \: \leq t_f\\ &=& x\\ t \leq \: s \: \leq t_f \\
\label{con15} u(s) &\in & U(s) \subseteq R^M, \: \: t \leq \: s \: \leq t_f
\end{eqnarray}
min uU
J(x, u, t) (1)
where
J(x, u, t) = dist(y(tf ), ) +
t
tf
L(y(s), u(s), s) ds
(2)
Subject to:
8.3
10
Note on
A L TEX
by Jim Peterson
Here $y$ and $u$ are the {\em state vector} and {\em control vector} of the system, respectively; $\cal U$ is the space of functions that the control must be chosen from during the minimization process and (~\ref{con13}) -(~\ref{con15}) give the initialization and constraint conditions that the state and control must satisfy. The set $\Gamma$ represents a target constraint set and $dist(y(t_f),\Gamma)$ indicates the distance from the final state $y(t_f)$ to the constraint set $\Gamma$.
Here y and u are the state vector and control vector of the system, respectively; U is the space of functions that the control must be chosen from during the minimization process and ( ??) ( ??) give the initialization and constraint conditions that the state and control must satisfy. The set represents a target constraint set and dist(y(tf ), ) indicates the distance from the nal state y(tf ) to the constraint set .
8.4
Setting Up a Table:
A Here is a L TEX code for a table and how it is referenced in the text:
\noindent A schematic of the learning algorithm for the network is given in Table ~\ref{criticlearn}; note that this training method is essentially a Gauss-Seidel procedure.
\begin{table}[hhh] \caption{Learning Algorithm} \begin{center} \begin{tabular}{cl} \\ 1 & $W_0 = 0$\\ 2 & $j=0$\\ 3 & $i=1$\\ 4 & 5 & Increment $j$\\ Set $W_j = W{j-1}$ \\
11
Note on
A L TEX
by Jim Peterson
6 & Input $y_i$, $\theta_i$ \\ 7 & Using the previous weights, $W_{j-1}$\\ & Calculate the desired target\\ & $D_i = \zeta {\phi}(W_{j-1},y_{i+1},\theta_{i+1}) +{\cal T}_{i}$\\ 8 & & Update the CMAC weights using gradient descent\\ to set ${\phi}(W_{j},y_i,\theta_i) = D_i$\\
9 & Increment $i$\\ 10 & If $i< \eta$ Go To (6)\\ & Else Continue\\
A schematic of the learning algorithm for the network is given in Table ??; note that this training method is essentially a Gauss-Seidel procedure.
8.5
The CMAC architectures are used to construct predictions for each state variable using the temporal difference approach already outlined. We used the following $6$ temporal differences:
12
Note on
A L TEX
by Jim Peterson
1 2 3 4 5 6 7
8 9 10 11 12
W0 = 0 j=0 i=1 Increment j Set Wj = W j 1 Input yi , i Using the previous weights, Wj1 Calculate the desired target Di = (Wj1 , yi+1 , i+1 ) + Ti Update the CMAC weights using gradient descent to set (Wj , yi , i ) = Di Increment i If i < Go To (6) Else Continue If Wj = Wj1 Go To (3) Else Continue Convergence
A L TEX output:
The CMAC architectures are used to construct predictions for each state variable using the temporal dierence approach already outlined in earlier sections. We used the following 6 temporal dierences: 1. sin(c (ti )) sin(c (ti1 )) 2. cos(c (ti )) cos(c (ti1 )) 3. sin(t (ti )) sin(t (ti1 )) 4. sin(t (ti )) sin(t (ti1 )) 5. xc (ti ) xc (ti1 )/XSCALE 6. yc (ti ) yc (ti1 )/Y SCALE
13
Note on
A L TEX
by Jim Peterson
8.6
A Here is L TEX code for another table with how to reference it. This table is a primitive attempt
to format an algorithm. The algorithm package does this better, but it is a bit hard to understand how to set it up, so for today, we will do it the simple way.
We will attempt to discuss generic software design issues, but we will use the truck backer-upper control problem as our framework so we can refer to concrete details when we need to do so. First, we look at a basic sketch of program flow as presented in
Table ~\ref{neurocontrolflow}.
\begin{table}[hhh] \caption{Neurocontrol Flow} \begin{center} \begin{tabular}{ll} \\ 1 & Set simulation parameters 2 & Set up CMAC architectures \\ \\
3 & Choose random truck start and control as state \\ 4 & i = 0 \\ 5 & Save state as sample i \\ 6 & Wait DATA\_FREQ time steps and store state\\ 7 & & & & & & & \hspace{.2in}If state lies in a new CMAC sensor, \\ \hspace{.4in} increment i\\
\hspace{.4in} save state as sample i of training set\\ \hspace{.4in} Compute next predicted optimal\\
\hspace{.6in} control using CMAC model\\ \hspace{.4in} If i $<$ num\_samples GoTo 6 \\ \hspace{.2in}Else, If i $<$ num\_samples GoTo 6 \\ \\
& Now have eta = num\_samples training samples 8 & For each output component d & & & \\
\hspace{.2in}For each input i, compute desired \\ \hspace{.4in} D = FUTURE\_WEIGHT*CMAC OUTPUT for input i \\ \hspace{.4in} + T for input i\\
9& Train CMAC to match I/O set \\ 10& Compute next predicted optimal control \\
14
Note on
A L TEX
by Jim Peterson
\\
11& Save sample eta as state and GoTo 4 \end{tabular} \end{center} \label{neurocontrolflow} \end{table}
A L TEX output:
We will attempt to discuss generic software design issues, but we will use the truck backer-upper control problem as our framework so we can refer to concrete details when we need to do so. First, we look at a basic sketch of program ow as presented in Table ??. Table 2: Neurocontrol Flow 1 2 3 4 5 6 7 Set simulation parameters Set up CMAC architectures Choose random truck start and control as state i=0 Save state as sample i Wait DATA FREQ time steps and store state If state lies in a new CMAC sensor, increment i save state as sample i of training set Compute next predicted optimal control using CMAC model If i < num samples GoTo 6 Else, If i < num samples GoTo 6 Now have eta = num samples training samples For each output component d For each input i, compute desired D = FUTURE WEIGHT*CMAC OUTPUT for input i + T for input i Train CMAC to match I/O set Compute next predicted optimal control using CMAC model Save sample eta as state and GoTo 4
9 10 11
8.7
A Here is simple L TEX code I have used to insert source code into a paper. It uses macros from the
Note on
A L TEX
by Jim Peterson
\mylistset{C++}{Setting Up A Parametric Study}% {$\;$ Setting Up A Parametric Study}% {run\_plot.c}{chh2runplot-d}% \begin{lstlisting} This macro takes five arguments: 1: C++ -- sets the source language 2: Comment which appears on top of source listing 3: $\;$ Comment which appears in Table of listings 4: Name of source file to appear on top of source listing 5: a label we can use to refer to the source code
code here
\end{lstlisting}
float **receptive_field_width;
16
Note on
A L TEX
by Jim Peterson
//store size of all widths fhash hash; }; struct working_memory{ float **mem; }; \end{lstlisting} //working memory levels by hash_size //hash function
10
// t h e number o f l e v e l s // hash v a l u e // o f f s e t = 1/ l e v e l s // s e n s o r w i d t h // s t o r e s i z e o f a l l o f f s e t s
15
20
f l o a t mem ; };
// w o r k i n g memory l e v e l s by h a s h s i z e
17
Note on
A L TEX
by Jim Peterson
8.8
Heres how you embed a png le into the document. We use the macro \myincludegraphics for
A this. The L TEX source is
\begin{figure} \begin{center} %5.55in x 4.17in % \myincludegraphics{voltage0-99.png} {4.5in}{4.5in} \caption{Parametric Study of Action Potentials: $\overline{g}_{Na}$ ranges from $60$ to $180$ in $10$ and $\overline{g}_{K}$ ranges from $18$ to $54$ in $10$ uniform steps each. This gives a total of $100$ different Action Potentials. % name of your image file % width and height of image % caption you want to use
All of the currents were the response of the cell model to the synaptic pulse described in the text.} \label{chh2-AP} \end{center} \end{figure} % label for image
A L TEX output:
18
Note on
A L TEX
by Jim Peterson
Figure 1: Parametric Study of Action Potentials: g N a ranges from 60 to 180 in 10 and g K ranges from 18 to 54 in 10 uniform steps each. This gives a total of 100 dierent Action Potentials. All of the currents were the response of the cell model to the synaptic pulse described in the text.
19