@@ -722,6 +722,8 @@ def create_bo_model(data):
722722 lower_bounds = [2.5 ] * 9 # Nine parameters for gamma
723723 upper_bounds = [6.0 ] * 9
724724 search_space = Box (lower_bounds , upper_bounds )
725+ init_space = Box ([4.0 ] * 9 , [5.0 ] * 9 ) # Initial space for sampling
726+ # a harder and higher dimensional problem, try to make sure the initial points are mostly feasible.
725727
726728 # Import required libraries for additional optimization methods
727729 from scipy .optimize import dual_annealing , differential_evolution
@@ -742,7 +744,7 @@ def combined_objective(params):
742744 res = evaluate_cf_point (params_array )
743745 # If the constraint is violated, return a large penalty
744746 if res ['constraint' ] > Sim_cf .threshold :
745- return 1e6 * (res ['constraint' ] - Sim_cf .threshold ) # if all initial samples have the same value some methods will error out.
747+ return 1e10 # *(res['constraint'] - Sim_cf.threshold) # if all initial samples have the same value some methods will error out.
746748 return float (res ['objective' ])
747749
748750 '''
@@ -761,13 +763,14 @@ def combined_objective(params):
761763
762764 # Generate common initial points for all methods
763765 num_initial_points = 5 #25 # Number of initial points
764- num_steps = 5 #25
766+ num_steps = 25 #25
765767 initial_seed = 42 # Use fixed seed for reproducibility
766768 tf .random .set_seed (initial_seed )
767769 np .random .seed (initial_seed )
768770
769771 # Generate initial points that all methods will use
770- initial_points = search_space .sample (num_initial_points )
772+ #initial_points = search_space.sample(num_initial_points)
773+ initial_points = init_space .sample (num_initial_points )
771774 initial_points_np = initial_points .numpy ()
772775
773776 # 1. Bayesian Optimization with Unknown Constraints (BOUC) using Trieste
@@ -840,6 +843,7 @@ def combined_objective(params):
840843
841844 print ("BOUC function calls:" , bouc_fcalls_arr )
842845 print ("BOUC combined costs:" , bouc_combined_costs )
846+ print ("BOUC best cost:" , results ["BOUC" ]["best_cost" ])
843847
844848 # 2. Vanilla Bayesian Optimization using Trieste
845849 print ("\n Running vanilla BO optimization..." )
@@ -928,8 +932,8 @@ def da_callback(x, f, context):
928932 return False
929933
930934 # Run optimization
931- da_max_calls = num_steps * 2
932- da_max_iter = num_steps // 5
935+ da_max_calls = int ( num_steps * 1.2 )
936+ da_max_iter = num_steps // 7
933937
934938 da_start_time = time .time ()
935939 res_da = dual_annealing (combined_objective , bounds = bounds_da ,
@@ -982,11 +986,11 @@ def de_callback(x, convergence):
982986 return False
983987
984988 # Create initial population that includes our initial points
985- popsize = num_initial_points
989+ popsize = num_initial_points
986990 population = np .array (initial_points_np )
987991
988992 # Set maxiter to ensure comparable number of function evaluations
989- de_max_iter = 2 * max (1 , num_steps // (popsize * len (lower_bounds )))
993+ de_max_iter = 3 * max (1 , num_steps // (popsize * len (lower_bounds )))
990994 print (f"DE max iterations: { de_max_iter } , popsize: { popsize } , function evaluations: { (de_max_iter + 1 ) * popsize * (len (lower_bounds ) - 1 )} " )
991995
992996 de_start_time = time .time ()
@@ -1138,15 +1142,15 @@ def rolling_min(costs, feasible=None):
11381142 min_cost_all = min (results [method ]["best_cost_so_far" ])
11391143
11401144 # Set y-limits from slightly below best cost to twice the best cost
1141- plt .ylim (0.95 * min_cost_all , 2.0 * min_cost_all )
1145+ # plt.ylim(0.95 * min_cost_all, 2.0 * min_cost_all)
11421146
11431147 for method , data in results .items ():
11441148 if data ["fcalls" ] and data ["best_cost_so_far" ]:
11451149 plt .plot (data ["fcalls" ], data ["best_cost_so_far" ], 'o-' , label = labels [method ], markersize = 8 )
11461150
11471151 plt .xlabel ('Function Evaluations' , fontsize = 14 )
11481152 plt .ylabel ('Best Cost Found' , fontsize = 14 )
1149- plt .title ('Optimization Methods Comparison (Zoomed) - Gamma Scenario' , fontsize = 16 )
1153+ plt .title ('Optimization Methods Comparison - Gamma Scenario' , fontsize = 16 )
11501154 plt .grid (True , alpha = 0.3 )
11511155 plt .legend (fontsize = 'x-large' )
11521156 plt .tight_layout ()
0 commit comments