mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-19 03:24:46 +00:00
clean up
This commit is contained in:
parent
44883f7463
commit
2daaa4c637
@ -3690,4 +3690,3 @@ class AutoML(BaseEstimator):
|
||||
q += inv[i] / s
|
||||
if p < q:
|
||||
return estimator_list[i]
|
||||
|
||||
@ -111,12 +111,18 @@ class FLOW2(Searcher):
|
||||
self.lexico_objectives = lexico_objectives
|
||||
if self.lexico_objectives is not None:
|
||||
if "modes" not in self.lexico_objectives.keys():
|
||||
self.lexico_objectives["modes"] = ["min"]*len(self.lexico_objectives["metrics"])
|
||||
for t_metric, t_mode in zip(self.lexico_objectives["metrics"], self.lexico_objectives["modes"]):
|
||||
self.lexico_objectives["modes"] = ["min"] * len(
|
||||
self.lexico_objectives["metrics"]
|
||||
)
|
||||
for t_metric, t_mode in zip(
|
||||
self.lexico_objectives["metrics"], self.lexico_objectives["modes"]
|
||||
):
|
||||
if t_metric not in self.lexico_objectives["tolerances"].keys():
|
||||
self.lexico_objectives["tolerances"][t_metric] = 0
|
||||
if t_metric not in self.lexico_objectives["targets"].keys():
|
||||
self.lexico_objectives["targets"][t_metric] = -float("inf") if t_mode == "min" else float("inf")
|
||||
self.lexico_objectives["targets"][t_metric] = (
|
||||
-float("inf") if t_mode == "min" else float("inf")
|
||||
)
|
||||
self.resource_multiple_factor = (
|
||||
resource_multiple_factor or SAMPLE_MULTIPLY_FACTOR
|
||||
)
|
||||
@ -299,7 +305,7 @@ class FLOW2(Searcher):
|
||||
flow2.best_obj = {}
|
||||
for k, v in obj.items():
|
||||
flow2.best_obj[k] = (
|
||||
v * -1
|
||||
-v
|
||||
if self.lexico_objectives["modes"][
|
||||
self.lexico_objectives["metrics"].index(k)
|
||||
]
|
||||
@ -345,7 +351,9 @@ class FLOW2(Searcher):
|
||||
self._init_search()
|
||||
return True
|
||||
|
||||
def update_fbest(self,):
|
||||
def update_fbest(
|
||||
self,
|
||||
):
|
||||
obj_initial = self.lexico_objectives["metrics"][0]
|
||||
feasible_index = [*range(len(self._histories[obj_initial]))]
|
||||
for k_metric in self.lexico_objectives["metrics"]:
|
||||
@ -376,10 +384,32 @@ class FLOW2(Searcher):
|
||||
for k in self.lexico_objectives["metrics"]:
|
||||
self._histories[k].append(result[k])
|
||||
self.update_fbest()
|
||||
for k_metric, k_mode in zip(self.lexico_objectives["metrics"],self.lexico_objectives["modes"]):
|
||||
k_target = self.lexico_objectives["targets"][k_metric] if k_mode == "min" else -1*self.lexico_objectives["targets"][k_metric]
|
||||
if (result[k_metric] < max([self._f_best[k_metric] + self.lexico_objectives["tolerances"][k_metric], k_target])) and (
|
||||
self.best_obj[k_metric] < max([self._f_best[k_metric] + self.lexico_objectives["tolerances"][k_metric], k_target])
|
||||
for k_metric, k_mode in zip(
|
||||
self.lexico_objectives["metrics"], self.lexico_objectives["modes"]
|
||||
):
|
||||
k_target = (
|
||||
self.lexico_objectives["targets"][k_metric]
|
||||
if k_mode == "min"
|
||||
else -self.lexico_objectives["targets"][k_metric]
|
||||
)
|
||||
if (
|
||||
result[k_metric]
|
||||
< max(
|
||||
[
|
||||
self._f_best[k_metric]
|
||||
+ self.lexico_objectives["tolerances"][k_metric],
|
||||
k_target,
|
||||
]
|
||||
)
|
||||
) and (
|
||||
self.best_obj[k_metric]
|
||||
< max(
|
||||
[
|
||||
self._f_best[k_metric]
|
||||
+ self.lexico_objectives["tolerances"][k_metric],
|
||||
k_target,
|
||||
]
|
||||
)
|
||||
):
|
||||
continue
|
||||
elif result[k_metric] < self.best_obj[k_metric]:
|
||||
|
||||
@ -150,9 +150,7 @@ class SearchThread:
|
||||
self.obj_best1 = obj
|
||||
self.cost_best = self.cost_last
|
||||
self.best_result = result
|
||||
if (
|
||||
getattr(self._search_alg, "lexico_objectives", None) is None
|
||||
):
|
||||
if getattr(self._search_alg, "lexico_objectives", None) is None:
|
||||
# TODO: Improve this behavior. When lexico_objectives is provided to CFO,
|
||||
# related variables are not callable.
|
||||
self._update_speed()
|
||||
|
||||
@ -74,13 +74,19 @@ class ExperimentAnalysis(EA):
|
||||
histories[objective].append(
|
||||
results[keys[time_index]][objective]
|
||||
if mode == "min"
|
||||
else trials[keys[time_index]][objective] * -1
|
||||
else -trials[keys[time_index]][objective]
|
||||
)
|
||||
obj_initial = self.lexico_objectives["metrics"][0]
|
||||
feasible_index = [*range(len(histories[obj_initial]))]
|
||||
for k_metric, k_mode in zip(self.lexico_objectives["metrics"],self.lexico_objectives["modes"]):
|
||||
for k_metric, k_mode in zip(
|
||||
self.lexico_objectives["metrics"], self.lexico_objectives["modes"]
|
||||
):
|
||||
k_values = np.array(histories[k_metric])
|
||||
k_target = self.lexico_objectives["targets"][k_metric] * -1 if k_mode == "max" else self.lexico_objectives["targets"][k_metric]
|
||||
k_target = (
|
||||
-self.lexico_objectives["targets"][k_metric]
|
||||
if k_mode == "max"
|
||||
else self.lexico_objectives["targets"][k_metric]
|
||||
)
|
||||
f_best[k_metric] = np.min(k_values.take(feasible_index))
|
||||
feasible_index_prior = np.where(
|
||||
k_values
|
||||
@ -449,8 +455,11 @@ def run(
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
|
||||
from .searcher.blendsearch import BlendSearch, CFO
|
||||
if lexico_objectives != None:
|
||||
logger.warning("If lexico_objectives is not None, search_alg is forced to be CFO")
|
||||
|
||||
if lexico_objectives is not None:
|
||||
logger.warning(
|
||||
"If lexico_objectives is not None, search_alg is forced to be CFO"
|
||||
)
|
||||
search_alg = None
|
||||
if search_alg is None:
|
||||
flaml_scheduler_resource_attr = (
|
||||
@ -469,9 +478,12 @@ def run(
|
||||
if lexico_objectives is None:
|
||||
try:
|
||||
import optuna as _
|
||||
|
||||
SearchAlgorithm = BlendSearch
|
||||
logger.info(
|
||||
"Using search algorithm {}.".format(SearchAlgorithm.__class__.__name__)
|
||||
"Using search algorithm {}.".format(
|
||||
SearchAlgorithm.__class__.__name__
|
||||
)
|
||||
)
|
||||
except ImportError:
|
||||
SearchAlgorithm = CFO
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user