2828import logging
2929import time
3030from spotPython .utils .progress import progress_bar
31- from spotPython .utils .convert import find_indices
31+ from spotPython .utils .convert import find_indices , sort_by_kth_and_return_indices
3232from spotPython .hyperparameters .values import (
3333 get_control_key_value ,
3434 get_ith_hyperparameter_name_from_fun_control ,
@@ -1640,7 +1640,7 @@ def plot_contour(
16401640 pylab .show ()
16411641
16421642 def plot_important_hyperparameter_contour (
1643- self , threshold = 0.0 , filename = None , show = True , max_imp = None , title = ""
1643+ self , threshold = 0.0 , filename = None , show = True , max_imp = None , title = "" , scale_global = False
16441644 ) -> None :
16451645 """
16461646 Plot the contour of important hyperparameters.
@@ -1649,7 +1649,7 @@ def plot_important_hyperparameter_contour(
16491649
16501650 Args:
16511651 threshold (float):
1652- threshold for the importance
1652+ threshold for the importance. Not used any more in spotPython >= 0.13.2.
16531653 filename (str):
16541654 filename of the plot
16551655 show (bool):
@@ -1691,23 +1691,22 @@ def plot_important_hyperparameter_contour(
16911691 S.plot_important_hyperparameter_contour()
16921692
16931693 """
1694- impo_org = self .print_importance (threshold = threshold , print_screen = True )
1695- print (f"impo: { impo_org } " )
1696- try :
1697- impo = sorted (impo_org , key = lambda x : x [1 ], reverse = True )
1698- except ValueError as e :
1699- print (f"ValueError: { e } " )
1700- impo = impo_org
1701- # if there are more than imp_max variables, select only the most important ones:
1694+ impo = self .print_importance (threshold = threshold , print_screen = True )
1695+ print (f"impo: { impo } " )
1696+ indices = sort_by_kth_and_return_indices (array = impo , k = 1 )
1697+ print (f"indices: { indices } " )
1698+ # take the first max_imp values from the indices array
17021699 if max_imp is not None :
1703- if len (impo ) > max_imp :
1704- impo = impo [:max_imp ]
1705- print (f"impo after select: { impo } " )
1706- var_plots = [i for i , x in enumerate (impo ) if x [1 ] > threshold ]
1707- min_z = min (self .y )
1708- max_z = max (self .y )
1709- for i in var_plots :
1710- for j in var_plots :
1700+ indices = indices [:max_imp ]
1701+ print (f"indices after max_imp selection: { indices } " )
1702+ if scale_global :
1703+ min_z = min (self .y )
1704+ max_z = max (self .y )
1705+ else :
1706+ min_z = None
1707+ max_z = None
1708+ for i in indices :
1709+ for j in indices :
17111710 if j > i :
17121711 if filename is not None :
17131712 filename_full = filename + "_contour_" + str (i ) + "_" + str (j ) + ".png"
0 commit comments