@@ -51,6 +51,7 @@ def runTest(self):
51
51
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x0 ), 'Wrong xopt after initialisation' )
52
52
self .assertTrue (array_compare (model .ropt (), rosenbrock (x0 )), 'Wrong ropt after initialisation' )
53
53
self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x0 )), 'Wrong fopt after initialisation' )
54
+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,0 ,0 ], dtype = int )), 'Wrong eval_num after initialisation' )
54
55
# Now add better point
55
56
x1 = np .array ([1.0 , 0.9 ])
56
57
rvec = rosenbrock (x1 )
@@ -59,6 +60,7 @@ def runTest(self):
59
60
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after x1' )
60
61
self .assertTrue (array_compare (model .ropt (), rosenbrock (x1 )), 'Wrong ropt after x1' )
61
62
self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x1' )
63
+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,2 ,0 ], dtype = int )), 'Wrong eval_num after x1' )
62
64
# Now add worse point
63
65
x2 = np .array ([2.0 , 0.9 ])
64
66
rvec = rosenbrock (x2 )
@@ -70,6 +72,7 @@ def runTest(self):
70
72
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after x2' )
71
73
self .assertTrue (array_compare (model .ropt (), rosenbrock (x1 )), 'Wrong ropt after x2' )
72
74
self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x2' )
75
+ self .assertTrue (array_compare (model .eval_num , np .array ([1 ,2 ,3 ], dtype = int )), 'Wrong eval_num after x2' )
73
76
# Now add best point (but don't update kopt)
74
77
x3 = np .array ([1.0 , 1.0 ])
75
78
rvec = rosenbrock (x3 )
@@ -80,6 +83,7 @@ def runTest(self):
80
83
self .assertAlmostEqual (model .objopt (), sumsq (rosenbrock (x1 )), 'Wrong fopt after x3' )
81
84
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), model .as_absolute_coordinates (model .xopt ())),
82
85
'Comparison wrong after x3' )
86
+ self .assertTrue (array_compare (model .eval_num , np .array ([4 ,2 ,3 ], dtype = int )), 'Wrong eval_num after x3' )
83
87
dirns = model .xpt_directions (include_kopt = True )
84
88
self .assertTrue (array_compare (x3 - x1 , dirns [0 , :]), 'Wrong dirn 0' )
85
89
self .assertTrue (array_compare (x1 - x1 , dirns [1 , :]), 'Wrong dirn 1' )
@@ -111,11 +115,13 @@ def runTest(self):
111
115
self .assertTrue (array_compare (model .xpt (1 , abs_coordinates = True ), x1 ), 'Wrong xpt(1) after swap 1' )
112
116
self .assertTrue (array_compare (model .xpt (2 , abs_coordinates = True ), x0 ), 'Wrong xpt(2) after swap 1' )
113
117
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after swap 1' )
118
+ self .assertTrue (array_compare (model .eval_num , np .array ([3 ,2 ,1 ], dtype = int )), 'Wrong eval_num after swap 1' )
114
119
model .swap_points (1 , 2 )
115
120
self .assertTrue (array_compare (model .xpt (0 , abs_coordinates = True ), x2 ), 'Wrong xpt(0) after swap 2' )
116
121
self .assertTrue (array_compare (model .xpt (1 , abs_coordinates = True ), x0 ), 'Wrong xpt(1) after swap 2' )
117
122
self .assertTrue (array_compare (model .xpt (2 , abs_coordinates = True ), x1 ), 'Wrong xpt(2) after swap 2' )
118
123
self .assertTrue (array_compare (model .xopt (abs_coordinates = True ), x1 ), 'Wrong xopt after swap 2' )
124
+ self .assertTrue (array_compare (model .eval_num , np .array ([3 ,1 ,2 ], dtype = int )), 'Wrong eval_num after swap 2' )
119
125
120
126
class TestBasicManipulation (unittest .TestCase ):
121
127
def runTest (self ):
@@ -170,31 +176,43 @@ def runTest(self):
170
176
self .assertIsNone (model .rsave , 'rsave not none after initialisation' )
171
177
self .assertIsNone (model .objsave , 'fsave not none after initialisation' )
172
178
self .assertIsNone (model .nsamples_save , 'nsamples_save not none after initialisation' )
179
+ self .assertIsNone (model .eval_num_save , 'eval_num_save not none after initialisation' )
180
+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after initialisation' )
173
181
model .save_point (x0 , rosenbrock (x0 ), 1 , 6 , x_in_abs_coords = True )
174
182
self .assertTrue (array_compare (model .xsave , x0 ), 'Wrong xsave after saving' )
175
183
self .assertTrue (array_compare (model .rsave , rosenbrock (x0 )), 'Wrong rsave after saving' )
176
184
self .assertAlmostEqual (model .objsave , sumsq (rosenbrock (x0 )), 'Wrong fsave after saving' )
177
185
self .assertEqual (model .nsamples_save , 1 , 'Wrong nsamples_save after saving' )
186
+ self .assertEqual (model .eval_num_save , 6 , 'Wrong eval_num_save after saving' )
187
+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving' )
178
188
x , rvec , f , jacmin , nsamples , x_eval_num , jacmin_eval_nums = model .get_final_results ()
179
189
self .assertTrue (array_compare (x , x1 ), 'Wrong final x after saving' )
180
190
self .assertTrue (array_compare (rvec , rosenbrock (x1 )), 'Wrong final rvec after saving' )
181
191
self .assertAlmostEqual (sumsq (rosenbrock (x1 )), f , 'Wrong final f after saving' )
182
192
self .assertEqual (1 , nsamples , 'Wrong final nsamples after saving' )
193
+ self .assertEqual (x_eval_num , 5 , 'Wrong final x_eval_num after saving' )
194
+ self .assertIsNone (jacmin_eval_nums , 'Final jacmin_eval_nums not none after saving' )
183
195
model .save_point (x2 - model .xbase , np .array ([0.0 , 0.0 ]), 2 , 7 , x_in_abs_coords = False )
184
196
self .assertTrue (array_compare (model .xsave , x2 ), 'Wrong xsave after saving 2' )
185
197
self .assertTrue (array_compare (model .rsave , np .array ([0.0 , 0.0 ])), 'Wrong rsave after saving 2' )
186
198
self .assertAlmostEqual (model .objsave , 0.0 , 'Wrong fsave after saving 2' )
187
199
self .assertEqual (model .nsamples_save , 2 , 'Wrong nsamples_save after saving 2' )
200
+ self .assertEqual (model .eval_num_save , 7 , 'Wrong eval_num_save after saving 2' )
201
+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving 2' )
188
202
x , rvec , f , jacmin , nsamples , x_eval_num , jacmin_eval_nums = model .get_final_results ()
189
203
self .assertTrue (array_compare (x , x2 ), 'Wrong final x after saving 2' )
190
204
self .assertTrue (array_compare (rvec , np .array ([0.0 , 0.0 ])), 'Wrong final rvec after saving 2' )
191
205
self .assertAlmostEqual (f , 0.0 , 'Wrong final f after saving 2' )
192
206
self .assertEqual (2 , nsamples , 'Wrong final nsamples after saving 2' )
207
+ self .assertEqual (x_eval_num , 7 , 'Wrong final x_eval_num after saving 2' )
208
+ self .assertIsNone (jacmin_eval_nums , 'Final jacmin_eval_nums not none after saving 2' )
193
209
model .save_point (x0 , rosenbrock (x0 ), 3 , 8 , x_in_abs_coords = True ) # try to re-save a worse value
194
210
self .assertTrue (array_compare (model .xsave , x2 ), 'Wrong xsave after saving 3' )
195
211
self .assertTrue (array_compare (model .rsave , np .array ([0.0 , 0.0 ])), 'Wrong rsave after saving 3' )
196
212
self .assertAlmostEqual (model .objsave , 0.0 , 'Wrong fsave after saving 3' )
197
213
self .assertEqual (model .nsamples_save , 2 , 'Wrong nsamples_save after saving 3' )
214
+ self .assertEqual (model .eval_num_save , 7 , 'Wrong eval_num_save after saving 2' )
215
+ self .assertIsNone (model .jacsave_eval_nums , 'jacsave_eval_nums not none after saving 2' )
198
216
199
217
200
218
class TestAveraging (unittest .TestCase ):
0 commit comments