@@ -1290,6 +1290,46 @@ def print_results(self, print_screen=True, dict=None) -> list[str]:
12901290 print_screen (bool, optional):
12911291 print results to screen
12921292
1293+ Returns:
1294+ output (list):
1295+ list of results
1296+ """
1297+ output = []
1298+ if print_screen :
1299+ print (f"min y: { self .min_y } " )
1300+ if self .noise :
1301+ print (f"min mean y: { self .min_mean_y } " )
1302+ if self .noise :
1303+ res = self .to_all_dim (self .min_mean_X .reshape (1 , - 1 ))
1304+ else :
1305+ res = self .to_all_dim (self .min_X .reshape (1 , - 1 ))
1306+ for i in range (res .shape [1 ]):
1307+ if self .all_var_name is None :
1308+ var_name = "x" + str (i )
1309+ else :
1310+ var_name = self .all_var_name [i ]
1311+ var_type = self .all_var_type [i ]
1312+ if var_type == "factor" and dict is not None :
1313+ val = get_ith_hyperparameter_name_from_fun_control (fun_control = dict , key = var_name , i = int (res [0 ][i ]))
1314+ else :
1315+ val = res [0 ][i ]
1316+ if print_screen :
1317+ print (var_name + ":" , val )
1318+ output .append ([var_name , val ])
1319+ return output
1320+
1321+ def print_results_old (self , print_screen = True , dict = None ) -> list [str ]:
1322+ """Print results from the run:
1323+ 1. min y
1324+ 2. min X
1325+ If `noise == True`, additionally the following values are printed:
1326+ 3. min mean y
1327+ 4. min mean X
1328+
1329+ Args:
1330+ print_screen (bool, optional):
1331+ print results to screen
1332+
12931333 Returns:
12941334 output (list):
12951335 list of results
@@ -1483,7 +1523,17 @@ def chg(self, x, y, z0, i, j) -> list:
14831523 return z0
14841524
14851525 def plot_contour (
1486- self , i = 0 , j = 1 , min_z = None , max_z = None , show = True , filename = None , n_grid = 25 , contour_levels = 10 , dpi = 200
1526+ self ,
1527+ i = 0 ,
1528+ j = 1 ,
1529+ min_z = None ,
1530+ max_z = None ,
1531+ show = True ,
1532+ filename = None ,
1533+ n_grid = 25 ,
1534+ contour_levels = 10 ,
1535+ dpi = 200 ,
1536+ title = "" ,
14871537 ) -> None :
14881538 """Plot the contour of any dimension.
14891539
@@ -1506,6 +1556,8 @@ def plot_contour(
15061556 number of contour levels
15071557 dpi (int):
15081558 dpi of the plot. Default is 200.
1559+ title (str):
1560+ title of the plot
15091561
15101562 Returns:
15111563 None
@@ -1561,7 +1613,7 @@ def plot_contour(
15611613 else :
15621614 plt .xlabel ("x" + str (i ) + ": " + self .var_name [i ])
15631615 plt .ylabel ("x" + str (j ) + ": " + self .var_name [j ])
1564- plt .title ("Surrogate" )
1616+ # plt.title("Surrogate")
15651617 pylab .colorbar ()
15661618 ax = fig .add_subplot (222 , projection = "3d" )
15671619 ax .plot_surface (X , Y , Z , rstride = 3 , cstride = 3 , alpha = 0.9 , cmap = "jet" , vmin = min_z , vmax = max_z )
@@ -1571,12 +1623,15 @@ def plot_contour(
15711623 else :
15721624 plt .xlabel ("x" + str (i ) + ": " + self .var_name [i ])
15731625 plt .ylabel ("x" + str (j ) + ": " + self .var_name [j ])
1626+ plt .title (title )
15741627 if filename :
15751628 pylab .savefig (filename , bbox_inches = "tight" , dpi = dpi , pad_inches = 0 ),
15761629 if show :
15771630 pylab .show ()
15781631
1579- def plot_important_hyperparameter_contour (self , threshold = 0.025 , filename = None , show = True , max_imp = None ) -> None :
1632+ def plot_important_hyperparameter_contour (
1633+ self , threshold = 0.025 , filename = None , show = True , max_imp = None , title = ""
1634+ ) -> None :
15801635 """
15811636 Plot the contour of important hyperparameters.
15821637 Calls `plot_contour` for each pair of important hyperparameters.
@@ -1592,6 +1647,8 @@ def plot_important_hyperparameter_contour(self, threshold=0.025, filename=None,
15921647 max_imp (int):
15931648 maximum number of important hyperparameters. If there are more important hyperparameters
15941649 than `max_imp`, only the max_imp important ones are selected.
1650+ title (str):
1651+ title of the plots
15951652
15961653 Returns:
15971654 None.
@@ -1625,12 +1682,12 @@ def plot_important_hyperparameter_contour(self, threshold=0.025, filename=None,
16251682
16261683 """
16271684 impo = self .print_importance (threshold = threshold , print_screen = True )
1628- print (f"impo: { impo } " )
1685+ # print(f"impo: {impo}")
16291686 # if there are more than imp_max variables, select only the most important ones:
16301687 if max_imp is not None :
16311688 if len (impo ) > max_imp :
16321689 impo = impo [:max_imp ]
1633- print (f"impo after select: { impo } " )
1690+ # print(f"impo after select: {impo}")
16341691 var_plots = [i for i , x in enumerate (impo ) if x [1 ] > threshold ]
16351692 min_z = min (self .y )
16361693 max_z = max (self .y )
@@ -1641,7 +1698,9 @@ def plot_important_hyperparameter_contour(self, threshold=0.025, filename=None,
16411698 filename_full = filename + "_contour_" + str (i ) + "_" + str (j ) + ".png"
16421699 else :
16431700 filename_full = None
1644- self .plot_contour (i = i , j = j , min_z = min_z , max_z = max_z , filename = filename_full , show = show )
1701+ self .plot_contour (
1702+ i = i , j = j , min_z = min_z , max_z = max_z , filename = filename_full , show = show , title = title
1703+ )
16451704
16461705 def get_importance (self ) -> list :
16471706 """Get importance of each variable and return the results as a list.
0 commit comments