Skip to content

Commit

Permalink
more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarelis committed Jan 7, 2022
1 parent dc5380d commit 989e7d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RankedChoices"
uuid = "562810e1-8c0d-4830-9cc1-9c323639d9b1"
authors = ["Myrl <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[compat]
julia = "^1.5"
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Idealistically, our elections should run on this kind of algorithm. See this [bl
## Interface
Here I detail how to parse rankings, handle the Gibbs sampler, and interpret the results. For instance,
```julia
# (n_participants x ranking_size)
# (n_respondents x ranking_size)
rankings = [
"B" "C" "D";
"A" "D" "C";
Expand Down Expand Up @@ -65,4 +65,27 @@ Two simulation tactics are exposed: `RejectionSim` and `HamiltonianSim`. The ori
The snazzy `HamiltonianSim(n_trajectories::Int, collision_limit::Int)` is much more complex, but converges quickly even on large rankings. You can set parameter `n_trajectories := 1` if you don't mind consecutive samples being correlated. Additionally, `collision_limit` can be set to a relatively high number like `128`. It determines how many times a ball can bounce between the walls of a linearly constrained Gaussian before we give up early.


More details on the core methods coming (very) soon.
### Conjugate Priors
My sampler is Bayesian, and takes advantage of a number of conjugate priors. We typically seek to treat all cohorts and respondents equally a priori. Hence, I expose a method
```julia
prior = make_impartial_prior(n_total_candidates, n_cohorts;
precision_scale, precision_dof, mean_scale, dirichlet_weight)
```
where...
* `precision_scale`, usually around or above unit, scales the diagonal matrix that parametrizes a Wishart prior for the precision matrix.
* `precision_dof` sets the strength of the Wishart prior for influencing precision matrices.
* `mean_scale`, which can stay unit, constrains the spread of the multivariate cohort means. In particular, it determines how much less the mean is spread out compared to the spread of the actual utilities.
* `dirichlet_weight`, typically greater than unit, determines how strongly to favor cohorts of equal proportion


### Sampler

```julia
result = simulate(prior, simulation, votes, n_trials;
n_burnin, seed, indifference=false, verbose=false)
```

The boolean flag `indifference` tells the sampler whether to treat incomplete rankings as implying that all unlisted candidates are lower than those listed (`indifference := false`) or not (`indifference := true`).


More details on the core methods coming soon.
4 changes: 2 additions & 2 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function read_prm_file(filename, N, R)
padded_candidates = vcat(candidates, zeros(Int, R-n_choices))
push!(rankings, RankedChoice{R}(padded_candidates))
end
rankings
IssueVote(rankings, N)
end

using CSV, DataFrames
Expand Down Expand Up @@ -83,7 +83,7 @@ function parse_matrix(matrix::AbstractMatrix{String}, candidates::AbstractVector
filtered_votes = filter(votes) do vote
vote[1] != 0 # first entry can't be zero!! todo: ensure all other entries are zero too? if not, we could shift forward...
end
filtered_votes, waste
IssueVote(filtered_votes, N), waste
end

function quantize(items::AbstractVector{S}, keys::AbstractVector{S}) where S
Expand Down

2 comments on commit 989e7d8

@marmarelis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/51929

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 989e7d830a9698e8a47f8292c1320cb12528370e
git push origin v0.1.1

Please sign in to comment.