Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion elsim/studies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"""

from .backends import JoblibBackend, SerialBackend
from .condorcet_metrics import merrill_1984_comparison_methods, tally_condorcet_agreement
from .condorcet_metrics import (
approval_at_optimal,
merrill_1984_comparison_methods,
tally_condorcet_agreement,
)
from .parameters import expand_product, expand_rows, expand_zip
from .runner import merge_counters, run_batched
from .social_utility import (
Expand All @@ -31,6 +35,7 @@
"merge_counters",
"run_batched",
"merrill_1984_comparison_methods",
"approval_at_optimal",
"tally_condorcet_agreement",
"spatial_random_reference_utility_updates",
"random_society_utility_updates",
Expand Down
13 changes: 10 additions & 3 deletions elsim/studies/condorcet_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
RatedMethod = Callable[..., Optional[int]]


def _approval_at_optimal(utilities: np.ndarray, tiebreaker: str) -> Optional[int]: # noqa: UP045
def approval_at_optimal(utilities: np.ndarray, tiebreaker: str = "random") -> Optional[int]: # noqa: UP045
"""
Rated-method helper: build an optimal approval ballot, then apply :func:`elsim.methods.approval`.

Intended for use in a ``rated_methods`` mapping passed to
:func:`tally_condorcet_agreement` or the spatial sweep helpers, so scripts
stay declarative without repeating lambdas.
"""
return approval(approval_optimal(utilities), tiebreaker)


Expand All @@ -44,7 +51,7 @@ def merrill_1984_comparison_methods() -> tuple[dict[str, RankedMethod], dict[str
}
rated_methods: dict[str, RatedMethod] = {
"SU max": utility_winner,
"Approval": _approval_at_optimal,
"Approval": approval_at_optimal,
}
return ranked_methods, rated_methods

Expand Down Expand Up @@ -76,7 +83,7 @@ def tally_condorcet_agreement(
Returns
-------
collections.Counter
Includes key ``\"CW\"`` when a Condorcet winner exists, plus one key per
Includes key ``"CW"`` when a Condorcet winner exists, plus one key per
supplied method name when that method's winner matches the Condorcet
winner.
"""
Expand Down