mggg / GerryChain

Use MCMC to analyze districting plans and gerrymanders
https://mggg.github.io/GerryChain/
Other
132 stars 74 forks source link

`MarkovChain` validators and `recursive_tree_part` #416

Closed cdonnay closed 1 year ago

cdonnay commented 1 year ago

The edit to chain.py ensures that if a user only inputs one constraint to a MarkovChain, it will still be able to print the correct error message should the chain fail. The error message relies on the constraints being turned into a Validator object, and previously if the user input a single constraint it did not get turned into a Validator.

The edit to tree.py fixes an issue that occasionally caused recursive_tree_part to generate plans that were imbalanced in population. Here is an example to show why the previous computation was incorrect. Suppose the ideal size is 100, epsilon = .02, and the previous district had size 99. Then the debt=-1, the min_pop=99, and max_pop=102. The pop_target = 100.5, and the new value for epsilon is .015. But then the lower end of the population range is actually (100.5)*(1-.015)=98.9925, and the upper end is 100.5**1+.015)=102.0075. The only change required to fix this is to compute the new value for epsilon using the new population target, not the ideal size.

codecov[bot] commented 1 year ago

Codecov Report

Merging #416 (6751a83) into main (1b8430d) will increase coverage by 0.00%. The diff coverage is 100.00%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/mggg/GerryChain/pull/416/graphs/tree.svg?width=650&height=150&src=pr&token=mDQkxqhlnr&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg)](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg) ```diff @@ Coverage Diff @@ ## main #416 +/- ## ======================================= Coverage 88.87% 88.88% ======================================= Files 39 39 Lines 1789 1790 +1 ======================================= + Hits 1590 1591 +1 Misses 199 199 ``` | [Files](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg) | Coverage Δ | | |---|---|---| | [gerrychain/chain.py](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg#diff-Z2VycnljaGFpbi9jaGFpbi5weQ==) | `88.63% <100.00%> (ø)` | | | [gerrychain/tree.py](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg#diff-Z2VycnljaGFpbi90cmVlLnB5) | `81.36% <100.00%> (+0.07%)` | :arrow_up: | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg). Last update [1b8430d...6751a83](https://app.codecov.io/gh/mggg/GerryChain/pull/416?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mggg).