@@ -92,12 +92,12 @@ def able_to_do_restart(self):
92
92
93
93
94
94
class Controller (object ):
95
- def __init__ (self , objfun , x0 , args , f0 , f0_nsamples , xl , xu , npt , rhobeg , rhoend , nf , nx , maxfun , params , scaling_changes ):
95
+ def __init__ (self , objfun , x0 , args , f0 , f0_nsamples , xl , xu , npt , rhobeg , rhoend , nf , nx , maxfun , params , scaling_changes , do_logging = True ):
96
96
self .objfun = objfun
97
97
self .maxfun = maxfun
98
98
self .args = args
99
99
self .model = Model (npt , x0 , f0 , xl , xu , f0_nsamples , abs_tol = params ("model.abs_tol" ),
100
- precondition = params ("interpolation.precondition" ))
100
+ precondition = params ("interpolation.precondition" ), do_logging = do_logging )
101
101
self .nf = nf
102
102
self .nx = nx
103
103
self .rhobeg = rhobeg
@@ -121,6 +121,7 @@ def __init__(self, objfun, x0, args, f0, f0_nsamples, xl, xu, npt, rhobeg, rhoen
121
121
self .total_unsuccessful_restarts = 0
122
122
self .last_run_fopt = f0
123
123
self .scaling_changes = scaling_changes
124
+ self .do_logging = do_logging
124
125
125
126
def n (self ):
126
127
return self .model .n ()
@@ -129,7 +130,8 @@ def npt(self):
129
130
return self .model .npt ()
130
131
131
132
def initialise_coordinate_directions (self , number_of_samples , num_directions , params ):
132
- logging .debug ("Initialising with coordinate directions" )
133
+ if self .do_logging :
134
+ logging .debug ("Initialising with coordinate directions" )
133
135
# self.model already has x0 evaluated, so only need to initialise the other points
134
136
# num_directions = params("growing.ndirs_initial")
135
137
assert self .model .num_pts <= (self .n () + 1 ) * (self .n () + 2 ) // 2 , "prelim: must have npt <= (n+1)(n+2)/2"
@@ -202,7 +204,8 @@ def initialise_coordinate_directions(self, number_of_samples, num_directions, pa
202
204
return None # return & continue
203
205
204
206
def initialise_random_directions (self , number_of_samples , num_directions , params ):
205
- logging .debug ("Initialising with random orthogonal directions" )
207
+ if self .do_logging :
208
+ logging .debug ("Initialising with random orthogonal directions" )
206
209
# self.model already has x0 evaluated, so only need to initialise the other points
207
210
# num_directions = params("growing.ndirs_initial")
208
211
assert 1 <= num_directions < self .model .num_pts , "Initialisation: must have 1 <= ndirs_initial < npt"
@@ -270,7 +273,8 @@ def trust_region_step(self):
270
273
return d , gopt , H , gnew , crvmin
271
274
272
275
def geometry_step (self , knew , adelt , number_of_samples , params ):
273
- logging .debug ("Running geometry-fixing step" )
276
+ if self .do_logging :
277
+ logging .debug ("Running geometry-fixing step" )
274
278
try :
275
279
c , g , H = self .model .lagrange_polynomial (knew ) # based at xopt
276
280
# Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
@@ -344,7 +348,8 @@ def evaluate_objective(self, x, number_of_samples, params):
344
348
incremented_nx = True
345
349
f_list [i ] = eval_objective (self .objfun , remove_scaling (x , self .scaling_changes ), self .args , eval_num = self .nf , pt_num = self .nx ,
346
350
full_x_thresh = params ("logging.n_to_print_whole_x_vector" ),
347
- check_for_overflow = params ("general.check_objfun_for_overflow" ))
351
+ check_for_overflow = params ("general.check_objfun_for_overflow" ),
352
+ verbose = self .do_logging )
348
353
num_samples_run += 1
349
354
350
355
# Check if the average value was below our threshold
@@ -453,11 +458,13 @@ def terminate_from_slow_iterations(self, current_iter, params):
453
458
# Update counter of number of slow iterations
454
459
if this_iter_slow :
455
460
self .num_slow_iters += 1
456
- logging .info ("Slow iteration (%g consecutive so far, max allowed %g)"
461
+ if self .do_logging :
462
+ logging .info ("Slow iteration (%g consecutive so far, max allowed %g)"
457
463
% (self .num_slow_iters , params ("slow.max_slow_iters" )))
458
464
else :
459
465
self .num_slow_iters = 0
460
- logging .debug ("Non-slow iteration" )
466
+ if self .do_logging :
467
+ logging .debug ("Non-slow iteration" )
461
468
return this_iter_slow , self .num_slow_iters >= params ("slow.max_slow_iters" )
462
469
463
470
def soft_restart (self , number_of_samples , nruns_so_far , params , x_in_abs_coords_to_save = None , f_to_save = None ,
@@ -491,7 +498,8 @@ def soft_restart(self, number_of_samples, nruns_so_far, params, x_in_abs_coords_
491
498
self .model .save_point (self .model .xopt (abs_coordinates = True ), self .model .fopt (),
492
499
self .model .nsamples [self .model .kopt ], x_in_abs_coords = True )
493
500
494
- logging .info ("Soft restart [currently, f = %g after %g function evals]" % (self .model .fopt (), self .nf ))
501
+ if self .do_logging :
502
+ logging .info ("Soft restart [currently, f = %g after %g function evals]" % (self .model .fopt (), self .nf ))
495
503
# Resetting method: reset delta and rho, then move the closest 'num_steps' points to xk to improve geometry
496
504
# Note: closest points because we are suddenly increasing delta & rho, so we want to encourage spreading out points
497
505
self .delta = self .rhobeg
0 commit comments