Answer architecture round 1: make cognitive complexity a pure recursion, share a tied top-k cut evenly, count unresolved places, skip a run whose commit is gone, fail on a file that does not parse, link the history's format and its reader both ways, reword item 85's order, and record the worse ruling
This commit is contained in:
@@ -38,18 +38,20 @@ def co_changed(log: str) -> dict[str, int]:
|
||||
return {path: len(others) for path, others in partners.items()}
|
||||
|
||||
|
||||
def bench(units: list[Unit], places: list[Place], spread: dict[str, int]) -> RunScores | None:
|
||||
"""How well each metric ranks the units the seats named above the rest; None when no named place is a measured unit."""
|
||||
def bench(units: list[Unit], places: list[Place], unresolved: int, spread: dict[str, int]) -> RunScores | None:
|
||||
"""How well each metric ranks the units the seats named above the rest; None when the named units are none or all of them. unresolved counts the places that named no tracked file."""
|
||||
names = {(place.path, place.name) for place in places}
|
||||
named = [unit for unit in units if (unit.path, unit.name) in names]
|
||||
if not named or len(named) == len(units):
|
||||
return None
|
||||
rest = [unit for unit in units if (unit.path, unit.name) not in names]
|
||||
measured = {(unit.path, unit.name) for unit in named}
|
||||
unmeasured = len({place for place in places if (place.path, place.name) not in measured})
|
||||
found = {(unit.path, unit.name) for unit in named}
|
||||
unmeasured = unresolved + len({place for place in places if (place.path, place.name) not in found})
|
||||
scores = {}
|
||||
for metric, value in METRICS.items():
|
||||
scores[metric] = Score(auc([value(unit, spread) for unit in named], [value(unit, spread) for unit in rest]), top_k(units, named, lambda unit: value(unit, spread)))
|
||||
named_values = [value(unit, spread) for unit in named]
|
||||
rest_values = [value(unit, spread) for unit in rest]
|
||||
scores[metric] = Score(auc(named_values, rest_values), top_k(named_values, rest_values))
|
||||
return RunScores(len(units), len(named), unmeasured, scores)
|
||||
|
||||
|
||||
@@ -59,10 +61,15 @@ def auc(named: list[int], rest: list[int]) -> float:
|
||||
return wins / (len(named) * len(rest))
|
||||
|
||||
|
||||
def top_k(units: list[Unit], named: list[Unit], value: Callable[[Unit], int]) -> float:
|
||||
"""The share of the metric's top k units the seats named, k being how many they named; a tie at the cut counts in order of the units."""
|
||||
top = sorted(units, key=value, reverse=True)[:len(named)]
|
||||
return sum(unit in named for unit in top) / len(named)
|
||||
def top_k(named: list[int], rest: list[int]) -> float:
|
||||
"""The share of the metric's k highest units the seats named, k being how many they named. Units tied at the cut share its remaining seats evenly, as a random order of them would."""
|
||||
k = len(named)
|
||||
cut = sorted(named + rest, reverse=True)[k - 1]
|
||||
above = sum(value > cut for value in named)
|
||||
seats = k - above - sum(value > cut for value in rest)
|
||||
tied_named = sum(value == cut for value in named)
|
||||
tied = tied_named + sum(value == cut for value in rest)
|
||||
return (above + seats * tied_named / tied) / k
|
||||
|
||||
|
||||
def medians(runs: list[RunScores]) -> dict[str, Score]:
|
||||
|
||||
Reference in New Issue
Block a user