saealib.WeightedSumComparator#
- class saealib.WeightedSumComparator(direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#
Bases:
ComparatorComparator for multi-objective optimization via weighted scalarization.
Aggregates multiple objectives into a single scalar using a weighted dot product: score = f @ weights. The sign convention for weights follows the same pattern as SingleObjectiveComparator: use negative weights for minimization (e.g., weights=np.array([-1.0, -1.0])).
Also supports single-objective problems (n_obj == 1).
- Parameters:
direction (np.ndarray) – Per-objective optimization directions (±1). shape = (n_obj,)
eps_cv (float)
eps_obj (float)
Methods
Compare two solutions directly without a Population object. |
|
Compare two individuals by weighted sum; -1=a better, 1=b better, 0=equal. |
|
Return population attributes this comparator needs to persist. |
|
Freshly recompute and materialize population-relative ranking state. |
|
Prepare population-relative ranking state, then sort. |
|
Sort population by weighted sum of objectives, with feasibility first. |
Method Details
- WeightedSumComparator.__init__(direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#
- Parameters:
direction (ndarray | None)
eps_cv (float)
eps_obj (float)
- WeightedSumComparator.compare(fa, cv_a, fb, cv_b)[source]#
Compare two solutions directly without a Population object.
- Parameters:
fa (ndarray)
cv_a (float)
fb (ndarray)
cv_b (float)
- Return type:
int
- WeightedSumComparator.compare_population(population, idx_a, idx_b)[source]#
Compare two individuals by weighted sum; -1=a better, 1=b better, 0=equal.
- Parameters:
population (Population)
idx_a (int)
idx_b (int)
- Return type:
int
- WeightedSumComparator.get_required_attrs(problem)#
Return population attributes this comparator needs to persist.
Population-relative ranking state (e.g. SPEA2 fitness) that must survive across selections belongs here as a named, typed attribute rather than in the population’s transient cache. Default: no additional attributes.
- Parameters:
problem (Problem) – The optimization problem.
- Returns:
Empty by default.
- Return type:
list[PopulationAttribute]
- WeightedSumComparator.prepare_population(population)#
Freshly recompute and materialize population-relative ranking state.
Default is a no-op — comparators whose ranking depends only on per-individual values already stored in
f/cvdo not need this. Comparators that declare attributes viaget_required_attrs()should override this to recompute and write those attributes for the given population, unconditionally (not reusing any prior cached value).- Parameters:
population (Population) – The population to prepare ranking state for.
- Return type:
None
- WeightedSumComparator.rank_population(population)#
Prepare population-relative ranking state, then sort.
Equivalent to calling
prepare_population()followed bysort_population(). Callers performing environmental selection on a freshly assembled pool (e.g. survivor selection merging population and offspring) should call this instead ofsort_population()directly, so any population-relative state declared viaget_required_attrs()is recomputed for the new set before ranking.- Parameters:
population (Population) – The population to rank.
- Returns:
Sorted population indices, as returned by
sort_population().- Return type:
np.ndarray
- WeightedSumComparator.sort_population(population)[source]#
Sort population by weighted sum of objectives, with feasibility first.
- Parameters:
population (Population)
- Return type:
np.ndarray