Skip to content

Commit f60de6b

Browse files
Update simple_cerebros_random_search.py
Duplicate vetted bug fix (keras metrics returning "inf" or other non-float types) from #234 , #230 without other non-vetted changes.
1 parent 1ff1e75 commit f60de6b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

cerebros/simplecerebrosrandomsearch/simple_cerebros_random_search.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,29 @@ def run_random_search(self):
565565
print(f"metric_to_rank_by is: '{self.metric_to_rank_by}'")
566566
print(
567567
f"Type of metric_to_rank_by is: {str(type(self.metric_to_rank_by))}")
568+
def has_valid_metric(num):
569+
try:
570+
float(num)
571+
return True
572+
except Exception as exc:
573+
print(exc)
574+
return False
575+
rows_having_a_valid_metric = oracles[self.metric_to_rank_by].apply(lambda x: has_valid_metric(x))
576+
oracles_having_valid_metrics = oracles[rows_having_a_valid_metric]
577+
568578
if self.direction == "maximize" or self.direction == "max":
569-
570-
best = float(oracles[oracles[self.metric_to_rank_by]
571-
!= self.metric_to_rank_by]
572-
[self.metric_to_rank_by].astype(float).max())
579+
best = float(oracles_having_valid_metrics[self.metric_to_rank_by].astype(float).max())
580+
# best = float(oracles[oracles[self.metric_to_rank_by]
581+
# != self.metric_to_rank_by]
582+
# [self.metric_to_rank_by].astype(float).max())
573583
else:
574584
print(f"metric_to_rank_by is: '{self.metric_to_rank_by}'")
575585
print(
576586
f"Type of metric_to_rank_by is: {str(type(self.metric_to_rank_by))}")
577-
best = float(oracles[oracles[self.metric_to_rank_by]
578-
!= self.metric_to_rank_by]
579-
[self.metric_to_rank_by].astype(float).min())
587+
best = float(oracles_having_valid_metrics[self.metric_to_rank_by].astype(float).min())
588+
# best = float(oracles[oracles[self.metric_to_rank_by]
589+
# != self.metric_to_rank_by]
590+
# [self.metric_to_rank_by].astype(float).min())
580591
print(f"Best result this trial was: {best}")
581592
print(f"Type of best result: {type(best)}")
582593
self.best_model_path =\

0 commit comments

Comments
 (0)