Skip to content

Commit c8af4b5

Browse files
author
weilixu
committed
buildsim calibration
Integrate BC-STAN scripts from AChong.
1 parent 02e51a7 commit c8af4b5

File tree

13 files changed

+22782
-158
lines changed

13 files changed

+22782
-158
lines changed

.idea/workspace.xml

+181-158
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildsimcalibration/DATACOMP.csv

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
yc,xc1,xc2,xc3,tc1,tc2,tc3
2+
1836.311382,1.691666667,37.93010753,204.0215054,0.726,19.535,0.0011998
3+
1600.207111,0.061011905,51.19196429,181.8467262,0.726,19.535,0.0011998
4+
1738.757931,4.350672043,50.60752688,219.4072581,0.726,19.535,0.0011998
5+
1682.950916,5.442638889,56.03472222,199.3166667,0.726,19.535,0.0011998
6+
1775.641414,14.06424731,44.78091398,244.1129032,0.726,19.535,0.0011998
7+
2024.757846,21.35458333,37.57916667,305.2166667,0.726,19.535,0.0011998
8+
2105.986898,22.26639785,49.41532258,272.4677419,0.726,19.535,0.0011998
9+
2138.781979,22.61505376,42.75537634,222.2553763,0.726,19.535,0.0011998
10+
1832.845423,18.45805556,53.5,225.0458333,0.726,19.535,0.0011998
11+
1652.636921,8.881451613,54.77016129,233.7217742,0.726,19.535,0.0011998
12+
1641.316706,6.096666667,42.07638889,217.4472222,0.726,19.535,0.0011998
13+
1915.45202,0.197043011,48.17607527,224.5537634,0.726,19.535,0.0011998
14+
2106.973629,1.691666667,37.93010753,204.0215054,0.58,29.558,0.0006871
15+
1824.393576,0.061011905,51.19196429,181.8467262,0.58,29.558,0.0006871
16+
2038.370765,4.350672043,50.60752688,219.4072581,0.58,29.558,0.0006871
17+
1952.372714,5.442638889,56.03472222,199.3166667,0.58,29.558,0.0006871
18+
2130.126984,14.06424731,44.78091398,244.1129032,0.58,29.558,0.0006871
19+
2397.227572,21.35458333,37.57916667,305.2166667,0.58,29.558,0.0006871
20+
2489.730744,22.26639785,49.41532258,272.4677419,0.58,29.558,0.0006871
21+
2533.991209,22.61505376,42.75537634,222.2553763,0.58,29.558,0.0006871
22+
2189.037912,18.45805556,53.5,225.0458333,0.58,29.558,0.0006871
23+
1989.524663,8.881451613,54.77016129,233.7217742,0.58,29.558,0.0006871
24+
1943.786733,6.096666667,42.07638889,217.4472222,0.58,29.558,0.0006871
25+
2182.146452,0.197043011,48.17607527,224.5537634,0.58,29.558,0.0006871
26+
1976.665565,1.691666667,37.93010753,204.0215054,0.422,24.97,0.0001627
27+
1706.465065,0.061011905,51.19196429,181.8467262,0.422,24.97,0.0001627
28+
1926.973194,4.350672043,50.60752688,219.4072581,0.422,24.97,0.0001627
29+
1839.710073,5.442638889,56.03472222,199.3166667,0.422,24.97,0.0001627
30+
2028.951466,14.06424731,44.78091398,244.1129032,0.422,24.97,0.0001627
31+
2271.219777,21.35458333,37.57916667,305.2166667,0.422,24.97,0.0001627
32+
2361.691578,22.26639785,49.41532258,272.4677419,0.422,24.97,0.0001627
33+
2398.918526,22.61505376,42.75537634,222.2553763,0.422,24.97,0.0001627
34+
2081.633159,18.45805556,53.5,225.0458333,0.422,24.97,0.0001627
35+
1899.969234,8.881451613,54.77016129,233.7217742,0.422,24.97,0.0001627
36+
1847.183727,6.096666667,42.07638889,217.4472222,0.422,24.97,0.0001627
37+
2036.259799,0.197043011,48.17607527,224.5537634,0.422,24.97,0.0001627
38+
1645.848066,1.691666667,37.93010753,204.0215054,0.706,12.971,0.0011428
39+
1432.533047,0.061011905,51.19196429,181.8467262,0.706,12.971,0.0011428
40+
1544.25852,4.350672043,50.60752688,219.4072581,0.706,12.971,0.0011428
41+
1499.753292,5.442638889,56.03472222,199.3166667,0.706,12.971,0.0011428
42+
1561.758979,14.06424731,44.78091398,244.1129032,0.706,12.971,0.0011428
43+
1791.965459,21.35458333,37.57916667,305.2166667,0.706,12.971,0.0011428
44+
1866.808322,22.26639785,49.41532258,272.4677419,0.706,12.971,0.0011428
45+
1891.104205,22.61505376,42.75537634,222.2553763,0.706,12.971,0.0011428
46+
1617.316513,18.45805556,53.5,225.0458333,0.706,12.971,0.0011428
47+
1453.964856,8.881451613,54.77016129,233.7217742,0.706,12.971,0.0011428
48+
1455.169041,6.096666667,42.07638889,217.4472222,0.706,12.971,0.0011428
49+
1732.329969,0.197043011,48.17607527,224.5537634,0.706,12.971,0.0011428
50+
1473.378259,1.691666667,37.93010753,204.0215054,0.413,6.012,0.0002739
51+
1248.091943,0.061011905,51.19196429,181.8467262,0.413,6.012,0.0002739
52+
1381.207432,4.350672043,50.60752688,219.4072581,0.413,6.012,0.0002739
53+
1335.370215,5.442638889,56.03472222,199.3166667,0.413,6.012,0.0002739
54+
1425.239521,14.06424731,44.78091398,244.1129032,0.413,6.012,0.0002739
55+
1626.465221,21.35458333,37.57916667,305.2166667,0.413,6.012,0.0002739
56+
1697.916461,22.26639785,49.41532258,272.4677419,0.413,6.012,0.0002739
57+
1712.343273,22.61505376,42.75537634,222.2553763,0.413,6.012,0.0002739
58+
1478.975722,18.45805556,53.5,225.0458333,0.413,6.012,0.0002739
59+
1343.705986,8.881451613,54.77016129,233.7217742,0.413,6.012,0.0002739
60+
1318.136957,6.096666667,42.07638889,217.4472222,0.413,6.012,0.0002739
61+
1561.146862,0.197043011,48.17607527,224.5537634,0.413,6.012,0.0002739
62+
2975.979622,1.691666667,37.93010753,204.0215054,0.128,8.231,0.000735
63+
2600.833327,0.061011905,51.19196429,181.8467262,0.128,8.231,0.000735
64+
2927.14945,4.350672043,50.60752688,219.4072581,0.128,8.231,0.000735
65+
2845.024497,5.442638889,56.03472222,199.3166667,0.128,8.231,0.000735
66+
3138.696984,14.06424731,44.78091398,244.1129032,0.128,8.231,0.000735
67+
3504.795597,21.35458333,37.57916667,305.2166667,0.128,8.231,0.000735
68+
3686.821406,22.26639785,49.41532258,272.4677419,0.128,8.231,0.000735
69+
3707.505279,22.61505376,42.75537634,222.2553763,0.128,8.231,0.000735
70+
3237.556406,18.45805556,53.5,225.0458333,0.128,8.231,0.000735
71+
2941.936302,8.881451613,54.77016129,233.7217742,0.128,8.231,0.000735
72+
2818.988488,6.096666667,42.07638889,217.4472222,0.128,8.231,0.000735
73+
3059.892679,0.197043011,48.17607527,224.5537634,0.128,8.231,0.000735
74+
1835.621781,1.691666667,37.93010753,204.0215054,0.816,21.478,0.0011063
75+
1596.089255,0.061011905,51.19196429,181.8467262,0.816,21.478,0.0011063
76+
1738.643376,4.350672043,50.60752688,219.4072581,0.816,21.478,0.0011063
77+
1680.349216,5.442638889,56.03472222,199.3166667,0.816,21.478,0.0011063
78+
1779.54957,14.06424731,44.78091398,244.1129032,0.816,21.478,0.0011063
79+
2025.88739,21.35458333,37.57916667,305.2166667,0.816,21.478,0.0011063
80+
2106.001866,22.26639785,49.41532258,272.4677419,0.816,21.478,0.0011063
81+
2140.918137,22.61505376,42.75537634,222.2553763,0.816,21.478,0.0011063
82+
1835.02372,18.45805556,53.5,225.0458333,0.816,21.478,0.0011063
83+
1655.86323,8.881451613,54.77016129,233.7217742,0.816,21.478,0.0011063
84+
1642.213572,6.096666667,42.07638889,217.4472222,0.816,21.478,0.0011063
85+
1911.073946,0.197043011,48.17607527,224.5537634,0.816,21.478,0.0011063
86+
2579.296213,1.691666667,37.93010753,204.0215054,0.157,13.803,0.0004071
87+
2247.654682,0.061011905,51.19196429,181.8467262,0.157,13.803,0.0004071
88+
2533.791274,4.350672043,50.60752688,219.4072581,0.157,13.803,0.0004071
89+
2451.233254,5.442638889,56.03472222,199.3166667,0.157,13.803,0.0004071
90+
2706.172611,14.06424731,44.78091398,244.1129032,0.157,13.803,0.0004071
91+
3019.858217,21.35458333,37.57916667,305.2166667,0.157,13.803,0.0004071
92+
3166.837609,22.26639785,49.41532258,272.4677419,0.157,13.803,0.0004071
93+
3192.20198,22.61505376,42.75537634,222.2553763,0.157,13.803,0.0004071
94+
2785.337744,18.45805556,53.5,225.0458333,0.157,13.803,0.0004071
95+
2537.351452,8.881451613,54.77016129,233.7217742,0.157,13.803,0.0004071
96+
2439.359501,6.096666667,42.07638889,217.4472222,0.157,13.803,0.0004071
97+
2649.309258,0.197043011,48.17607527,224.5537634,0.157,13.803,0.0004071
98+
1584.086649,1.691666667,37.93010753,204.0215054,0.679,9.01,0.0013563
99+
1390.610008,0.061011905,51.19196429,181.8467262,0.679,9.01,0.0013563
100+
1484.734307,4.350672043,50.60752688,219.4072581,0.679,9.01,0.0013563
101+
1442.803491,5.442638889,56.03472222,199.3166667,0.679,9.01,0.0013563
102+
1481.777434,14.06424731,44.78091398,244.1129032,0.679,9.01,0.0013563
103+
1712.476965,21.35458333,37.57916667,305.2166667,0.679,9.01,0.0013563
104+
1786.29391,22.26639785,49.41532258,272.4677419,0.679,9.01,0.0013563
105+
1805.557701,22.61505376,42.75537634,222.2553763,0.679,9.01,0.0013563
106+
1539.256742,18.45805556,53.5,225.0458333,0.679,9.01,0.0013563
107+
1378.373847,8.881451613,54.77016129,233.7217742,0.679,9.01,0.0013563
108+
1386.676202,6.096666667,42.07638889,217.4472222,0.679,9.01,0.0013563
109+
1680.499585,0.197043011,48.17607527,224.5537634,0.679,9.01,0.0013563
110+
2173.918568,1.691666667,37.93010753,204.0215054,0.384,23.152,0.0008346
111+
1881.648491,0.061011905,51.19196429,181.8467262,0.384,23.152,0.0008346
112+
2097.010598,4.350672043,50.60752688,219.4072581,0.384,23.152,0.0008346
113+
2016.711717,5.442638889,56.03472222,199.3166667,0.384,23.152,0.0008346
114+
2191.979488,14.06424731,44.78091398,244.1129032,0.384,23.152,0.0008346
115+
2472.120012,21.35458333,37.57916667,305.2166667,0.384,23.152,0.0008346
116+
2573.891277,22.26639785,49.41532258,272.4677419,0.384,23.152,0.0008346
117+
2611.76857,22.61505376,42.75537634,222.2553763,0.384,23.152,0.0008346
118+
2258.167906,18.45805556,53.5,225.0458333,0.384,23.152,0.0008346
119+
2051.308275,8.881451613,54.77016129,233.7217742,0.384,23.152,0.0008346
120+
2001.234627,6.096666667,42.07638889,217.4472222,0.384,23.152,0.0008346
121+
2252.17893,0.197043011,48.17607527,224.5537634,0.384,23.152,0.0008346

