new version of optimization demo with the restart option
@@ -37,7 +37,7 @@ search_space = {
"eta": Real(low=0.001, high=5.0)
}
-# Initialize optimizer
+#%% Initialize optimizer
optimizer = Optimizer(
model,
dataset,
@@ -47,9 +47,8 @@ optimizer = Optimizer(
plot_best_seen=True,
save_path="results/simple_RF/",
save_name="resultsBO",
- save_csv=True,
save_models=False,
- number_of_call=10,
+ number_of_call=5,
n_random_starts=3,
optimization_type='Maximize',
model_runs=5,
@@ -62,34 +61,27 @@ BestObject = optimizer.optimize()
end_time = time.time()
total_time = end_time - start_time # Total time to optimize
-#The results of the optimization are saved in the object BestObject
-
-#To start a new optimization from the previous results we need to include x0 and y0 in the object optimizer...
-
+#%%Restart
+PreviousResult=BestObject.load("results/simple_RF/resultsBO.json")
-# import pandas as pd
-
-# optimizer = Optimizer(
-# model,
-# dataset,
-# npmi,
-# search_space,
-# plot_model=True,
-# plot_best_seen=True,
-# save_path="results/simple_RF/",
-# save_name="resultsBO",
-# save_csv=True,
-# save_models=True,
-# number_of_call=10,
-# n_random_starts=3,
-# optimization_type='Maximize',
-# model_runs=3,
-# surrogate_model="RF",
-# x0=pd.DataFrame(BestObject.x_iters_as_dict).values.tolist(), #!!!!!
-# y0=BestObject.func_vals)
+# Initialize optimizer
+optimizer = Optimizer(
+ model,
+ dataset,
+ npmi,
+ search_space,
+ plot_model=True,
+ plot_best_seen=True,
+ save_path="results/simple_RF/",
+ save_name="resultsBO2",
+ save_models=False,
+ number_of_call=5,
+ optimization_type='Maximize',
+ model_runs=5,
+ surrogate_model="GP")
-# # #..and launch again the optimize
-# start_time = time.time()
-# BestObject = optimizer.optimize()
-# end_time = time.time()
+# # #..and launch again the optimization
+start_time = time.time()
+BestObject2 = optimizer.restart_optimize(PreviousResult.copy())
+end_time = time.time()
total_time = end_time - start_time # Total time to optimize
\ No newline at end of file
