solution

solution

MaxDivSolution dataclass

MaxDivSolution(
    i_selected: NDArray[int32],
    score_checkpoints: list[tuple[str, Elapsed, Score]],
    step_durations: dict[str, Elapsed],
)

score property

score: Score

Return the final score of the solution.

duration property

duration: Elapsed

Return the total elapsed time and iterations taken to compute the solution.

Score dataclass

Score(
    size: float,
    constraints: float,
    diversity: float,
    div_tie_breakers: tuple[float, ...],
)

Object representing the multi-component score of a selection, i.e. of a final or intermediate solution to a max-div problem with fairness constraints.

The different components have strict priorities in order of appearance:

                            size > constraints > diversity > div_non_zero > div_fgm.

Only in case of a tie in a lower-priority component, the next higher-priority component is considered for comparisons.

All scores are >= 0.0, with higher being better.

RATIONALE behind diversity tie-breakers:

  • these are optional additional metrics that can be added in case of ties in the main diversity score.

    • EX 1: min-dist only depends on the smallest distance. Hence, swapping out any other vector in the selection can have no effect on the diversity score, leading to many ties. --> Adding a tie-breaker such as geo-mean separation, can help pure swap-based algorithm converge towards a more optimal solution.

    • EX 2: geo-mean will be 0.0 if any separation-value in the selection is 0. If more than 1 such value is 0.0, we have a situation where any single-vector swap will not affect the diversity score. --> Adding a tie-breaker that counts how many non-zero distances there are, helps guide the solver towards removing vectors causing 0-distances.

as_tuple

as_tuple(
    soft: float = 0.0, ignore_infeasible_diversity: bool = False
) -> tuple[float, ...]

Return score as tuple, in order of descending priority, such that tuple-comparison yields correct results.

Parameters:

Name Type Description Default
soft float

Softness parameter in [0.0 ,1.0] indicating how soft constraints should be treated. 0.0 = hard constraints (i.e. constraints score is absolute higher prio than diversity)

0.0 = soft constraints (i.e. diversity score is partly 'mixed into' constraints score) constraints_soft = constraints^(1-soft) * diversity^soft

0.0
ignore_infeasible_diversity bool

If True, diversity is set to 0.0 if constraints are not fully satisfied.

False