buildsimcalibration/DATAFIELD.csv

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
yf,xf1,xf2,xf3
2+
1562,1.69166666666667,37.9301075268817,204.021505376344
3+
1395,0.0610119047619034,51.1919642857143,181.846726190476
4+
1279,4.35067204301076,50.6075268817204,219.407258064516
5+
1347,5.44263888888889,56.0347222222222,199.316666666667
6+
1363,14.064247311828,44.7809139784946,244.112903225806
7+
1691,21.3545833333333,37.5791666666667,305.216666666667
8+
1852,22.2663978494624,49.4153225806452,272.467741935484
9+
1983,22.6150537634409,42.755376344086,222.255376344086
10+
1650,18.4580555555556,53.5,225.045833333333
11+
1385,8.88145161290323,54.7701612903226,233.721774193548
12+
1347,6.09666666666667,42.0763888888889,217.447222222222
13+
1524,0.197043010752687,48.1760752688172,224.55376344086

buildsimcalibration/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
This package is developed jointly between BuildSim team and Professor Adrian Chong.
3+
4+
The original script and example can be found at GITHUB page: https://github.com/adChong/bc-stan
5+
6+
The paper published can be found at: https://www.sciencedirect.com/science/article/pii/S0378778818307539?via%3Dihub
7+
8+
"""

buildsimcalibration/bcWithPred.stan

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
data {
2+
int<lower=1> n; // number of field data
3+
int<lower=1> m; // number of computer simulation
4+
int<lower=1> n_pred; // number of predictions
5+
int<lower=1> p; // number of observable inputs x
6+
int<lower=1> q; // number of calibration parameters t
7+
vector[n] y; // field observations
8+
vector[m] eta; // output of computer simulations
9+
matrix[n, p] xf; // observable inputs corresponding to y
10+
// (xc, tc): design points corresponding to eta
11+
matrix[m, p] xc;
12+
matrix[m, q] tc;
13+
// x_pred: new design points for predictions
14+
matrix[n_pred, p] x_pred;
15+
}
16+
17+
transformed data {
18+
int<lower = 1> N;
19+
vector[n+m] y_eta;
20+
vector[n+m+n_pred] mu; // mean vector
21+
matrix[n+n_pred, p] X; // X=[xf, x_pred]
22+
23+
N = n + m + n_pred;
24+
// set mean vector to zero
25+
for (i in 1:N) {
26+
mu[i] = 0;
27+
}
28+
X = append_row(xf, x_pred);
29+
y_eta = append_row(y, eta); // y_eta = [y, eta]
30+
}
31+
32+
parameters {
33+
// tf: calibration parameters
34+
// rho_eta: reparameterization of beta_eta
35+
// rho_delta: reparameterization of beta_delta
36+
// lambda_eta: precision parameter for eta
37+
// lambda_delta: precision parameter for bias term
38+
// lambda_e: precision parameter of observation error
39+
// y_pred: predictions
40+
row_vector<lower=0, upper=1>[q] tf;
41+
row_vector<lower=0, upper=1>[p+q] rho_eta;
42+
row_vector<lower=0, upper=1>[p] rho_delta;
43+
real<lower=0> lambda_eta;
44+
real<lower=0> lambda_delta;
45+
real<lower=0> lambda_e;
46+
vector[n_pred] y_pred;
47+
}
48+
49+
transformed parameters {
50+
// beta_delta: correlation parameter for bias term
51+
// beta_e: correlation parameter of observation error
52+
row_vector[p+q] beta_eta;
53+
row_vector[p] beta_delta;
54+
beta_eta = -4.0 * log(rho_eta);
55+
beta_delta = -4.0 * log(rho_delta);
56+
}
57+
58+
model {
59+
// declare variables
60+
matrix[N, p+q] xt;
61+
matrix[N, N] sigma_eta; // simulator covarinace
62+
matrix[n+n_pred, n+n_pred] sigma_delta; // bias term covariance
63+
matrix[N, N] sigma_z; // covariance matrix
64+
matrix[N, N] L; // cholesky decomposition of covariance matrix
65+
vector[N] z; // z = [y, eta, y_pred]
66+
row_vector[p] temp_delta;
67+
row_vector[p+q] temp_eta;
68+
69+
z = append_row(y_eta, y_pred); // z = [y, eta, y_pred]
70+
71+
// xt = [[xf,tf],[xc,tc],[x_pred,tf]]
72+
xt[1:n, 1:p] = xf;
73+
xt[1:n, (p+1):(p+q)] = rep_matrix(tf, n);
74+
xt[(n+1):(n+m), 1:p] = xc;
75+
xt[(n+1):(n+m), (p+1):(p+q)] = tc;
76+
xt[(n+m+1):N, 1:p] = x_pred;
77+
xt[(n+m+1):N, (p+1):(p+q)] = rep_matrix(tf, n_pred);
78+
79+
// diagonal elements of sigma_eta
80+
sigma_eta = diag_matrix(rep_vector((1 / lambda_eta), N));
81+
82+
// off-diagonal elements of sigma_eta
83+
for (i in 1:(N-1)) {
84+
for (j in (i+1):N) {
85+
temp_eta = xt[i] - xt[j];
86+
sigma_eta[i, j] = beta_eta .* temp_eta * temp_eta';
87+
sigma_eta[i, j] = exp(-sigma_eta[i, j]) / lambda_eta;
88+
sigma_eta[j, i] = sigma_eta[i, j];
89+
}
90+
}
91+
92+
// diagonal elements of sigma_delta
93+
sigma_delta = diag_matrix(rep_vector((1 / lambda_delta),
94+
n+n_pred));
95+
96+
// off-diagonal elements of sigma_delta
97+
for (i in 1:(n+n_pred-1)) {
98+
for (j in (i+1):(n+n_pred)) {
99+
temp_delta = X[i] - X[j];
100+
sigma_delta[i, j] = beta_delta .* temp_delta * temp_delta';
101+
sigma_delta[i, j] = exp(-sigma_delta[i, j]) / lambda_delta;
102+
sigma_delta[j, i] = sigma_delta[i, j];
103+
}
104+
}
105+
106+
// computation of covariance matrix sigma_z
107+
sigma_z = sigma_eta;
108+
sigma_z[1:n, 1:n] = sigma_eta[1:n, 1:n] +
109+
sigma_delta[1:n, 1:n];
110+
sigma_z[1:n, (n+m+1):N] = sigma_eta[1:n, (n+m+1):N] +
111+
sigma_delta[1:n, (n+1):(n+n_pred)];
112+
sigma_z[(n+m+1):N, 1:n] = sigma_eta[(n+m+1):N, 1:n] +
113+
sigma_delta[(n+1):(n+n_pred),1:n];
114+
sigma_z[(n+m+1):N, (n+m+1):N] = sigma_eta[(n+m+1):N, (n+m+1):N] +
115+
sigma_delta[(n+1):(n+n_pred), (n+1):(n+n_pred)];
116+
117+
// add observation errors
118+
for (i in 1:n) {
119+
sigma_z[i, i] = sigma_z[i, i] + (1.0 / lambda_e);
120+
}
121+
122+
// Specify priors here
123+
rho_eta[1:(p+q)] ~ beta(1.0, 0.3);
124+
rho_delta[1:p] ~ beta(1.0, 0.3);
125+
lambda_eta ~ gamma(10, 10); // gamma (shape, rate)
126+
lambda_delta ~ gamma(10, 0.3);
127+
lambda_e ~ gamma(10, 0.03);
128+
129+
L = cholesky_decompose(sigma_z); // cholesky decomposition
130+
z ~ multi_normal_cholesky(mu, L);
131+
}

0 commit comments

Comments
 (0)