Overview¶
GerryTools exposes the same scoring ideas at three levels. Choose the smallest interface that fits the work you are doing.
Use |
|
|---|---|
Convenience functions |
Evaluate one assignment |
PlanEvaluator |
Reuse resources across metrics or plans |
Array formulas |
Score arrays already aggregated by district |
Assignment forms¶
Form |
Interpretation |
|---|---|
GeoDataFrame column name |
District labels are read from that column |
Mapping |
Each graph node is mapped to a district label |
Sequence |
District labels follow graph-node order |
GerryChain |
The partition assignment and graph are used together |
Geometry metrics need a GeoDataFrame. Graph metrics can use a NetworkX graph or GerryChain
partition. PlanEvaluator uses one graph as the common unit order for every registered metric.
Metric families¶
Every row below has both a lowercase convenience function and a corresponding capitalized metric unless noted otherwise.
Aggregation, population, and demographics¶
Function / metric |
Result |
|---|---|
|
Sums one or more columns by district |
|
Sums columns by fixed region and district |
|
Signed district deviations from ideal population |
|
Largest absolute district deviation |
|
Top-to-bottom district population range |
|
District subgroup shares |
|
Count of districts above a subgroup threshold |
Elections and partisan scores¶
Function / metric |
Result |
|---|---|
|
Two-party district vote shares |
|
District win indicators |
|
Seats won |
|
Aggregate two-party vote share |
|
Signed seat share minus aggregate vote share |
|
Wasted-vote efficiency gap |
|
Equal-turnout seat-vote formula |
|
Median minus mean district vote share |
|
Partisan bias at 50 percent under uniform swing |
|
Unsigned partisan Gini under uniform swing |
Scores across elections¶
These metrics accept one party/opposition column pair per election.
Function / metric |
Result |
|---|---|
|
Contests within a margin around 50 percent |
|
Party wins by district across elections |
|
Districts not consistently won by either side |
|
Districts won by the party in every election |
|
Districts won by the opposition in every election |
|
Wins across every election and district |
|
Mean signed seat-share minus vote-share gap |
|
Mean absolute seat-share minus vote-share gap |
Regions and compactness¶
Function / metric |
Result |
|---|---|
|
Cut-edge count or summed edge weight |
|
Fixed regions assigned to multiple districts |
|
Occupied region-district pairs |
|
Connected region-district parts |
|
Polsby-Popper compactness |
|
Schwartzberg compactness |
|
Minimum-enclosing-circle compactness |
|
Convex-hull compactness |
|
State-clipped convex-hull compactness |
|
Population captured by a district convex hull |
|
Seat share against a population-weighted regional benchmark |
Array formulas¶
The functions in gerrytools.scoring.formulas operate on NumPy-compatible arrays. The final
axis is districts; cross-election functions use the preceding axis for elections.
import pandas as pd
import gerrytools.scoring as gs
democratic_votes = [60, 45, 70, 40]
republican_votes = [40, 55, 30, 60]
district_populations = [98, 101, 100, 101]
pd.Series(
{
"seats": gs.formulas.seats(democratic_votes, republican_votes),
"efficiency gap": gs.formulas.efficiency_gap(democratic_votes, republican_votes),
"maximum population deviation": gs.formulas.max_population_deviation(district_populations),
}
)
/home/docs/checkouts/readthedocs.org/user_builds/gerrytools/envs/latest/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
seats 2
efficiency gap -0.075
maximum population deviation 3.0
dtype: object
Continue with Convenience Functions for one-plan calls or PlanEvaluator when resources should be reused. The scoring API contains the full signatures and formula conventions.