根据对应的边界对浮点数列表进行归一化。
参数
values : list[float] 要归一化的成本列表。 bounds : list[tuple[float, float]] | None, 可选, 默认为 None 边界元组列表。如果未传递边界,则返回输入值。
返回值
normalized_costs : list[float] 基于边界的归一化成本。如果未给出边界,则返回原始值。此外,如果最小和最大边界相同,则相应目标的价值设置为 1。
源代码位于 smac/utils/multi_objective.py
中
| def normalize_costs(
values: list[float],
bounds: list[tuple[float, float]] | None = None,
) -> list[float]:
"""
Normalizes a list of floats with corresponding bounds.
Parameters
----------
values : list[float]
List of costs to be normalized.
bounds : list[tuple[float, float]] | None, optional, defaults to None
List of tuple of bounds. If no bounds are passed, the input is returned.
Returns
-------
normalized_costs : list[float]
Normalized costs based on the bounds. If no bounds are given, the original values are returned.
Also, if min and max bounds are the same, the value of the corresponding objective is set to 1.
"""
if bounds is None:
return values
if len(values) != len(bounds):
raise ValueError("Number of values and bounds must be equal.")
costs = []
for v, b in zip(values, bounds):
assert not isinstance(v, list)
p = v - b[0]
q = b[1] - b[0]
if q < 1e-10:
cost = 1.0
else:
cost = p / q
costs.append(cost)
return costs
|