Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stan-dev/stan into bugfi…
Browse files Browse the repository at this point in the history
…x/issue-530-no-model-parameters
  • Loading branch information
ksvanhorn committed Feb 17, 2014
2 parents 1d6cb5c + fbdafe9 commit 0040d0c
Show file tree
Hide file tree
Showing 41 changed files with 4,583 additions and 1,820 deletions.
2 changes: 2 additions & 0 deletions make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ $(patsubst %.stan,%.cpp,$(filter src/test/test-models/no-main/%,$(TEST_MODELS)))
##
test/unit/io/mcmc_writer.o: src/test/test-models/no-main/io_example.cpp
test/unit/gm/command_init.o: src/test/test-models/no-main/gm/test_lp.cpp
test/unit/gm/command_write_iteration.o: src/test/test-models/no-main/gm/test_lp.cpp
test/unit/gm/generator.o: src/test/test-models/no-main/gm/test_lp.cpp

test/unit/model/util.o: src/test/test-models/no-main/model/valid.cpp src/test/test-models/no-main/model/domain_fail.cpp
Expand All @@ -216,6 +217,7 @@ test/CmdStan/command.o: \
$(addsuffix $(EXE), printer domain_fail value_fail proper))
test/CmdStan/gm/argument_configuration.o: src/test/test-models/compiled/CmdStan/test_model$(EXE)
test/CmdStan/fixed_param_sampler.o: src/test/test-models/compiled/CmdStan/empty$(EXE) src/test/test-models/compiled/CmdStan/proper$(EXE)
test/CmdStan/optimization_output.o: src/test/test-models/compiled/CmdStan/optimization_output$(EXE)

##
# CmdStan specific targets. Should be removed in the future.
Expand Down
110 changes: 86 additions & 24 deletions src/docs/bibtex/all.bib
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,14 @@ @incollection{Gay:2005
}


@book{GelmanCarlinSternRubin:2003,
@book{GelmanEtAl:2013,
Address = {London},
Author = {Andrew Gelman and J.~B.~Carlin and Hal S.~Stern and Donald B.~Rubin},
Edition = {2nd},
Publisher = {CRC Press},
Author = {Andrew Gelman and J.~B.~Carlin and Hal S.~Stern and
David B.~Dunson and Aki Vehtari and Donald B.~Rubin},
Edition = {Third},
Publisher = {Chapman \&Hall/CRC Press},
Title = {Bayesian Data Analysis},
Year = {2003}}
Year = {2013}}

