Skip to content

Commit bc735a3

Browse files
normalize by max
1 parent ac2a3a1 commit bc735a3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def choose_weights(**importance: float) -> list[float]:
6262
return [v / total for v in importance.values()]
6363

6464

65-
def normalize(values: list[float]) -> list[float]:
66-
mn, mx = min(values), max(values)
67-
if mx == mn:
65+
def normalize_by_max(values: list[float]) -> list[float]:
66+
mx = max(values)
67+
if mx == 0:
6868
return [0.0] * len(values)
69-
return [(v - mn) / (mx - mn) for v in values]
69+
return [v / mx for v in values]
7070

7171

7272
def create_score_dictionary_from_metrics(weights: list[float], *metrics: list[float]) -> dict[int, int]:

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
file_name_from_test_module_name,
3939
get_run_tmp_file,
4040
module_name_from_file_path,
41-
normalize,
41+
normalize_by_max,
4242
restore_conftest,
4343
unified_diff_strings,
4444
)
@@ -198,8 +198,8 @@ def _process_refinement_results(self) -> OptimizedCandidate | None:
198198
runtime_w, diff_w = REFINED_CANDIDATE_RANKING_WEIGHTS
199199
weights = choose_weights(runtime=runtime_w, diff=diff_w)
200200

201-
runtime_norm = normalize(runtimes_list)
202-
diffs_norm = normalize(diff_lens_list)
201+
runtime_norm = normalize_by_max(runtimes_list)
202+
diffs_norm = normalize_by_max(diff_lens_list)
203203
# the lower the better
204204
score_dict = create_score_dictionary_from_metrics(weights, runtime_norm, diffs_norm)
205205
top_n_candidates = int((TOP_N_REFINEMENTS * len(runtimes_list)) + 0.5)

0 commit comments

Comments
 (0)