mirror of
https://github.com/tgorordo/smithy.git
synced 2026-06-05 16:22:15 -07:00
switch default to numpy pmg building
This commit is contained in:
parent
1a668a7cee
commit
368770d792
4 changed files with 3010 additions and 9 deletions
|
|
@ -28,20 +28,18 @@ def pmg_from_rcv_polars(ballots: pl.DataFrame) -> rwx.PyDiGraph:
|
||||||
pmg = rwx.PyDiGraph()
|
pmg = rwx.PyDiGraph()
|
||||||
nodes = {c: pmg.add_node(c) for c in candidates}
|
nodes = {c: pmg.add_node(c) for c in candidates}
|
||||||
|
|
||||||
#compressed = ballots.group_by(ballots.columns).len().rename({"len": "count"})
|
compressed = ballots.group_by(ballots.columns).len().rename({"len": "count"})
|
||||||
|
|
||||||
exprs = []
|
exprs = []
|
||||||
pairs = list(combinations(candidates, 2))
|
pairs = list(combinations(candidates, 2))
|
||||||
|
|
||||||
for a, b in pairs:
|
for a, b in pairs:
|
||||||
exprs.extend(
|
exprs.extend([
|
||||||
[
|
pl.when(pl.col(a) < pl.col(b)).then(pl.col("count")).otherwise(0).sum().alias(f"{a}>{b}"),
|
||||||
(pl.col(a) < pl.col(b)).sum().alias(f"{a}>{b}"),
|
pl.when(pl.col(b) < pl.col(a)).then(pl.col("count")).otherwise(0).sum().alias(f"{b}>{a}")
|
||||||
(pl.col(b) < pl.col(a)).sum().alias(f"{b}>{a}"),
|
])
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
results = ballots.select(exprs).row(0, named=True)
|
results = compressed.select(exprs).row(0, named=True)
|
||||||
|
|
||||||
for a, b in pairs:
|
for a, b in pairs:
|
||||||
a_wins = results[f"{a}>{b}"]
|
a_wins = results[f"{a}>{b}"]
|
||||||
|
|
@ -99,7 +97,7 @@ def pmg_from_rcv_numpy(ballots: pl.DataFrame) -> rwx.PyDiGraph:
|
||||||
|
|
||||||
return pmg
|
return pmg
|
||||||
|
|
||||||
def pmg_from_rcv(ballots: pl.DataFrame, method="polars") -> rwx.PyDiGraph:
|
def pmg_from_rcv(ballots: pl.DataFrame, method="numpy") -> rwx.PyDiGraph:
|
||||||
if method == "polars":
|
if method == "polars":
|
||||||
return pmg_from_rcv_polars(ballots)
|
return pmg_from_rcv_polars(ballots)
|
||||||
elif method == "numpy":
|
elif method == "numpy":
|
||||||
|
|
|
||||||
1001
test/stress_test_1000000x1000.csv
Normal file
1001
test/stress_test_1000000x1000.csv
Normal file
File diff suppressed because one or more lines are too long
1001
test/stress_test_100000x100.csv
Normal file
1001
test/stress_test_100000x100.csv
Normal file
File diff suppressed because it is too large
Load diff
1001
test/stress_test_1000x100.csv
Normal file
1001
test/stress_test_1000x100.csv
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue