File tree Expand file tree Collapse file tree 8 files changed +105
-57
lines changed
bugs_examples/vol3/funshapes Expand file tree Collapse file tree 8 files changed +105
-57
lines changed Original file line number Diff line number Diff line change 1- # http://www.openbugs.info/Examples/Funshapes.html
2-
1+ /*
2+ * BUGS volume 3, fun shapes, circle
3+ * http://www.openbugs.info/Examples/Funshapes.html
4+ */
35parameters {
4- real < lower =- 1 ,upper = 1 > x;
5- real < lower =- 1 ,upper = 1 > y;
6+ real < lower =- 1 ,upper =1 > x;
7+ real < lower = - sqrt( 1 - square( x)),
8+ upper = sqrt( 1 - square( x))> y;
69}
7-
810model {
9- // lp__ <- log(step(1 - x * x - y * y));
10- lp__ <- log(fmax( 0 , 1 - x * x - y * y));
11-
11+ /* uniform within constraints */
1212}
Original file line number Diff line number Diff line change 1+ /*
2+ * Hollow Square
3+ * http://www.openbugs.info/Examples/Funshapes.html
4+ *
5+ * Transform a uniform rectangle
6+ * 1234
7+ * 5678
8+ * 90AB
9+ * to a uniform hollow square
10+ * 1234
11+ * 5 6
12+ * 7 8
13+ * 90AB
14+ */
15+ parameters {
16+ real < lower =0 ,upper =2 > x_raw;
17+ real < lower =0 ,upper =1.5 > y_raw;
18+ }
19+ model {
20+ /* no-op; uniformity implied by parameter constraints */
21+ }
22+ generated quantities {
23+ real x;
24+ real y;
25+ if (y_raw > 1 ) {
26+ // cases 1, 2, 3, 4
27+ x <- x_raw - 1 ;
28+ y <- y_raw - 0.5 ;
29+ } else if (y_raw < 0.5 ) {
30+ // cases 9, 0, A, B
31+ x <- x_raw - 1 ;
32+ y <- y_raw - 1 ;
33+ } else if (x_raw < 0.5 ) {
34+ // case 5
35+ x <- x_raw - 1 ;
36+ y <- y_raw - 0.5 ;
37+ } else if (x_raw < 1.0 ) {
38+ // case 6
39+ x <- x_raw - 1.5 ;
40+ y <- y_raw - 1 ;
41+ } else if (x_raw < 1.5 ) {
42+ // case 7
43+ x <- x_raw - 0.5 ;
44+ y <- y_raw - 0.5 ;
45+ } else {
46+ x <- x_raw - 1.0 ;
47+ y <- y_raw - 1.0 ;
48+ }
49+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ PGM = circle#
33PGM2 = squaremc#
44PGM3 = ring#
55PGM4 = hsquare#
6- PGM5 = parallelagram #
6+ PGM5 = parallelogram #
77
88CXX = g++
99CXX = clang++
@@ -12,31 +12,32 @@ EIGENPATH = $(shell find $(STAN_HOME)/lib -path '*lib/eigen_*' -regex '.*lib\/ei
1212CPPFLAGS = -I $(BOOSTPATH ) -I$(EIGENPATH ) -I $(STAN_HOME ) /src
1313LIBFLAGS = -L$(STAN_HOME ) /bin -lstan
1414
15+ all : $(PGM ) $(PGM2 ) $(PGM3 ) $(PGM4 ) $(PGM5 )
16+
1517$(PGM ) :
1618 $(STAN_HOME ) /bin/stanc --name=$(PGM ) $(PGM ) .stan
1719 $(CXX ) -Wall -O3 -DNDEBUG $(CPPFLAGS ) $(PGM ) .cpp -o $(PGM ) $(LIBFLAGS )
18- ./$(PGM ) # --data=$(PGM).data.R
20+ ./$(PGM )
1921
2022$(PGM2 ) :
2123 $(STAN_HOME ) /bin/stanc --name=$(PGM2 ) $(PGM2 ) .stan
2224 $(CXX ) -Wall -O3 -DNDEBUG $(CPPFLAGS ) $(PGM2 ) .cpp -o $(PGM2 ) $(LIBFLAGS )
23- ./$(PGM2 ) --iter=10000 --warmup=1000 # --data=$(PGM2).data.R
24-
25+ ./$(PGM2 )
2526
2627$(PGM3 ) :
2728 $(STAN_HOME ) /bin/stanc --name=$(PGM3 ) $(PGM3 ) .stan
2829 $(CXX ) -Wall -O3 -DNDEBUG $(CPPFLAGS ) $(PGM3 ) .cpp -o $(PGM3 ) $(LIBFLAGS )
29- ./$(PGM3 ) --iter=10000 --warmup=1000 --thin=1# --data= $( PGM3 ) .data.R
30+ ./$(PGM3 )
3031
3132$(PGM4 ) :
32- $(STAN_HOME ) /bin/stanc --name=$(PGM4 ) $(PGM4 ) .stan.0
33+ $(STAN_HOME ) /bin/stanc --name=$(PGM4 ) $(PGM4 ) .stan
3334 $(CXX ) -Wall -O3 -DNDEBUG $(CPPFLAGS ) $(PGM4 ) .cpp -o $(PGM4 ) $(LIBFLAGS )
34- ./$(PGM4 ) # --data=$(PGM4).data.R
35+ ./$(PGM4 )
3536
3637$(PGM5 ) :
3738 $(STAN_HOME ) /bin/stanc --name=$(PGM5 ) $(PGM5 ) .stan
3839 $(CXX ) -Wall -O3 -DNDEBUG $(CPPFLAGS ) $(PGM5 ) .cpp -o $(PGM5 ) $(LIBFLAGS )
39- ./$(PGM5 ) # --data=$(PGM5).data.R
40+ ./$(PGM5 )
4041
4142
4243clean :
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /*
2+ * BUGS Volume 3, funshapes, parallelogram
3+ * http://www.openbugs.info/Examples/Funshapes.html
4+ */
5+ parameters {
6+ real < lower =0 ,upper =1 > x;
7+ real < lower =0 ,upper =1 > y_raw;
8+ }
9+ transformed parameters {
10+ real < lower =- 1 ,upper =1 > y;
11+ y <- y_raw - x;
12+ }
13+ model {
14+ /* uniform within constraints */
15+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /*
2+ * BUGS Volume 3, funshapes, square minus circle
3+ * http://www.openbugs.info/Examples/Funshapes.html
4+ *
5+ * first draw raw samples from diamond-like shape reflected per
6+ * quadrant, then reflect in transformed parameters
7+ *
8+ * unfortunate redundancy in 1-sqrt() term because we can't
9+ * get local variables into parameters
10+ */
11+ parameters {
12+ real < lower =- 1 ,upper =1 > x_raw;
13+ real < lower = - (1 - sqrt( 1 - square( 1 - fabs (x_raw)))),
14+ upper = (1 - sqrt( 1 - square( 1 - fabs (x_raw))))> y_raw;
15+ }
16+ transformed parameters {
17+ real < lower =- 1 ,upper =1 > x;
18+ real < lower =- 1 ,upper =1 > y;
19+ x <- if_else (x_raw > 0 , 1 , - 1 ) - x_raw;
20+ y <- if_else (y_raw > 0 , 1 , - 1 ) - y_raw;
21+ }
22+ model {
23+ lp__ <- lp__ + log1m(sqrt( 1 - square( 1 - fabs (x_raw))));
24+ }
You can’t perform that action at this time.
0 commit comments