Skip to content

Commit 810bfc3

Browse files
committed
final before initial submission
1 parent ebd44d9 commit 810bfc3

File tree

46 files changed

+25221
-20525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+25221
-20525
lines changed

baseline_controllers/gamma/optimize_parameters.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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("\nRunning 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()
81.9 KB
Loading
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
method,best_cost,optimization_time_sec,num_function_calls,param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8,param_9
2-
BOUC,99290.67299849597,34477.51378130913,50,3.6077411389789056,5.3807122663141955,3.442493276477518,5.7232907117410665,5.337139884533713,4.190866514161556,2.729240969602435,4.5890491048784785,2.7649846856003766
3-
BO,98377.50329707502,535.5013947486877,50,3.931620357112107,5.10573759247095,3.6278875241137896,4.84199169640375,4.3314561496114035,2.5151946820151045,4.246216602957377,2.6639378348946607,5.570273166335934
4-
DA,68970.11886400828,897.9846568107605,75,3.262722931802273,4.638648509979248,3.1899866349995136,5.378272503614426,4.7226347625255585,3.721466556424275,5.884222760796547,2.5597217231988907,5.8646092265844345
5-
DE,87445.70084261333,954.190426826477,100,3.2419585373433937,3.9608576461699503,3.395929034032598,5.83247917716061,3.1556220277169844,2.5558112183094126,2.8870635771375257,4.553924883217957,5.1252473575821496
2+
BOUC,104791.93504003703,320.93161702156067,30,3.3439470709496613,4.907406024606427,3.8277356191137515,4.837456152651078,4.112413454940194,3.7550806440028617,4.338703109663414,4.458628065967337,4.24917181869433
3+
BO,119382.23813566855,263.12797451019287,30,4.2625012853156115,5.4209690750371715,3.6110748786739846,5.101152909223343,4.432456661682204,3.6704665958157356,4.463743370250949,4.187103050937975,3.2958336045742427
4+
DA,129356.94544444678,216.78493905067444,35,4.225781738758087,5.694479823112488,4.269283793279291,4.629364438354969,3.772303983569145,4.897373799933121,3.7375309988856316,2.6554581969976425,4.075709910171536
5+
DE,136640.54275972047,108.53766369819641,25,4.113463270214174,5.648448322023452,4.190402200035405,4.512789276829983,5.086862392526488,4.533943370949488,2.728116294254682,4.366053824488603,4.915519192913303
18.7 KB
Loading

0 commit comments

Comments
 (0)