From 6c088673b9f7d4b0e3b186b850d4fd6ba9997326 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 29 Sep 2015 22:08:57 +0000 Subject: lstbayes (29sep15) git-svn-id: svn://tug.org/texlive/trunk@38498 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/lstbayes/Makefile | 42 +++++++ Master/texmf-dist/doc/latex/lstbayes/README.md | 54 +++++++++ Master/texmf-dist/doc/latex/lstbayes/examples.pdf | Bin 0 -> 141285 bytes Master/texmf-dist/doc/latex/lstbayes/examples.tex | 129 ++++++++++++++++++++++ Master/texmf-dist/doc/latex/lstbayes/lstbayes.pdf | Bin 0 -> 132474 bytes 5 files changed, 225 insertions(+) create mode 100644 Master/texmf-dist/doc/latex/lstbayes/Makefile create mode 100644 Master/texmf-dist/doc/latex/lstbayes/README.md create mode 100644 Master/texmf-dist/doc/latex/lstbayes/examples.pdf create mode 100644 Master/texmf-dist/doc/latex/lstbayes/examples.tex create mode 100644 Master/texmf-dist/doc/latex/lstbayes/lstbayes.pdf (limited to 'Master/texmf-dist/doc') diff --git a/Master/texmf-dist/doc/latex/lstbayes/Makefile b/Master/texmf-dist/doc/latex/lstbayes/Makefile new file mode 100644 index 00000000000..fd92ddab4e4 --- /dev/null +++ b/Master/texmf-dist/doc/latex/lstbayes/Makefile @@ -0,0 +1,42 @@ +# +# This file generates files required to use the lstbayes package +# + +# formatting tools +PYTHON = python3 +SHELL = bash +LATEX = pdflatex +TEX = tex + +.PHONY: build pdf all + +all: build pdf + +build: lstbayes.sty + +release: build pdf README.md + -rm lstbayes.zip + if [ -d lstbayes ]; then rm -rf ./lstbayes; fi + mkdir lstbayes + cp *.pdf *.ins *.dtx *.tex README.md Makefile lstbayes + zip -r lstbayes.zip lstbayes + +pdf: lstbayes.pdf examples.pdf + +lstbayes.dtx: lstbayes.dtx.mustache + $(PYTHON) lstbayes.py $< > $@ + +lstbayes.sty: lstbayes.ins lstbayes.dtx + $(TEX) $< + +lstbayes.pdf: lstbayes.dtx + $(LATEX) $< + makeindex -s gind.ist -o ${@:.pdf=.ind} ${@:.pdf=.idx} + makeindex -s gglo.ist -o ${@:.pdf=.gls} ${@:.pdf=.glo} + $(LATEX) $< + $(LATEX) $< + +examples.pdf: examples.tex + $(LATEX) $< + $(LATEX) $< + diff --git a/Master/texmf-dist/doc/latex/lstbayes/README.md b/Master/texmf-dist/doc/latex/lstbayes/README.md new file mode 100644 index 00000000000..9f076be4c5c --- /dev/null +++ b/Master/texmf-dist/doc/latex/lstbayes/README.md @@ -0,0 +1,54 @@ +# Listings language drivers for BUGS, JAGS, and Stan + +[![CTAN](https://img.shields.io/ctan/v/lstbayes.svg)](https://www.ctan.org/pkg/lstbayes) +[![CTAN license](https://img.shields.io/ctan/l/lstbayes.svg)](https://www.ctan.org/pkg/lstbayes) + +Adds support for the following languages to the LaTeX +[listings](http://www.ctan.org/tex-archive/macros/latex/contrib/listings/) +package, which pretty-prints source code: + +- [BUGS](http://www.openbugs.net) +- [JAGS](http://mcmc-jags.sourceforge.net/) +- [Stan](http://mc-stan.org/) + +# Usage + +To use, load the package +```latex +\usepackage{lstbayes} +``` +Then use `BUGS`, `JAGS` or `Stan` as a language in one of the listings environments or commands. For example, to format the Stan [Eight schools](https://raw.githubusercontent.com/wiki/stan-dev/rstan/8schools.stan) model, +```latex +\begin{lstlisting}[language=Stan] +data { + int J; // number of schools + real y[J]; // estimated treatment effects + real sigma[J]; // s.e. of effect estimates +} +parameters { + real mu; + real tau; + real eta[J]; +} +transformed parameters { + real theta[J]; + for (j in 1:J) + theta[j] <- mu + tau * eta[j]; +} +model { + eta ~ normal(0, 1); + y ~ normal(theta, sigma); +} +\end{lstlisting} +``` + +Also see the examples in `examples.tex` and `examples.pdf` files included in this repository. +See the `listings` [documentation](https://www.ctan.org/tex-archive/macros/latex/contrib/listings/?la) for more on how to use the `listings` package. + +# Issues + +Development occurs on github at . + + + diff --git a/Master/texmf-dist/doc/latex/lstbayes/examples.pdf b/Master/texmf-dist/doc/latex/lstbayes/examples.pdf new file mode 100644 index 00000000000..2d18ac1f480 Binary files /dev/null and b/Master/texmf-dist/doc/latex/lstbayes/examples.pdf differ diff --git a/Master/texmf-dist/doc/latex/lstbayes/examples.tex b/Master/texmf-dist/doc/latex/lstbayes/examples.tex new file mode 100644 index 00000000000..48a1c91be51 --- /dev/null +++ b/Master/texmf-dist/doc/latex/lstbayes/examples.tex @@ -0,0 +1,129 @@ +\documentclass{article} + +\title{Examples for the \textsf{lstbayes} package} +\author{Jeffrey B. Arnold} + +\usepackage{lstbayes} +\usepackage{hyperref} + +\begin{document} + +\maketitle{} + +Some example programs typset using the \textsf{listings} language drivers provideb by the \textsf{lstbayes} package. + +\section{BUGS} + +The Rats model from the OpenBUGS Examples Volume I: \url{http://www.openbugs.net/Examples/Rats.html}. +\begin{lstlisting}[language=BUGS] +model { + for( i in 1 : N ) { + for( j in 1 : T ) { + Y[i , j] ~ dnorm(mu[i , j],tau.c) + mu[i , j] <- alpha[i] + beta[i] * (x[j] - xbar) + culmative.Y[i , j] <- culmative(Y[i , j], Y[i , j]) + post.pv.Y[i , j] <- post.p.value(Y[i , j]) + prior.pv.Y[i , j] <- prior.p.value(Y[i , j]) + replicate.post.Y[i , j] <- replicate.post(Y[i , j]) + pv.post.Y[i , j] <- step(Y[i , j] - replicate.post.Y[i , j]) + replicate.prior.Y[i , j] <- replicate.prior(Y[i , j]) + pv.prior.Y[i , j] <- step(Y[i , j] - replicate.prior.Y[i , j]) + } + alpha[i] ~ dnorm(alpha.c,alpha.tau) + beta[i] ~ dnorm(beta.c,beta.tau) + } + tau.c ~ dgamma(0.001,0.001) + sigma <- 1 / sqrt(tau.c) + alpha.c ~ dnorm(0.0,1.0E-6) + alpha.tau ~ dgamma(0.001,0.001) + beta.c ~ dnorm(0.0,1.0E-6) + beta.tau ~ dgamma(0.001,0.001) + alpha0 <- alpha.c - xbar * beta.c +} +\end{lstlisting} + + +\section{JAGS} + +Linear regression example from John Myles White, \url{http://www.johnmyleswhite.com/notebook/2010/08/20/using-jags-in-r-with-the-rjags-package/}. + +\begin{lstlisting}[language=JAGS] +model { + for (i in 1:N){ + y[i] ~ dnorm(y.hat[i], tau) + y.hat[i] <- a + b * x[i] + } + a ~ dnorm(0, .0001) + b ~ dnorm(0, .0001) + tau <- pow(sigma, -2) + sigma ~ dunif(0, 100) +} +\end{lstlisting} + + +\section{Stan} + +Rats example from \url{https://github.com/stan-dev/example-models/blob/master/bugs_examples/vol1/rats/rats_vec.stan}. + +\begin{lstlisting}[language=Stan] +# http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/Vol1.pdf +# Page 3: Rats +data { + int N; + int T; + real x[T]; + real y[N,T]; + real xbar; +} +transformed data { + real x_minus_xbar[T]; + real y_linear[N*T]; + + for (t in 1:T) + x_minus_xbar[t] <- x[t] - xbar; + + for (n in 1:N) + for (t in 1:T) + y_linear[(n-1)*T + t] <- y[n, t]; +} +parameters { + real alpha[N]; + real beta[N]; + + real mu_alpha; + real mu_beta; + + real sigmasq_y; + real sigmasq_alpha; + real sigmasq_beta; +} +transformed parameters { + real sigma_y; + real sigma_alpha; + real sigma_beta; + + sigma_y <- sqrt(sigmasq_y); + sigma_alpha <- sqrt(sigmasq_alpha); + sigma_beta <- sqrt(sigmasq_beta); +} +model { + real pred[N*T]; + + for (n in 1:N) + for (t in 1:T) + pred[(n-1)*T + t] <- fma(beta[n], x_minus_xbar[t], alpha[n]); + + mu_alpha ~ normal(0, 100); + mu_beta ~ normal(0, 100); + sigmasq_y ~ inv_gamma(0.001, 0.001); + sigmasq_alpha ~ inv_gamma(0.001, 0.001); + sigmasq_beta ~ inv_gamma(0.001, 0.001); + alpha ~ normal(mu_alpha, sigma_alpha); // vectorized + beta ~ normal(mu_beta, sigma_beta); // vectorized + + y_linear ~ normal(pred, sigma_y); // vectorized +} +\end{lstlisting} + +\end{document} + diff --git a/Master/texmf-dist/doc/latex/lstbayes/lstbayes.pdf b/Master/texmf-dist/doc/latex/lstbayes/lstbayes.pdf new file mode 100644 index 00000000000..edcdd0195e3 Binary files /dev/null and b/Master/texmf-dist/doc/latex/lstbayes/lstbayes.pdf differ -- cgit v1.2.3