Skip to content

Commit e2de966

Browse files
authored
Merge pull request #190 from andrjohns/feature/basic_dist_update
Update basic_distributions syntax
2 parents 5dcadbc + 6b4c0b0 commit e2de966

File tree

11 files changed

+48
-87
lines changed

11 files changed

+48
-87
lines changed

basic_distributions/binormal.stan

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
transformed data {
2-
matrix[2,2] Sigma;
3-
vector[2] mu;
4-
5-
mu[1] <- 0.0;
6-
mu[2] <- 0.0;
7-
Sigma[1,1] <- 1.0;
8-
Sigma[2,2] <- 1.0;
9-
Sigma[1,2] <- 0.10;
10-
Sigma[2,1] <- 0.10;
2+
matrix[2,2] Sigma = [[1, 0.1],
3+
[0.1, 1]];
4+
vector[2] mu = [0, 0]';
115
}
126
parameters {
137
vector[2] y;
148
}
159
model {
16-
y ~ multi_normal(mu,Sigma);
10+
y ~ multi_normal(mu, Sigma);
1711
}

basic_distributions/inv_wishart.stan

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
transformed data {
2-
cov_matrix[3] S;
3-
S[1, 1] <- 2; S[1, 2] <- 0; S[1, 3] <- 0;
4-
S[2, 2] <- 1; S[2, 1] <- 0; S[2, 3] <- 0;
5-
S[3, 3] <- .5; S[3, 1] <- 0; S[3, 2] <- 0;
2+
cov_matrix[3] S = [[2, 0, 0],
3+
[0, 1, 0],
4+
[0, 0, 0.5]];
65
}
76
parameters {
87
cov_matrix[3] W;

basic_distributions/normal.stan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ parameters {
22
real y;
33
}
44
model {
5-
y ~ normal(0,1);
5+
y ~ normal(0, 1);
66
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
transformed data {
2-
real<lower=0,upper=1> theta;
3-
real mu[2];
4-
real<lower=0> sigma[2];
5-
6-
mu[1] <- 0.0; sigma[1] <- 0.5;
7-
mu[2] <- 4.0; sigma[2] <- 3.0;
8-
theta <- 0.25;
2+
real<lower=0,upper=1> theta = 0.25;
3+
vector[2] mu = [0, 4]';
4+
vector<lower=0>[2] sigma = [0.5, 3]';
95
}
106
parameters {
117
real y;
128
}
139
model {
14-
increment_log_prob(log_sum_exp(log(theta)
15-
+ normal_log(y,mu[1],sigma[1]),
16-
log(1.0 - theta)
17-
+ normal_log(y,mu[2],sigma[2])));
10+
target += log_mix(theta,
11+
normal_lpdf(y | mu[1], sigma[1]),
12+
normal_lpdf(y | mu[2], sigma[2]));
1813
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
transformed data {
2-
real L;
3-
real H;
4-
L <- -5.0;
5-
H <- 5.0;
2+
real L = -5;
3+
real H = 5;
64
}
75
parameters {
8-
real<lower=L,upper=H> a;
9-
real<lower=a,upper=H> b;
6+
real<lower=L, upper=H> a;
7+
real<lower=a, upper=H> b;
108
}
119
model {
12-
// a ~ uniform(L,b);
13-
// b ~ uniform(a,H);
10+
// a ~ uniform(L, b);
11+
// b ~ uniform(a, H);
1412
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
parameters {
2-
real<lower=-1,upper=1> x1;
3-
real<lower=-1,upper=1> x2;
2+
real<lower=-1, upper=1> x1;
3+
real<lower=-1, upper=1> x2;
44
}
55
model {
66
}
77
generated quantities {
8-
real a;
9-
real b;
10-
a <- fmax(x1,x2);
11-
b <- fmin(x1,x2);
8+
real a = fmax(x1, x2);
9+
real b = fmin(x1, x2);
1210
}

basic_distributions/triangle.stan

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters {
2-
real<lower=-1,upper=1> y;
2+
real<lower=-1, upper=1> y;
33
}
44
model {
5-
increment_log_prob(log1m(fabs(y)));
5+
target += log1m(fabs(y));
66
}

basic_distributions/uniform.stan

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters {
2-
real<lower=0,upper=1> y;
2+
real<lower=0, upper=1> y;
33
}
44
model {
5-
y ~ uniform(0,1);
5+
y ~ uniform(0, 1);
66
}

basic_distributions/wishart.stan

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
transformed data {
2-
cov_matrix[2] S;
3-
4-
for (i in 1:2)
5-
for (j in 1:2)
6-
S[i,j] <- 0.0;
7-
8-
S[1,1] <- 2.0;
9-
S[2,2] <- 0.5;
2+
cov_matrix[2] S = [[2, 0],
3+
[0, 0.5]];
104
}
115
parameters {
126
cov_matrix[2] W;

basic_distributions/wishart2.stan

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
transformed data {
22
cov_matrix[4] S;
33

4-
S[1,1] <- 2.9983662;
5-
S[1,2] <- 0.2898776;
6-
S[1,3] <- -2.650523;
7-
S[1,4] <- 0.1055911;
8-
S[2,2] <- 11.4803610;
9-
S[2,3] <- 7.157993;
10-
S[2,4] <- -3.1129955;
11-
S[3,3] <- 11.676181;
12-
S[3,4] <- -3.5866852;
13-
S[4,4] <- 1.4482736;
4+
S[1,1] = 2.9983662;
5+
S[2,1] = 0.2898776;
6+
S[3,1] = -2.650523;
7+
S[4,1] = 0.1055911;
8+
S[2,2] = 11.4803610;
9+
S[3,2] = 7.157993;
10+
S[4,2] = -3.1129955;
11+
S[3,3] = 11.676181;
12+
S[4,3] = -3.5866852;
13+
S[4,4] = 1.4482736;
1414

15-
for (m in 1:4)
16-
for (n in 1:(m-1))
17-
S[m,n] <- S[n,m];
15+
S = symmetrize_from_lower_tri(S);
1816
}
1917
parameters {
2018
cov_matrix[4] W;

0 commit comments

Comments
 (0)