@@ -64,6 +64,63 @@ def create_rank_dictionary_compact(int_array: list[int]) -> dict[int, int]:
6464 return {original_index : rank for rank , original_index in enumerate (sorted_indices )}
6565
6666
67+ def choose_weights (** importance : float ) -> list [float ]:
68+ """Choose normalized weights from relative importance values.
69+
70+ Example:
71+ choose_weights(runtime=3, diff=1)
72+ -> [0.75, 0.25]
73+
74+ Args:
75+ **importance: keyword args of metric=importance (relative numbers).
76+
77+ Returns:
78+ A list of weights in the same order as the arguments.
79+
80+ """
81+ total = sum (importance .values ())
82+ if total == 0 :
83+ raise ValueError ("At least one importance value must be > 0" )
84+
85+ return [v / total for v in importance .values ()]
86+
87+
88+ def normalize (values : list [float ]) -> list [float ]:
89+ mn , mx = min (values ), max (values )
90+ if mx == mn :
91+ return [0.0 ] * len (values )
92+ return [(v - mn ) / (mx - mn ) for v in values ]
93+
94+
95+ def create_score_dictionary_from_metrics (weights : list [float ], * metrics : list [float ]) -> dict [int , int ]:
96+ """Combine multiple metrics into a single weighted score dictionary.
97+
98+ Each metric is a list of values (smaller = better).
99+ The total score for each index is the weighted sum of its values
100+ across all metrics:
101+
102+ score[index] = Σ (value * weight)
103+
104+ Args:
105+ weights: A list of weights, one per metric. Larger weight = more influence.
106+ *metrics: Lists of values (one list per metric, aligned by index).
107+
108+ Returns:
109+ A dictionary mapping each index to its combined weighted score.
110+
111+ """
112+ if len (weights ) != len (metrics ):
113+ raise ValueError ("Number of weights must match number of metrics" )
114+
115+ combined : dict [int , float ] = {}
116+
117+ for weight , metric in zip (weights , metrics ):
118+ for idx , value in enumerate (metric ):
119+ combined [idx ] = combined .get (idx , 0 ) + value * weight
120+
121+ return combined
122+
123+
67124@contextmanager
68125def custom_addopts () -> None :
69126 pyproject_file = find_pyproject_toml ()
0 commit comments