surmise_test_function
Created on Tue Feb 9 10:27:23 2021
@author: mosesyhc
- surmise_test_function.borehole(H, persis_info, sim_specs, libE_info)
Wraps the borehole function
- surmise_test_function.borehole_failmodel(x, theta)
Given x and theta, return matrix of [row x] times [row theta] of values.
- surmise_test_function.borehole_model(x, theta)
Given x and theta, return matrix of [row x] times [row theta] of values.
- surmise_test_function.borehole_true(x)
Given x, return matrix of [row x] times 1 of values.
- surmise_test_function.borehole_vec(x, theta)
Given x and theta, return vector of values.
- surmise_test_function.tstd2theta(tstd, hard=True)
Given standardized theta in [0, 1]^d, return non-standardized theta.
- surmise_test_function.xstd2x(xstd)
Given standardized x in [0, 1]^2 x {0, 1}, return non-standardized x.
surmise_test_function.py
1"""
2Created on Tue Feb 9 10:27:23 2021
3
4@author: mosesyhc
5"""
6
7import numpy as np
8
9
10def borehole(H, persis_info, sim_specs, libE_info):
11 """
12 Wraps the borehole function
13 """
14
15 H_o = np.zeros(H["x"].shape[0], dtype=sim_specs["out"])
16
17 # If observation do not use failure model
18 sim_id = libE_info["H_rows"][0]
19 if sim_id > sim_specs["user"]["num_obs"]:
20 H_o["f"] = borehole_failmodel(H["x"], H["thetas"])
21 else:
22 H_o["f"] = borehole_model(H["x"], H["thetas"])
23 return H_o, persis_info
24
25
26def borehole_failmodel(x, theta):
27 """Given x and theta, return matrix of [row x] times [row theta] of values."""
28 f = borehole_model(x, theta)
29 wheretoobig = np.where((f / borehole_true(x)) > 1.25)
30 f[wheretoobig[0], wheretoobig[1]] = np.inf
31 return f
32
33
34def borehole_model(x, theta):
35 """Given x and theta, return matrix of [row x] times [row theta] of values."""
36 theta = tstd2theta(theta)
37 x = xstd2x(x)
38 p = x.shape[0]
39 n = theta.shape[0]
40
41 theta_stacked = np.repeat(theta, repeats=p, axis=0)
42 x_stacked = np.tile(x.astype(float), (n, 1))
43
44 f = borehole_vec(x_stacked, theta_stacked).reshape((n, p))
45 return f.T
46
47
48def borehole_true(x):
49 """Given x, return matrix of [row x] times 1 of values."""
50 # assume true theta is [0.5]^d
51 theta0 = np.atleast_2d(np.array([0.5] * 4))
52 f0 = borehole_model(x, theta0)
53
54 return f0
55
56
57def borehole_vec(x, theta):
58 """Given x and theta, return vector of values."""
59 (Hu, Ld_Kw, Treff, powparam) = np.split(theta, theta.shape[1], axis=1)
60 (rw, Hl) = np.split(x[:, :-1], 2, axis=1)
61 numer = 2 * np.pi * (Hu - Hl)
62 denom1 = 2 * Ld_Kw / rw**2
63 denom2 = Treff
64
65 f = ((numer / ((denom1 + denom2))) * np.exp(powparam * rw)).reshape(-1)
66
67 return f
68
69
70def tstd2theta(tstd, hard=True):
71 """Given standardized theta in [0, 1]^d, return non-standardized theta."""
72 if tstd.ndim < 1.5:
73 tstd = tstd[:, None].T
74 (Treffs, Hus, LdKw, powparams) = np.split(tstd, tstd.shape[1], axis=1)
75
76 Treff = (0.5 - 0.05) * Treffs + 0.05
77 Hu = Hus * (1110 - 990) + 990
78 if hard:
79 Ld_Kw = LdKw * (1680 / 1500 - 1120 / 15000) + 1120 / 15000
80 else:
81 Ld_Kw = LdKw * (1680 / 9855 - 1120 / 12045) + 1120 / 12045
82
83 powparam = powparams * (0.5 - (-0.5)) + (-0.5)
84
85 theta = np.hstack((Hu, Ld_Kw, Treff, powparam))
86 return theta
87
88
89def xstd2x(xstd):
90 """Given standardized x in [0, 1]^2 x {0, 1}, return non-standardized x."""
91 if xstd.ndim < 1.5:
92 xstd = xstd[:, None].T
93 (rws, Hls, labels) = np.split(xstd, xstd.shape[1], axis=1)
94
95 rw = rws * (np.log(0.5) - np.log(0.05)) + np.log(0.05)
96 rw = np.exp(rw)
97 Hl = Hls * (820 - 700) + 700
98
99 x = np.hstack((rw, Hl, labels))
100 return x