consistent_sampler
Routine sampler for providing 'consistent sampling' --- sampling that is
consistent across subsets. Consistent sampling works by associating a random number with
each element; the desired sample is found by taking the subset of the desired sample size
containing those elements with the smallest associated random numbers.
The sampling is consistent since it consistently favors elements with small associated random numbers; if two sets S and T have substantial overlap, then their samples of a given size will also have substantial overlap (for the same random seed).
This routine is intended for use in election audits, where the objects being sampled are ballots, but this procedure is for general use. For a similar election audit sampling method, see Stark's election audit tools: https://www.stat.berkeley.edu/~stark/Vote/auditTools.htm
This routine takes as input a finite collection of distinct object ids, a random seed, and some other parameters. The sampling may be "with replacement" or "without replacement". One of the additional parameters to the routine is "take" -- the size of the desired sample.
It provides as output a "sampling order" --- an ordered list of object ids that determine
the sample. For sampling without replacement, the output can not be longer than the input, as no
object may appear in the sample more than once. For sampling with replacement, the output
may be infinite in length, as an object may appear in the sample an arbitrarily large
(even infinite) number of times. The output of sampler is therefore always a python
generator, capable of producing an infinitely long stream of output object ids.
As a small example of sampling without replacement:
g = sampler(['A-1', 'A-2', 'A-3', 'B-1', 'B-2', 'B-3'],
with_replacement=False, take=4, seed=314159, output='id')
yields a generator g whose output can be printed:
print(list(id for id in g))
which produces:
['B-2', 'B-3', 'A-3', 'A-2']
Consistent sampling is not a new idea, see for example https://arxiv.org/abs/1612.01041 and the references to consistent sampling therein.
The routine here may (or may not) be novel in that it extends consistent sampling to sampling with replacement: when an item is sampled and then replaced in the set of items being sampled, it is given a new random number drawn uniformly from the set of numbers in (0, 1) larger than its previous associated number. To implement this efficiently and portably, we represent a number in (0, 1) as a variable-length decimal string of the form '0.dddddd...' .
For our applications, one big advantage of consistent sampling is the following. If each county collects cast ballots separately, then they can order their own ballots for sampling and interpretation independently of what other counties are doing. An overall sample can be constructed from the individual county samples.
Further documentation and examples are in the code.
Metadata
Release files for consistentsamplerpkg 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| consistentsamplerpkg-1.0.2.tar.gz | 2.6 kB | Without provenance | Details for consistentsamplerpkg-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| consistentsamplerpkg-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for consistentsamplerpkg-1.0.2-py3-none-any.whl |
Total release size: 5.4 kB
Release files / consistentsamplerpkg-1.0.2.tar.gz
| Download URL | consistentsamplerpkg-1.0.2.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee0908b978e7f874fbb7f024a96214e7ca29228ab3f84ccd4a5824be489cc861
|
|
BLAKE2b-256 checksum How to use checksums |
f8f18e5d15380153856f62bcd63713e8f6e8757892aed726aa1108e8920599aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.1
|
Release files / consistentsamplerpkg-1.0.2-py3-none-any.whl
| Download URL | consistentsamplerpkg-1.0.2-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
074d5d0669350e3392c3a974f14d38b900c31eb7005913767978624e0f99557a
|
|
BLAKE2b-256 checksum How to use checksums |
a7feb1a80ef801c54584826fc709109bee3b5f63d01fcfdc3c9ba469f4176715
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.1
|
Security for consistentsamplerpkg 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.