Skip to content

Commit fe8d24f

Browse files
committed
bugs example v2/endo vectorization
1 parent 19b682b commit fe8d24f

File tree

4 files changed

+36
-81
lines changed

4 files changed

+36
-81
lines changed

bugs_examples/vol1/seeds/seeds.stan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ transformed parameters {
2525
sigma <- 1.0 / sqrt(tau);
2626
}
2727
model {
28-
real tmpp[I];
2928
alpha0 ~ normal(0.0,1.0E3);
3029
alpha1 ~ normal(0.0,1.0E3);
3130
alpha2 ~ normal(0.0,1.0E3);

bugs_examples/vol2/endo/endo1.stan

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,40 @@
55
# model specifications are used for one equivalent
66
# model. This is method 1.
77

8-
# status: (works)
9-
108
data {
119
int n10;
1210
int n01;
1311
int n11;
1412
int I;
15-
int J;
1613
}
17-
/*
18-
19-
Y <-
20-
structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
21-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
22-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
23-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
24-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
25-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
26-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
27-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
28-
1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
50-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
51-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(183, 2))
57-
*/
5814

5915
transformed data {
60-
int Y[I, 2];
61-
int est[I, 2];
16+
int J;
17+
int Y[2, I];
18+
vector<lower=0>[I] est[2];
19+
vector[I] est1m2;
20+
J <- 2;
6221
for (i in 1:I) {
63-
Y[i, 1] <- 1;
64-
Y[i, 2] <- 0;
22+
Y[1, i] <- 1;
23+
Y[2, i] <- 0;
6524
}
6625
for (i in 1:n10) {
67-
est[i, 1] <- 1;
68-
est[i, 2] <- 0;
26+
est[1, i] <- 1;
27+
est[2, i] <- 0;
6928
}
7029
for (i in (n10 + 1):(n10 + n01)) {
71-
est[i, 1] <- 0;
72-
est[i, 2] <- 1;
30+
est[1, i] <- 0;
31+
est[2, i] <- 1;
7332
}
7433
for (i in (n10 + n01 + 1):(n10 + n01 + n11)) {
75-
est[i, 1] <- 1;
76-
est[i, 2] <- 1;
34+
est[1, i] <- 1;
35+
est[2, i] <- 1;
7736
}
7837
for (i in (n10 + n01 + n11 + 1):I ) {
79-
est[i, 1] <- 0;
80-
est[i, 2] <- 0;
38+
est[1, i] <- 0;
39+
est[2, i] <- 0;
8140
}
41+
est1m2 <- est[1] - est[2];
8242
}
8343

8444
parameters {
@@ -88,6 +48,5 @@ parameters {
8848
model {
8949
# METHOD 1: Logistic regression
9050
beta ~ normal(0, 1000);
91-
for (i in 1:I)
92-
Y[i, 1] ~ binomial(1, inv_logit(beta * (est[i, 1] - est[i, J])));
51+
Y[1] ~ binomial_logit(1, beta * est1m2);
9352
}

bugs_examples/vol2/endo/endo3.stan

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,44 @@ data {
1111
int n01;
1212
int n11;
1313
int I;
14-
int J;
15-
# int Y[I, 2];
16-
# int est[I, 2];
1714
}
1815

1916
transformed data {
20-
int<lower=0> Y[I, 2];
21-
int<lower=0> est[I, 2];
17+
int J;
18+
int<lower=0> Y[2, I];
19+
vector<lower=0>[I] est[2];
20+
J <- 2;
2221
for (i in 1:I) {
23-
Y[i, 1] <- 1;
24-
Y[i, 2] <- 0;
22+
Y[1, i] <- 1;
23+
Y[2, i] <- 0;
2524
}
2625
for (i in 1:n10) {
27-
est[i, 1] <- 1;
28-
est[i, 2] <- 0;
26+
est[1, i] <- 1;
27+
est[2, i] <- 0;
2928
}
3029
for (i in (n10 + 1):(n10 + n01)) {
31-
est[i, 1] <- 0;
32-
est[i, 2] <- 1;
30+
est[1, i] <- 0;
31+
est[2, i] <- 1;
3332
}
3433
for (i in (n10 + n01 + 1):(n10 + n01 + n11)) {
35-
est[i, 1] <- 1;
36-
est[i, 2] <- 1;
34+
est[1, i] <- 1;
35+
est[2, i] <- 1;
3736
}
38-
for (i in (n10 + n01 + n11 + 1):I ) {
39-
est[i, 1] <- 0;
40-
est[i, 2] <- 0;
37+
for (i in (n10 + n01 + n11 + 1):I) {
38+
est[1, i] <- 0;
39+
est[2, i] <- 0;
4140
}
4241
}
4342

4443
parameters {
4544
real beta;
46-
real beta0[I];
45+
vector[I] beta0;
4746
}
4847

4948
model {
5049
# METHOD 3 fit standard Poisson regressions relative to baseline
5150
beta ~ normal(0, 1000);
5251
beta0 ~ normal(0, 1000);
53-
for (i in 1:I)
54-
for (j in 1:J)
55-
Y[i, j] ~ poisson_log(beta0[i] + beta * est[i, j]);
52+
for (j in 1:J)
53+
Y[j] ~ poisson_log(beta0 + beta * est[j]);
5654
}

bugs_examples/vol2/eyes/eyes.stan

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ parameters {
1313
real<lower=0> sigmasq;
1414
real<lower=0> theta;
1515
real lambda_1;
16-
real<lower=0,upper= 1> p1;
16+
real<lower=0,upper=1> p1;
1717
}
1818
transformed parameters {
1919
real lambda[2];
@@ -24,7 +24,6 @@ transformed parameters {
2424
}
2525

2626
model {
27-
p1 ~ beta(1, 1);
2827
theta ~ normal(0, 100);
2928
lambda_1 ~ normal(0, 1e3);
3029
sigmasq ~ inv_gamma(1e-3, 1e-3);

0 commit comments

Comments
 (0)