@book{GelmanHill:2007,
Address = {Cambridge, United Kingdom},
Expand Down Expand Up @@ -351,6 +352,16 @@ @article{Hastings:1970
Pages = {97--109}
}

@article{HoerlKennard:1970,
author = {Arthur E.\ Hoerl and Robert W.\ Kennard},
year = {1970},
title = {Ridge regression: biased estimation for nonorthogonal problems},
journal = {Technometrics},
volume = {12},
number = {1},
pages = {55--67}
}

@article{Hoffman-Gelman:2011,
Author = {Matthew D. Hoffman and Andrew Gelman},
Title = {The No-{U}-Turn Sampler: Adaptively Setting Path
Expand All @@ -363,7 +374,7 @@ @article{Hoffman-Gelman:2011
Year = {2011}
}

@article{Hoffman-Gelman:2013,
@article{Hoffman-Gelman:2014,
Author = {Matthew D. Hoffman and Andrew Gelman},
Title = {The No-{U}-Turn Sampler: Adaptively Setting Path
Lengths in {H}amiltonian {M}onte {C}arlo},
Expand All @@ -387,6 +398,19 @@ @book{HuntThomas:99
publisher = {Addison-Wesley}
}

@inproceedings{JamesStein:1961,
author = {W.\ James and Charles Stein},
year = {1961},
title = {Estimation with quadratic loss},
editor = {Jerzey Neyman},
booktitle = {Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability},
volume = {1},
pages = {361--379},
publisher = {University of California Press}
}



@article{Lambert:1992,
author = {Diane Lambert},
year = {1992},
Expand Down Expand Up @@ -462,6 +486,17 @@ @article{Neal:1994
Pages = {194--203}
}

@article{Neal:1996b,
author = {Radford M. Neal},
year = {1996},
title = {Sampling from multimodal distributions using tempered
transitions},
journal = {Statistics and Computing},
volume = {6},
number = {4},
pages = {353--366}
}

@techreport{Neal:1997,
author = {Neal, Radford M.},
year = {1997},
Expand Down Expand Up @@ -617,6 +652,25 @@ @article{SmithSpiegelhalterThomas:1995
pages = {2685--2699}
}

@article{SwendsenWang:1986,
author = {Robert H. Swendsen and Jian-Sheng Wang},
year = {1986},
title = {Replica Monte Carlo simulation of spin glasses},
journal = {Physical Review Letters},
volume = {57},
pages = {2607--2609}
}

@article{Tibshirani:1996,
author = {Robert Tibshirani},
year = {1996},
title = {Regression shrinkage and selection via the lasso},
journal = {Journal of the Royal Statistical Society, Series B},
volume = {58},
number = {1},
pages = {267--288}
}

@techreport{TokudaGoodrichVanMechelen:2010,
Author = {Tomoki Tokuda and Ben Goodrich and Iven Van~Mechelen and Andrew Gelman and Francis Tuerlinckx},
Date-Added = {2011-10-11 09:21:36 -0400},
Expand Down Expand Up @@ -665,6 +719,15 @@ @inproceedings{Zhang:2011
year={2011}
}

@article{ZouHastie:2005,
author = {Hui Zou and Trevor Hastie},
year = {2005},
title = {Regularization and variable selection via the elastic net},
journal = {Journal of the Royal Statistical Society, Series B},
volume = {67},
number = {2},
pages = {301--320}
}

%%%% ==================== OLDER BIB ITEMS ======================
Expand Down Expand Up @@ -1999,21 +2062,6 @@ @book{Dye:1966
Title = {Politics, Economics, and the Public: Political Outcomes in the American States},
Year = {1966}}

@article{EfronMorris:1975,
Author = {Efron, B. and Morris, C.},
Journal = {Journal of the American Statistical Association},
Pages = {311--319},
Title = {Data analysis using Stein's estimator and its generalizations},
Volume = {70},
Year = {1975}}

@book{EfronTibshirani:1993,
Address = {London},
Author = {Efron, B. and Tibshirani, R. J.},
Publisher = {Chapman and Hall},
Title = {An Introduction to the Bootstrap},
Year = {1993}}

@book{Ehrenberg:1978,
Address = {New York},
Author = {Ehrenberg, A. S. C.},
Expand Down Expand Up @@ -3220,11 +3268,24 @@ @book{HastieTibshirani:1990
Year = {1990}}

@book{HastieTibshiraniFriedman:2002,
Address = {New York},
Author = {Hastie, T. J. and Tibshirani, R. J. and Friedman, J.},
Year = {2002},
Title = {The Elements of Statistical Learning: Data Mining,
Inference, and Prediction},
Edition = {First},
Publisher = {Springer-Verlag},
Title = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
Year = {2002}}
Address = {New York}
}

@book{HastieTibshiraniFriedman:2009,
Author = {Trevor Hastie and Robert Tibshirani and Jerome Friedman},
Year = {2009},
Title = {The Elements of Statistical Learning: Data Mining,
Inference, and Prediction},
Edition = {Second},
Publisher = {Springer-Verlag},
Address = {New York}
}

@article{HauerNgLovell:1988,
Author = {Hauer, E. and Ng, J. C. N. and Lovell, J.},
Expand Down Expand Up @@ -7336,6 +7397,7 @@ @article{EfronMorris:1975
Volume = {70},
Year = {1975}}


@book{EfronTibshirani:1993,
Address = {London},
Author = {Efron, B. and Tibshirani, R. J.},
Expand Down
2 changes: 1 addition & 1 deletion src/docs/stan-models/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<project name="Stan Model PDF" default="pdf" basedir=".">

<property name="version"
value="2.1.0"/>
value="2.2.0"/>

<path id="classpath">
<pathelement location="stan-models.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion src/docs/stan-models/models.sty
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@

\sloppy % no line overruns

\title{{\Huge\bf Stan Example Models} \\[12pt] Version 2.1.0 \\[48pt]}
\title{{\Huge\bf Stan Example Models} \\[12pt] Version 2.2.0 \\[48pt]}
\author{Stan Development Team \vfill \today}
2 changes: 1 addition & 1 deletion src/docs/stan-models/src/MakeModelTex.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void writeStart(Writer texWriter)
texWriter.write("\\\\[2in]" + EOL);
texWriter.write("{\\Huge\\bf Stan Example Models}" + EOL);
texWriter.write("\\\\[18pt]" + EOL);
texWriter.write("{\\large Version 2.1.0}" + EOL);
texWriter.write("{\\large Version 2.2.0}" + EOL);
texWriter.write("\\\\[12pt]" + EOL);
texWriter.write("{\\large \\today}" + EOL);
texWriter.write("\\\\[1in]" + EOL);
Expand Down
137 changes: 137 additions & 0 deletions src/docs/stan-reference/R/non-identified-plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
library(ggplot2);
library(grid);

N <- 100;
y <- rnorm(N);

loc_sum <- function(lambda1,lambda2) {
sum(dnorm(y,lambda1 + lambda2, 1, log=TRUE));
}

loc_sum_prior <- function(lambda1,lambda2) {
sum(dnorm(y,lambda1 + lambda2, 1, log=TRUE)) +
sum(dnorm(c(lambda1,lambda2),0,1,log=TRUE));
}

one_param <- function(xs) {
dta <- rnorm(100,0,1);
result <- rep(NA, length(xs));
i <- 1;
for (x in xs) {
result[i] <- sum(dnorm(dta,xs[i],1,log=TRUE));
i <- i + 1;
}
return(result);
}
p_one_param <-
ggplot(data.frame(mu=c(-20, 20)), aes(mu)) +
labs(title = "Proper Posterior (without Prior)\n") +
stat_function(fun=one_param) +
labs(x=expression(mu), y="log p") +
theme(aspect.ratio=1,
panel.border=element_blank(),
plot.margin=unit(c(0,0,0,0),"cm"),
text=element_text(size=28),
axis.title=element_text(size=32));
png(res=100,height=800,width=900,file="one_param_identified.png");
print(p_one_param);
dev.off();





K <- 500;
ub <- 25;
lambda_1 <- seq(-ub,ub,len=K);
lambda_2 <- seq(-ub,ub,len=K);

v_lambda_1 <- rep(NA,K^2);
v_lambda_2 <- rep(NA,K^2);
v_density <- rep(NA,K^2);

# use prior (loc_sum_prior)
pos <- 1;
for (m in 1:K) {
for (n in 1:K) {
v_lambda_1[pos] <- lambda_1[m];
v_lambda_2[pos] <- lambda_2[n];
v_density[pos] <- loc_sum_prior(lambda_1[m], lambda_2[n]);
pos <- pos + 1;
}
}
df_vals <- list(lambda_1=v_lambda_1,lambda_2=v_lambda_2,log_density=v_density);
df_prior <- as.data.frame(df_vals);

# plot and save as png

p_prior <-
ggplot(df_prior,aes(x=lambda_1,y=lambda_2,fill=log_density)) +
labs(title = "Proper Posterior (with Prior)\n") +
geom_tile() +
labs(x=expression(lambda[1]), y=expression(lambda[2])) +
scale_fill_gradient2("log p",
limits=c(-600,-120),
midpoint=-400, low="gray95", high="darkblue",
mid="lightyellow", na.value="transparent",
breaks=c(-200, -400, -600),
labels=c("-200", "-400", "-600")) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
theme(aspect.ratio=1,
panel.border=element_blank(),
plot.margin=unit(c(0,0,0,0),"cm"),
text=element_text(size=28),
axis.title=element_text(size=32),
legend.title=element_text(size=30,face="plain",color="gray25"),
legend.text=element_text(size=20,color="gray40"),
legend.margin=unit(0.3,"cm") )

png(res=100,height=800,width=900,file="non-identified-plus-prior.png");
plot(p_prior)
dev.off();
plot(p_prior)

# no prior (loc_sum)
pos <- 1;
for (m in 1:K) {
for (n in 1:K) {
v_density[pos] <- loc_sum(lambda_1[m], lambda_2[n]);
pos <- pos + 1;
}
}
df_vals <- list(lambda_1=v_lambda_1,lambda_2=v_lambda_2,log_density=v_density);
df_no_prior <- as.data.frame(df_vals);

# plot and save as png

p_no_prior <-
ggplot(df_no_prior,aes(x=lambda_1,y=lambda_2,fill=log_density)) +
labs(title = "Improper Posterior (without Prior)\n") +
geom_tile() +
labs(x=expression(lambda[1]), y=expression(lambda[2])) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
scale_fill_gradient2("log p",
limits=c(-600,-120),
midpoint=-400, low="gray95", high="darkblue",
mid="lightyellow", na.value="transparent",
breaks=c(-200, -400, -600),
labels=c("-200", "-400", "-600") ) +
theme(aspect.ratio=1,
panel.border=element_blank(),
plot.margin=unit(c(0,0,0,0),"cm"),
text=element_text(size=28),
axis.title=element_text(size=32),
legend.title=element_text(size=30,face="plain",color="gray25"),
legend.text=element_text(size=20,color="gray40"),
legend.margin=unit(0.3,"cm") )


theme(aspect.ratio=1,text=element_text(size=28),
axis.title=element_text(size=32),
legend.margin=unit(0.3,"cm"));

png(res=100,height=800,width=900,file="non-identified.png")
print(p_no_prior)
dev.off();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/docs/stan-reference/R/non-identified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0040d0c

Please sign in to comment.