diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index 73b01cb..1434e94 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -22,5 +22,3 @@ jobs: - name: Trunk Check uses: trunk-io/trunk-action@75699af9e26881e564e9d832ef7dc3af25ec031b # v1.2.4 - with: - post-annotations: true diff --git a/README.md b/README.md index f09a08a..9b76349 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ different voting systems, electorate models, and strategic behaviors. See the [VSE FAQ](https://electionscience.github.io/vse-sim/) for an explanation of the methods and published results. +See the [chart reproduction guide](docs/chart-reproduction.md) to generate the +full simulation CSV used by the chart analysis. + ## Setup The project supports Python 3.10 through 3.12 and uses diff --git a/docs/chart-reproduction.md b/docs/chart-reproduction.md new file mode 100644 index 0000000..9b3fff1 --- /dev/null +++ b/docs/chart-reproduction.md @@ -0,0 +1,24 @@ +--- +title: Chart data reproduction +layout: default +permalink: /chart-reproduction +--- + +The published charts are derived from a full simulation CSV. Generate that CSV +with the same settings used by the charts: + +```bash +uv run python scripts/generate_published_results.py --elections 15000 \ + --output artifacts/published-results +``` + +The command prints the generated filename. To explore that data with the +historical R analysis, install `data.table` and `scatterD3`, then pass the CSV +path explicitly: + +```bash +Rscript vseCheck.R artifacts/published-results1.csv +``` + +The generated CSV is intentionally not committed. It records the model, +methods, seed, and iteration count in its first line. diff --git a/scripts/generate_published_results.py b/scripts/generate_published_results.py new file mode 100644 index 0000000..a18ff11 --- /dev/null +++ b/scripts/generate_published_results.py @@ -0,0 +1,49 @@ +"""Generate the complete simulation CSV consumed by the chart analysis. + +Example: + + uv run python scripts/generate_published_results.py --elections 15000 \ + --output artifacts/published-results +""" + +import argparse +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) + +from debugDump import setDebug +from vse import CsvBatch, KSModel, allSystems, fuzzyMediaFor + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--elections", type=int, default=15_000) + parser.add_argument("--seed", default="target15000") + parser.add_argument( + "--output", + type=Path, + default=Path("artifacts/published-results"), + help="Filename prefix; the runner appends a numeric CSV suffix.", + ) + args = parser.parse_args() + + setDebug(False) + args.output.parent.mkdir(parents=True, exist_ok=True) + batch = CsvBatch( + KSModel(dcdecay=(1, 3), wcdecay=(1.5, 3), dccut=.2, wcalpha=1.5), + allSystems, + nvot=40, + ncand=6, + niter=args.elections, + baseName=str(args.output), + media=fuzzyMediaFor(), + seed=args.seed, + force=True, + retain_rows=False, + ) + print(batch.output_file) + + +if __name__ == "__main__": + main() diff --git a/vseCheck.R b/vseCheck.R index 08dac5a..50db141 100644 --- a/vseCheck.R +++ b/vseCheck.R @@ -35,7 +35,11 @@ library(scatterD3) # # fvse = rbind(fvse,fread("wtf2.csv")) -fvse = fread("target3.csv") +args = commandArgs(trailingOnly = TRUE) +if (length(args) != 1) { + stop("Usage: Rscript vseCheck.R PATH_TO_RESULTS.csv") +} +fvse = fread(args[[1]]) fuzVses = fvse[,mean(util-rand)/mean(best-rand),by=list(method,chooser)] etype = fvse[method=="Schulze" & chooser=="honBallot",tallyVal0,by=eid] names(etype) = c("eid","scenario") @@ -135,4 +139,4 @@ honestScenarios2[,VSE:=vse*100] library(ggplot2) library(ggthemes) ggplot(data = honestScenarios2[as.character(method) %in% levels(honestScenarios2[,method])[c(1:3,5)],], aes(x = VSE, y = method, group = method)) + geom_line(size=3) + xlim(70,100) + theme_gdocs() + theme(axis.title.y=element_blank()) + xlab("% Voter Satisfaction Efficiency (VSE)") -#(I think that refining the strategies can improve the function:backfire balance, but it's a) \ No newline at end of file +#(I think that refining the strategies can improve the function:backfire balance, but it's a)