\documentclass[a4paper,10pt,notumble]{leaflet}
\usepackage{graphics}
\usepackage{fancyhdr}
\usepackage{color}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{{\tiny\today}}
\cfoot{} %{\tiny\thepage}}
\rfoot{{\tiny \copyright 2009 ADMB Foundation}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage[bookmarks=false]{hyperref}
\hypersetup{pdfauthor={John Sibert and Anders Nielsen}}
\hypersetup{pdfsubject={ADModel Builder}}
\hypersetup{pdftitle={ADMB Reference Card}}
\hypersetup{pdfkeywords={Automatic differentiation, AUTODIF, ADMB}}

\definecolor{admbgreen}{rgb}{0.0,0.3125,0.0781}

\title{\begin{minipage}[t]{0.98\textwidth}\begin{center}
\includegraphics[width=\textwidth]{./cropped-logo-20080527.jpeg}
{\color{admbgreen}Handy-dandy Reference Card}\\
    \end{center}\end{minipage}}

\author{John Sibert \and Anders Nielsen}

\CutLine*{1}
\CutLine*{2}
\CutLine*{3}
\CutLine*{4}
\CutLine*{5}
\CutLine*{6}

\setmargins{3ex}{5ex}{1.5em}{1.5em}

\begin{document}
\maketitle
\thispagestyle{empty}
\scriptsize
\small
\parindent=0pt

\section{ADMB Syntax Notes}
\begin{itemize}
\item \verb+_SECTIONS+ must begin in the first position of a line.
\item Other ADMB statements and variable declarations
 must begin in the third position  of the line or beyond.
\item \verb+LOCAL_CALCS+ and \verb+END_CALCS+ 
must begin in the second position.
\item Semicolons are not
required after statements in either the \verb+DATA_SECTION+ or the
\verb+PARAMETER_SECTION+, but should be used elsewhere. Since
semicolons are required by C++, it is harmless to use them
everywhere.
\item \verb+!!+ preceding a statement indicates a line of C++ code
that will be passed unchanged to the C++ compiler; a semicolon must
end the line.
\item Template file errors are indicated by the line number in the template
file and the first letter of the offending text.
\item Beware of editors intended for word processing (e.g. WordPad)
that may insert extra invisible formatting characters in files.
\item Some Windows versions of ADMB may require a
blank line after the last line of the program. 
\item Adopt a consistent programming style. Here are a couple of
reasonable sets of guidlines:\\
\url{http://corelinux.sourceforge.net/cppstnd/cppstnd.php}
and
\url{http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml}.
\item Avoid directories (folders) and file names that contain
spaces. They will only cause grief and tears. Some operating systems do
not distinguish between upper-case and lower-case letters, so it's
best not to mix.
\end{itemize}

\section{Example Template File (linear regression)}
\begin{verbatim}
DATA_SECTION
  init_int N
  init_vector x(1,N)
  init_vector Y(1,N)

PARAMETER_SECTION
  init_number a
  init_number b
  init_number logSigma
  sdreport_number ss
  objective_function_value nll

PROCEDURE_SECTION
  ss=exp(2.0*logSigma);
  nll=0.5*(N*log(2.0*M_PI*ss)+sum(square(Y-(a+b*x)))/ss);
\end{verbatim}
{\bf Compile:} \verb|makeadm <programname>| creates a executable \\
{\bf Run:} \verb|<programname>| runs the executable

\section{Template File SECTIONs}
Sections are discussed in detail in the ADMB manual.
Every ADMB program must contain these three sections.

\par{\everypar={\hangindent=1em \hangafter=1}
\verb+DATA_SECTION+ Describes data and specifies how they are read 
and possible transformed.

\verb+PARAMETER_SECTION+ Describes model parameters, valid ranges and
sequence of estimation. The variable holding the value of the
objective function is specified here.

\verb+PROCEDURE_SECTION+ Contains the details of the model and the
likelihood computation.
Semi-colons are required at the end of each statement.
}

Other sections have specialized purposes.

\par{\everypar={\hangindent=1em \hangafter=1}
\verb+FUNCTION+ Begins definition of a function or ``method'' in the \verb+PROCEDURE_SECTION+ 
\verb+LOCAL_CALCS+ and \verb+END_CALCS+ bracket C++ code transmitted
without modification to the compiler. 
Semi-colons are required at the end of each statement.

\verb+INITIALIZATION_SECTION+
Used to initialize parameters declared in the \verb+PARAMETER_SECTION+. 

\verb+REPORT_SECTION+
Used to create a customized report. Uses the pre-defined
\verb+ofstream+ variable \verb+report+ for output. For example
\verb+report << "a = " << a << endl;+ would place the value of the
variable \verb+a+ in the file \verb+<programname>.rep+.

\verb+RUNTIME_SECTION+
Used to control the behavior of the function minimizer. Useful to
change stopping criteria during initial phases of an estimation.

\verb+PRELIMINARY_CALCULATIONS_SECTION+ or \verb+PRELIMINARY_CALCS_SECTION+
Intended to do preliminary calculations on the data prior to starting
the model. Largely supplanted by 
\verb+LOCAL_CALCS+ and \verb+END_CALCS+ code fragments.

\verb+BETWEEN_PHASES_SECTION+
Code executed between estimation phases.

\verb+GLOBALS_SECTION+
Used to insert any valid C++ statements prior to the defination of
the \verb+main()+ function. Useful to include header files and to
declare global objects.

\verb+TOP_OF_MAIN_SECTION+
Used to set AUTODIF global variables. Useful to reduce size of
temporary gradient files.

\verb+FINAL_SECTION+

\verb+SLAVE_SECTION+

}

\section{ADMB Variable Types}
ADMB uses two fundamental data types: the standard C++
\verb+double+ for which no derivative information is generated, and the
AUTODIF library \verb+dvariable+ for which derivative information is
generated. See the AUTODIF manual for details. The prefix
\verb+init_+ in the \verb+DATA_SECTION+ tells ADMB to read
the value of the variable from the file \verb+<programname>.dat+. The prefix
\verb+init_+ in the \verb+PARAMETER_SECTION+ tells ADMB to
estimate the value of the parameter using the model. Qualifiers in
brackets \verb+[...]+ are optional. Refer to the ADMB manual for a
complete descriptions.
{\scriptsize
\begin{center}
{\tt
\begin{tabular}{@{}lll@{}}
\hline
Declaration in tpl & \verb+DATA_SECTION+ & \verb+PARAMETER_SECTION+\\
\hline
\verb+[init_]int+ & int & int\\
\verb+[init_][bounded_]number+  & double & dvariable\\
\verb+[init_][bounded_][dev_]vector+ & dvector & \verb+dvar_vector+\\
\verb+[init_][bounded_]matrix+ & dmatrix & \verb+dvar_matrix+\\
\verb+[init_]3darray+ & 3D double array & 3D dvariable array\\
4darray & 4D double array & 4D dvariable array\\
5darray & 5D double array & 5D dvariable array\\
6darray & 6D double array & 6D dvariable array\\
7darray & 7D double array & 7D dvariable array\\
\verb+sdreport_number+ & na & dvariable\\
\verb+likeprof_number+ & na & dvariable\\
\verb+sdreport_vector+ & na & \verb+dvar_vector+\\
\verb+sdreport_matrix+ & na & \verb+dvar_matrix+\\
\hline
\end{tabular}
}
\end{center}
}

\section {ADMB Utilities}
\verb+ADMB_HOME+ environment variable is the folder in which ADMB was
installed. Used by other utilities, compilers and make files to
access ADMB

\verb+makeadm+ and \verb+makeadms+ build executable files from 
\verb+.tpl+ files. The terminal letter `s' invokes the ``safe''
library for subscript checking.

\verb+tpl2cpp+ and \verb+tpl2rem+ translate \verb+.tpl+ to C++ code.

\verb+mygcco+ \verb+mygccs+ \verb+mygccopt+ \verb+mygcco-re+ comple
ADMB c++ code into object files.

\verb+linkadm+ and \verb+linkadms+ link ADMB object files into
executables.

\verb+admb+ Makes ADMB applications. Takes -s -r and -d command line
options. Type \verb+admb --help+ for more information.

\verb+adcomp+ and \verb+adlink+ Used by \verb+admb+ for compiling and
linking.

\verb+check-expected-results+ I have no idea what this does.

{\bf The following should probably not be mentioned:}
\verb+seddf1b2+
\verb+seddf1b3+
\verb+seddf1b4+
\verb+sed.exe+
\verb+sedf1b2a+
\verb+sedf1b2c+
\verb+sedf1b2d+
\verb+sedflex+

\section {ADMB Files}

\verb+<programname>.tpl+ ADMB template file specifying a complete
model.

\verb+<programname>.dat+ The default file for reading in data to an
ADMB application.

\verb+<programname>.htp+ and \verb+<programname>.cpp+ C++ header and
source code files produced by \verb+tpl2cpp+.

\verb+<programname>.par+ Estimated values of parameters.

\verb+<programname>.std+ Estimated values of parameters and the
standard deviations of the parameter estimates computed by the the inverse
Hessian method.

\verb+<programname>.cor+ Correlation matrix of the estimated
parameters.

\verb+<programname>.pin+ File containing the initial values of the
paramters to be used to start the numerical estimation. Format is the
same as \verb+<programname>.par+ 

\section{Run-time Interventions}
Pressing Control-C (press the control key and~then~C) after the
minimizer has started will interrupt the program and cause it to
display the prompt, 
``\verb|press q to quit or c to invoke derivative checker:|''.
Pressing `q' and then ``Return'' (or ``Enter''), will cause the
program to leave the minimizer and enter the report phase. Pressing
`c' and then ``Return'' will invoke the derivative checker and
additional prompts will be displayed.

%\end{document}

\section{Almost complete list of ADMB types}
{\scriptsize
\begin{center}
%\begin{tabular}{|@{}l|l|l|l@{}|}
\begin{tabular}{@{}llll@{}}
\verb+3darray+&
\verb+4darray+\\
\verb+5darray+&
\verb+6darray+\\
\verb+7darray+&
\verb+SPinit_3darray+\\
\verb+SPinit_4darray+&
\verb+SPinit_bounded_3darray+\\
\verb+SPinit_4darray+&
\verb+SPinit_bounded_3darray+\\
\verb+SPinit_bounded_matrix+&
\verb+SPinit_bounded_number+\\
\verb+SPinit_bounded_vector+&
\verb+SPinit_imatrix+\\
\verb+SPinit_int+&
\verb+SPinit_ivector+\\
\verb+SPinit_matrix+&
\verb+SPinit_number+\\
\verb+SPinit_vector+&
\verb+SPint+\\
\verb+SPivector+&
\verb+SPmatrix+\\
\verb+SPnumber+&
\verb+SPvector+\\
\verb+constant_quadratic_penalty+&
\verb+dll_3darray+\\
\verb+dll_adstring+&
\verb+dll_imatrix+\\
\verb+dll_init_3darray+&
\verb+dll_init_bounded_number+\\
\verb+dll_init_bounded_vector+&
\verb+dll_init_imatrix+\\
\verb+dll_init_int+&
\verb+dll_init_matrix+\\
\verb+dll_init_number+&
\verb+dll_init_vector+\\
\verb+dll_int+&
\verb+dll_matrix+\\
\verb+dll_number+&
\verb+dll_random_effects_vector+\\
\verb+dll_vector+&
\verb+equality_constraint_vector+\\
\verb+gaussian_prior+&
\verb+imatrix+\\
\verb+inequality_constraint_vector+&
\verb+init_3darray+\\
\verb+init_4darray+&
\verb+init_5darray+\\
\verb+init_6darray+&
\verb+init_7darray+\\
\verb+init_adstring+&
\verb+init_bounded_3darray+\\
\verb+init_bounded_dev_vector+&
\verb+init_bounded_matrix+\\
\verb+init_bounded_matrix_vector+&
\verb+init_bounded_number+\\
\verb+init_bounded_number_vector+&
\verb+init_bounded_vector+\\
\verb+init_bounded_vector_vector+&
\verb+init_imatrix+\\
\verb+init_int+&
\verb+init_ivector+\\
\verb+init_line_adstring+&
\verb+init_matrix+\\
\verb+init_matrix_vector+&
\verb+init_number+\\
\verb+init_number_vector+&
\verb+init_vector+\\
\verb+init_vector_vector+&
\verb+int+\\
\verb+ivector+&
\verb+likeprof_number+\\
\verb+matrix+&
\verb+normal_prior+\\
\verb+number+&
\verb+objective_function_value+\\
\verb+quadratic_penalty+&
\verb+quadratic_prior+\\
\verb+random_effects_bounded_matrix+&
\verb+random_effects_bounded_vector+\\
\verb+random_effects_matrix+&
\verb+random_effects_vector+\\
\verb+sdreport_matrix+&
\verb+sdreport_number+\\
\verb+sdreport_vector+&
\verb+splus_3darray+\\
\verb+splus_adstring+&
\verb+splus_imatrix+\\
\verb+splus_init_3darray+&
\verb+splus_init_bounded_number+\\
\verb+splus_init_bounded_vector+&
\verb+splus_init_matrix+\\
\verb+splus_init_number+&
\verb+splus_init_vector+\\
\verb+splus_int+&
\verb+splus_matrix+\\
\verb+splus_number+&
\verb+splus_vector+\\
\verb+vector+&
\\
\end{tabular}
\end{center}
}

\section{Command-line Options}
\par{\tiny\everypar={\hangindent=1em \hangafter=1}
\verb|-ainp NAME|      change default ascii input parameter file name to NAME

\verb|-binp NAME|      change default binary input parameter file name to NAME

\verb|-est|            only do the parameter estimation

\verb|-noest|          do not do the parameter estimation (optimization) 

\verb|-ind NAME|       change default input data file name to NAME

\verb|-lmn N|          use limited memory quasi newton -- keep N steps

\verb|-dd N|           check derivatives after n function evaluations

\verb|-lprof|          perform profile likelihood calculations

\verb|-maxph N|        increase the maximum phase number to N

\verb|-mcdiag|         use diagonal covariance matrix for mcmc with diagonal values 1

\verb|-mcmc [N]|       perform markov chain monte carlo with N simulations

\verb|-mcmult N|       multiplier N for mcmc default

\verb|-mcr|            resume previous mcmc

\verb|-mcrb  N|        reduce the amount of correlation in the covariance matrix 1<=N<=9

\verb|-mcnoscale|      don't rescale step size for mcmc depending on acceptance rate

\verb|-nosdmcmc|       turn off mcmc histogram calcs to make mcsave run faster

\verb|-mcgrope N|      use probing strategy for mcmc with factor N

\verb|-mcseed N|       seed for random number generator for markov chain monte carlo

\verb|-mcscale N|       rescale step size for first N evaluations

\verb|-mcsave N|       save the parameters for every N'th simulation

\verb|-mceval|         Go throught the saved mcmc values from a previous mcsave

\verb|-crit N1,N2,...| set gradient magnitude convergence criterion to N

\verb|-iprint N|       print out function minimizer report every N iterations

\verb|-maxfn N1,N2,...| set maximum number opf function eval's to N

\verb|-rs|             if function minmimizer can't make progress rescale and try again

\verb|-nox|            don't show vector and gradient values in function minimizer screen report

\verb|-phase N|        start minimization in phase N

\verb|-simplex|        use simplex algorithm for minimization (new test version)

\verb|-nohess|         don't do hessian or delta method for std dev

\verb|-eigvec|         calculate eigenvectors of the Hessian

\verb|-sdonly|         do delta method for std dev estimates without redoing hessian

\verb|-ams N|          set arrmblsize to N (\verb|ARRAY_MEMBLOCK_SIZE|)

\verb|-cbs N|          set \verb|CMPDIF_BUFFER_SIZE| to N (\verb|ARRAY_MEMBLOCK_SIZE|)

\verb|-mno N|          set the maximum number of independent variables to N

\verb|-mdl N|          set the maximum number of dvariables to N

\verb|-master|         run as PVM master program

\verb|-gbs N|          set \verb|GRADSTACK_BUFFER_SIZE| to N (\verb|ARRAY_MEMBLOCK_SIZE|)

\verb|-master|         run as PVM master program

\verb|-slave|          run as PVM slave program

\verb|-pvmtime|        record timing information for PVM performance analysis

\verb|-info|           Contributors acknowledgements

\verb|-nr N|           maximum number of Newton-Raphson steps

\verb|-imaxfn N|       maximum number of fevals in quasi-Newton inner optimization

\verb|-is N|           set importance sampling size to n for random effects

\verb|-isf N|          set importance sampling size funnel blocksto n for random effects

\verb|-isdiag|         print importance sampling diagnostics

\verb|-hybrid|         do hybrid Monte Carlo version of MCMC

\verb|-hbf|            set the hybrid bounded flag for bounded parameters

\verb|-hyeps|          mean step size for hybrid Monte Carlo

\verb|-hynstep|        number of steps for hybrid Monte Carlo

\verb|-noinit|         do not initialize random effects before inner optimzation

\verb|-ndi N|          set maximum number of separable calls

\verb|-ndb N|          set number of blocks for derivatives for random effects (reduces temporary file sizes)

\verb|-ddnr|           use high precision Newton-Raphson for inner optimization for banded hessian case ONLY even if implemented

\verb|-nrdbg|           verbose reporting for debugging newton-raphson

\verb|-mm N|          do minimax optimization

\verb|-shess|         use sparse Hessian structure inner optimzation

\verb|-? -help --help| list of options
}
\end{document}
