chwirut1
- chwirut1.chwirut_eval(H, _, sim_specs)
Evaluates the chwirut objective function at a given set of points in
H["x"]. If"obj_component"is a field insim_specs["out"], only that component of the objective will be evaluated. Otherwise, all 214 components are evaluated and returned in the"fvec"field.See also
test_persistent_aposmm_pounders.py for an example where the entire fvec is computed each call.
See also
test_uniform_sampling_one_residual_at_a_time.py for an example where one component of fvec is computed per call
chwirut1.py
1__all__ = ["chwirut_eval"]
2import numpy as np
3
4NOBSERVATIONS = 214
5
6y = np.zeros(214)
7t = np.zeros(214)
8
9# fmt: off
10y[0] = 92.9000; t[0] = 0.5000;
11y[1] = 78.7000; t[1] = 0.6250;
12y[2] = 64.2000; t[2] = 0.7500;
13y[3] = 64.9000; t[3] = 0.8750;
14y[4] = 57.1000; t[4] = 1.0000;
15y[5] = 43.3000; t[5] = 1.2500;
16y[6] = 31.1000; t[6] = 1.7500;
17y[7] = 23.6000; t[7] = 2.2500;
18y[8] = 31.0500; t[8] = 1.7500;
19y[9] = 23.7750; t[9] = 2.2500;
20y[10] = 17.7375; t[10] = 2.7500;
21y[11] = 13.8000; t[11] = 3.2500;
22y[12] = 11.5875; t[12] = 3.7500;
23y[13] = 9.4125; t[13] = 4.2500;
24y[14] = 7.7250; t[14] = 4.7500;
25y[15] = 7.3500; t[15] = 5.2500;
26y[16] = 8.0250; t[16] = 5.7500;
27y[17] = 90.6000; t[17] = 0.5000;
28y[18] = 76.9000; t[18] = 0.6250;
29y[19] = 71.6000; t[19] = 0.7500;
30y[20] = 63.6000; t[20] = 0.8750;
31y[21] = 54.0000; t[21] = 1.0000;
32y[22] = 39.2000; t[22] = 1.2500;
33y[23] = 29.3000; t[23] = 1.7500;
34y[24] = 21.4000; t[24] = 2.2500;
35y[25] = 29.1750; t[25] = 1.7500;
36y[26] = 22.1250; t[26] = 2.2500;
37y[27] = 17.5125; t[27] = 2.7500;
38y[28] = 14.2500; t[28] = 3.2500;
39y[29] = 9.4500; t[29] = 3.7500;
40y[30] = 9.1500; t[30] = 4.2500;
41y[31] = 7.9125; t[31] = 4.7500;
42y[32] = 8.4750; t[32] = 5.2500;
43y[33] = 6.1125; t[33] = 5.7500;
44y[34] = 80.0000; t[34] = 0.5000;
45y[35] = 79.0000; t[35] = 0.6250;
46y[36] = 63.8000; t[36] = 0.7500;
47y[37] = 57.2000; t[37] = 0.8750;
48y[38] = 53.2000; t[38] = 1.0000;
49y[39] = 42.5000; t[39] = 1.2500;
50y[40] = 26.8000; t[40] = 1.7500;
51y[41] = 20.4000; t[41] = 2.2500;
52y[42] = 26.8500; t[42] = 1.7500;
53y[43] = 21.0000; t[43] = 2.2500;
54y[44] = 16.4625; t[44] = 2.7500;
55y[45] = 12.5250; t[45] = 3.2500;
56y[46] = 10.5375; t[46] = 3.7500;
57y[47] = 8.5875; t[47] = 4.2500;
58y[48] = 7.1250; t[48] = 4.7500;
59y[49] = 6.1125; t[49] = 5.2500;
60y[50] = 5.9625; t[50] = 5.7500;
61y[51] = 74.1000; t[51] = 0.5000;
62y[52] = 67.3000; t[52] = 0.6250;
63y[53] = 60.8000; t[53] = 0.7500;
64y[54] = 55.5000; t[54] = 0.8750;
65y[55] = 50.3000; t[55] = 1.0000;
66y[56] = 41.0000; t[56] = 1.2500;
67y[57] = 29.4000; t[57] = 1.7500;
68y[58] = 20.4000; t[58] = 2.2500;
69y[59] = 29.3625; t[59] = 1.7500;
70y[60] = 21.1500; t[60] = 2.2500;
71y[61] = 16.7625; t[61] = 2.7500;
72y[62] = 13.2000; t[62] = 3.2500;
73y[63] = 10.8750; t[63] = 3.7500;
74y[64] = 8.1750; t[64] = 4.2500;
75y[65] = 7.3500; t[65] = 4.7500;
76y[66] = 5.9625; t[66] = 5.2500;
77y[67] = 5.6250; t[67] = 5.7500;
78y[68] = 81.5000; t[68] = .5000;
79y[69] = 62.4000; t[69] = .7500;
80y[70] = 32.5000; t[70] = 1.5000;
81y[71] = 12.4100; t[71] = 3.0000;
82y[72] = 13.1200; t[72] = 3.0000;
83y[73] = 15.5600; t[73] = 3.0000;
84y[74] = 5.6300; t[74] = 6.0000;
85y[75] = 78.0000; t[75] = .5000;
86y[76] = 59.9000; t[76] = .7500;
87y[77] = 33.2000; t[77] = 1.5000;
88y[78] = 13.8400; t[78] = 3.0000;
89y[79] = 12.7500; t[79] = 3.0000;
90y[80] = 14.6200; t[80] = 3.0000;
91y[81] = 3.9400; t[81] = 6.0000;
92y[82] = 76.8000; t[82] = .5000;
93y[83] = 61.0000; t[83] = .7500;
94y[84] = 32.9000; t[84] = 1.5000;
95y[85] = 13.8700; t[85] = 3.0000;
96y[86] = 11.8100; t[86] = 3.0000;
97y[87] = 13.3100; t[87] = 3.0000;
98y[88] = 5.4400; t[88] = 6.0000;
99y[89] = 78.0000; t[89] = .5000;
100y[90] = 63.5000; t[90] = .7500;
101y[91] = 33.8000; t[91] = 1.5000;
102y[92] = 12.5600; t[92] = 3.0000;
103y[93] = 5.6300; t[93] = 6.0000;
104y[94] = 12.7500; t[94] = 3.0000;
105y[95] = 13.1200; t[95] = 3.0000;
106y[96] = 5.4400; t[96] = 6.0000;
107y[97] = 76.8000; t[97] = .5000;
108y[98] = 60.0000; t[98] = .7500;
109y[99] = 47.8000; t[99] = 1.0000;
110y[100] = 32.0000; t[100] = 1.5000;
111y[101] = 22.2000; t[101] = 2.0000;
112y[102] = 22.5700; t[102] = 2.0000;
113y[103] = 18.8200; t[103] = 2.5000;
114y[104] = 13.9500; t[104] = 3.0000;
115y[105] = 11.2500; t[105] = 4.0000;
116y[106] = 9.0000; t[106] = 5.0000;
117y[107] = 6.6700; t[107] = 6.0000;
118y[108] = 75.8000; t[108] = .5000;
119y[109] = 62.0000; t[109] = .7500;
120y[110] = 48.8000; t[110] = 1.0000;
121y[111] = 35.2000; t[111] = 1.5000;
122y[112] = 20.0000; t[112] = 2.0000;
123y[113] = 20.3200; t[113] = 2.0000;
124y[114] = 19.3100; t[114] = 2.5000;
125y[115] = 12.7500; t[115] = 3.0000;
126y[116] = 10.4200; t[116] = 4.0000;
127y[117] = 7.3100; t[117] = 5.0000;
128y[118] = 7.4200; t[118] = 6.0000;
129y[119] = 70.5000; t[119] = .5000;
130y[120] = 59.5000; t[120] = .7500;
131y[121] = 48.5000; t[121] = 1.0000;
132y[122] = 35.8000; t[122] = 1.5000;
133y[123] = 21.0000; t[123] = 2.0000;
134y[124] = 21.6700; t[124] = 2.0000;
135y[125] = 21.0000; t[125] = 2.5000;
136y[126] = 15.6400; t[126] = 3.0000;
137y[127] = 8.1700; t[127] = 4.0000;
138y[128] = 8.5500; t[128] = 5.0000;
139y[129] = 10.1200; t[129] = 6.0000;
140y[130] = 78.0000; t[130] = .5000;
141y[131] = 66.0000; t[131] = .6250;
142y[132] = 62.0000; t[132] = .7500;
143y[133] = 58.0000; t[133] = .8750;
144y[134] = 47.7000; t[134] = 1.0000;
145y[135] = 37.8000; t[135] = 1.2500;
146y[136] = 20.2000; t[136] = 2.2500;
147y[137] = 21.0700; t[137] = 2.2500;
148y[138] = 13.8700; t[138] = 2.7500;
149y[139] = 9.6700; t[139] = 3.2500;
150y[140] = 7.7600; t[140] = 3.7500;
151y[141] = 5.4400; t[141] = 4.2500;
152y[142] = 4.8700; t[142] = 4.7500;
153y[143] = 4.0100; t[143] = 5.2500;
154y[144] = 3.7500; t[144] = 5.7500;
155y[145] = 24.1900; t[145] = 3.0000;
156y[146] = 25.7600; t[146] = 3.0000;
157y[147] = 18.0700; t[147] = 3.0000;
158y[148] = 11.8100; t[148] = 3.0000;
159y[149] = 12.0700; t[149] = 3.0000;
160y[150] = 16.1200; t[150] = 3.0000;
161y[151] = 70.8000; t[151] = .5000;
162y[152] = 54.7000; t[152] = .7500;
163y[153] = 48.0000; t[153] = 1.0000;
164y[154] = 39.8000; t[154] = 1.5000;
165y[155] = 29.8000; t[155] = 2.0000;
166y[156] = 23.7000; t[156] = 2.5000;
167y[157] = 29.6200; t[157] = 2.0000;
168y[158] = 23.8100; t[158] = 2.5000;
169y[159] = 17.7000; t[159] = 3.0000;
170y[160] = 11.5500; t[160] = 4.0000;
171y[161] = 12.0700; t[161] = 5.0000;
172y[162] = 8.7400; t[162] = 6.0000;
173y[163] = 80.7000; t[163] = .5000;
174y[164] = 61.3000; t[164] = .7500;
175y[165] = 47.5000; t[165] = 1.0000;
176y[166] = 29.0000; t[166] = 1.5000;
177y[167] = 24.0000; t[167] = 2.0000;
178y[168] = 17.7000; t[168] = 2.5000;
179y[169] = 24.5600; t[169] = 2.0000;
180y[170] = 18.6700; t[170] = 2.5000;
181y[171] = 16.2400; t[171] = 3.0000;
182y[172] = 8.7400; t[172] = 4.0000;
183y[173] = 7.8700; t[173] = 5.0000;
184y[174] = 8.5100; t[174] = 6.0000;
185y[175] = 66.7000; t[175] = .5000;
186y[176] = 59.2000; t[176] = .7500;
187y[177] = 40.8000; t[177] = 1.0000;
188y[178] = 30.7000; t[178] = 1.5000;
189y[179] = 25.7000; t[179] = 2.0000;
190y[180] = 16.3000; t[180] = 2.5000;
191y[181] = 25.9900; t[181] = 2.0000;
192y[182] = 16.9500; t[182] = 2.5000;
193y[183] = 13.3500; t[183] = 3.0000;
194y[184] = 8.6200; t[184] = 4.0000;
195y[185] = 7.2000; t[185] = 5.0000;
196y[186] = 6.6400; t[186] = 6.0000;
197y[187] = 13.6900; t[187] = 3.0000;
198y[188] = 81.0000; t[188] = .5000;
199y[189] = 64.5000; t[189] = .7500;
200y[190] = 35.5000; t[190] = 1.5000;
201y[191] = 13.3100; t[191] = 3.0000;
202y[192] = 4.8700; t[192] = 6.0000;
203y[193] = 12.9400; t[193] = 3.0000;
204y[194] = 5.0600; t[194] = 6.0000;
205y[195] = 15.1900; t[195] = 3.0000;
206y[196] = 14.6200; t[196] = 3.0000;
207y[197] = 15.6400; t[197] = 3.0000;
208y[198] = 25.5000; t[198] = 1.7500;
209y[199] = 25.9500; t[199] = 1.7500;
210y[200] = 81.7000; t[200] = .5000;
211y[201] = 61.6000; t[201] = .7500;
212y[202] = 29.8000; t[202] = 1.7500;
213y[203] = 29.8100; t[203] = 1.7500;
214y[204] = 17.1700; t[204] = 2.7500;
215y[205] = 10.3900; t[205] = 3.7500;
216y[206] = 28.4000; t[206] = 1.7500;
217y[207] = 28.6900; t[207] = 1.7500;
218y[208] = 81.3000; t[208] = .5000;
219y[209] = 60.9000; t[209] = .7500;
220y[210] = 16.6500; t[210] = 2.7500;
221y[211] = 10.0500; t[211] = 3.7500;
222y[212] = 28.9000; t[212] = 1.7500;
223y[213] = 28.9500; t[213] = 1.7500;
224# fmt: on
225
226
227def func_def(x, i):
228 return y[i] - np.exp(-x[0] * t[i]) / (x[1] + x[2] * t[i])
229
230
231def EvaluateFunction(x, component=np.nan):
232 """
233 Evaluates the chwirut function
234 """
235 if np.isnan(component):
236 f = np.zeros(NOBSERVATIONS)
237 for i in range(NOBSERVATIONS):
238 f[i] = func_def(x, i)
239 else:
240 f = func_def(x, component)
241
242 return f
243
244
245def EvaluateJacobian(x):
246 """
247 Evaluates the chwirut Jacobian
248 """
249 j = np.zeros((NOBSERVATIONS, 3))
250
251 for i in range(NOBSERVATIONS):
252 base = np.exp(-x[0] * t[i]) / (x[1] + x[2] * t[i])
253
254 j[i][0] = t[i] * base
255 j[i][1] = base / (x[1] + x[2] * t[i])
256 j[i][2] = base * t[i] / (x[1] + x[2] * t[i])
257
258 return j
259
260
261def chwirut_eval(H, _, sim_specs):
262 """
263 Evaluates the chwirut objective function at a given set of points in
264 ``H["x"]``. If ``"obj_component"`` is a field in ``sim_specs["out"]``, only that
265 component of the objective will be evaluated. Otherwise, all 214 components
266 are evaluated and returned in the ``"fvec"`` field.
267
268 .. seealso::
269 `test_persistent_aposmm_pounders.py <https://github.com/Libensemble/libensemble/blob/develop/libensemble/tests/regression_tests/test_persistent_aposmm_pounders.py>`_ # noqa
270 for an example where the entire fvec is computed each call.
271
272 .. seealso::
273 `test_uniform_sampling_one_residual_at_a_time.py <https://github.com/Libensemble/libensemble/blob/develop/libensemble/tests/functionality_tests/test_uniform_sampling_one_residual_at_a_time.py>`_ # noqa
274 for an example where one component of fvec is computed per call
275 """
276
277 batch = len(H["x"])
278 O = np.zeros(batch, dtype=sim_specs["out"])
279
280 for i, x in enumerate(H["x"]):
281 if "obj_component" in H.dtype.names:
282 if (
283 "user" in sim_specs
284 and "component_nan_frequency" in sim_specs["user"]
285 and np.random.uniform(0, 1) < sim_specs["user"]["component_nan_frequency"]
286 ):
287 O["f_i"][i] = np.nan
288 else:
289 O["f_i"][i] = EvaluateFunction(x, H["obj_component"][i])
290
291 else:
292 O["fvec"][i] = EvaluateFunction(x)
293 if "combine_component_func" in sim_specs["user"]:
294 O["f"][i] = sim_specs["user"]["combine_component_func"](O["fvec"][i])
295 else:
296 O["f"][i] = np.sum(O["fvec"][i] ** 2)
297
298 return O
299
300
301# if __name__ == "__main__":
302# x = np.zeros(3)
303# x[0] = 0.15;
304# x[1] = 0.008;
305# x[2] = 0.010;
306
307# f = EvaluateFunction(x)
308# J = EvaluateJacobian(x)
309
310# print(f, J)