@@ -326,6 +326,8 @@ def append_X_ocba(self, X_ocba, X0):
326326
327327 def run (self , X_start = None ):
328328 self .initialize_design (X_start )
329+ # New: self.update_stats() moved here:
330+ self .update_stats ()
329331 # (S-5) Calling the spotLoop Function
330332 # and
331333 # (S-9) Termination Criteria, Conditions:
@@ -365,8 +367,22 @@ def initialize_design(self, X_start=None):
365367 self .y = self .fun (X = X_all , fun_control = self .fun_control )
366368 # TODO: Error if only nan values are returned
367369 logger .debug ("New y value: %s" , self .y )
370+ #
371+ self .counter = self .y .size
372+ if self .spot_writer is not None :
373+ writer = self .spot_writer
374+ # range goes to init_size -1 because the last value is added by update_stats(),
375+ # which always adds the last value.
376+ for j in range (len (self .y ) - 1 ):
377+ X_j = self .X [j ].copy ()
378+ y_j = self .y [j ].copy ()
379+ config = {self .var_name [i ]: X_j [i ] for i in range (self .k )}
380+ writer .add_hparams (config , {"spot_y" : y_j })
381+ writer .flush ()
382+ #
368383 self .X , self .y = remove_nan (self .X , self .y )
369- self .update_stats ()
384+ # self.update_stats() moved to run()!
385+ # self.update_stats()
370386 # (S-4): Imputation:
371387 # Not implemented yet.
372388 # (S-11) Surrogate Fit:
@@ -422,13 +438,16 @@ def update_stats(self):
422438 y_min = self .min_y .copy ()
423439 y_last = self .last_y .copy ()
424440 X_min = self .min_X .copy ()
441+ # y_min: best y value so far
442+ # y_last: last y value, can he worse than y_min
425443 writer .add_scalars ("spot_y" , {"min" : y_min , "last" : y_last }, self .counter )
444+ # X_min: X value of the best y value so far
426445 writer .add_scalars ("spot_X" , {f"X_{ i } " : X_min [i ] for i in range (self .k )}, self .counter )
427446 # get last value of self.X and convert to dict. take the values from self.var_name as keys:
428447 X_last = self .X [- 1 ].copy ()
429448 config = {self .var_name [i ]: X_last [i ] for i in range (self .k )}
430- y_val = self . y [ - 1 ]. copy ()
431- writer .add_hparams (config , {"fun_torch: loss " : y_val })
449+ # hyperparameters X and value y of the last configuration:
450+ writer .add_hparams (config , {"spot_y " : y_last })
432451 writer .flush ()
433452 # Update aggregated x and y values (if noise):
434453 if self .noise :
@@ -440,11 +459,17 @@ def update_stats(self):
440459 self .min_mean_X = self .mean_X [argmin (self .mean_y )]
441460 if self .spot_writer is not None :
442461 writer = self .spot_writer
462+ # y_min_mean: best mean y value so far
443463 y_min_mean = self .min_mean_y .copy ()
464+ # X_min_mean: X value of the best mean y value so far
444465 X_min_mean = self .min_mean_X .copy ()
466+ # y_var: variance of the y values
445467 y_var = self .var_y .copy ()
446- writer .add_scalars ("spot_y_noise" , {"min_mean_y" : y_min_mean , "last" : y_last }, self .counter )
447468 writer .add_scalar ("spot_y_var" , y_var , self .counter )
469+ # y_min_mean: best mean y value so far (see above)
470+ # y_last: last y value, can he worse than y_min_mean
471+ writer .add_scalars ("spot_y_noise" , {"min_mean_y" : y_min_mean , "last" : y_last }, self .counter )
472+ # X_min_mean: X value of the best mean y value so far (see above)
448473 writer .add_scalars (
449474 "spot_X_noise" , {f"X_min_mean{ i } " : X_min_mean [i ] for i in range (self .k )}, self .counter
450475 )
@@ -574,10 +599,10 @@ def plot_progress(
574599 range (1 , n_init + 1 ),
575600 s_y [:n_init ],
576601 style [0 ],
577- range (1 , n_init + 1 ),
578- [s_c [:n_init ].min ()] * n_init ,
602+ range (1 , n_init + 2 ),
603+ [s_c [:n_init ].min ()] * ( n_init + 1 ) ,
579604 style [1 ],
580- range (n_init , len (s_c )),
605+ range (n_init + 1 , len (s_c ) + 1 ),
581606 s_c [n_init :],
582607 style [2 ],
583608 )
0 commit comments