urn-calculator


Nameurn-calculator JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryMultivariate hypergeometric command line calculator.
upload_time2023-11-04 14:20:15
maintainer
docs_urlNone
authorAlex Riley
requires_python>=3.10
licenseMIT License Copyright (c) 2023 Alex Riley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords calculator probability count draw random sample hypergeometric
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # urn

A fast multivariate hypergeometric calculator with an intuitive language interface.

Find the probability of drawing a target set of objects from a collection, either with or without replacement.

Display the results as a table or a plot in your terminal.

## Using the calculator

The `urn` program can be run as a shell:
```
$ urn
urn>
```
Computations are described in the following form:
```
PROBABILITY DRAW [number of things]
FROM [collection]
WHERE [zero or more constraints on draw];
```
To see the total count of possible draws, replace `PROBABILITY` with `COUNT`.

By default, the computation assumes that draws are made without replacement. This can be changed by specifying `DRAW [number of things] WITH REPLACEMENT`.

Let's look at some examples.

Suppose we want to draw _without replacement_ from an urn containing coloured marbles. We want to see the probability that we see _at least_ 2 red and _at most_ 5 blue:
```
urn> probability draw from red = 5, blue = 7, green = 3 where red >= 2 and blue <= 5;
```
This returns the table of probabilities:
```
  draw size    probability
-----------  -------------
          2      0.0952381
          3      0.241758
          4      0.406593
          5      0.566434
          6      0.706294
          7      0.818182
          8      0.888889
          9      0.895105
         10      0.818182
         11      0.661538
         12      0.446154
         13      0.2

```
Note that the query keywords such as `FROM` and `WHERE` are not case sensitive. A semicolon `;` ends the query. Whitespace is ignored.

We didn't specify a size for our draw, so the program returned _all_ draw sizes with a non-zero probability of meeting our constraints.

By default `urn` returns float numbers for probabilities. We can make it show exact rational numbers by appending `show rational`:
```
urn> probability draw 1..5 from red=5, blue=7, green=3 where red >= 2 and blue <= 5 show rational;
  draw size  probability
-----------  -------------
          1  0
          2  2/21
          3  22/91
          4  37/91
          5  81/143
```
Here we also specified a range `1..5` for the draw size. Single draw sizes (e.g. `5`) are also permitted.

It's useful to create a plot (`show plot`) to see the optimal draw size at a glance:
```
urn> probability draw from red=5, blue=7, green=3 where red >= 2 and blue <= 5 show plot;
┌────────────────────────────────────────────────────────────┐
│                                ▝     ▘                     │ 
│                           ▘               ▝                │ 
│                                                            │ 
│                     ▗                                      │ 
│                                                 ▘          │ 
│                                                            │ 
│                ▘                                           │ 
│                                                            │ 0.5
│                                                      ▖     │ 
│          ▝                                                 │ 
│                                                            │ 
│                                                            │ 
│     ▝                                                      │ 
│                                                           ▝│ 
│                                                            │ 
│▘                                                           │ 
│▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0.0
└────────────────────────────────────────────────────────────┘
   2             5             7           10            12
```
To see the same calculation, but in the case where we draw _with replacement_, we must specify a range and use the `WITH REPLACEMENT` modifier:

```
urn> probability draw 2..13 with replacement
...  from red=5, blue=7, green=3
...  where red >= 2 and blue <= 5 show plot;
┌────────────────────────────────────────────────────────────┐
│                           ▖    ▝     ▖                     │ 
│                                                            │ 
│                     ▗                     ▝                │ 
│                                                            │ 
│                                                 ▘          │ 
│                ▘                                           │ 
│                                                      ▖     │ 0.5
│                                                            │ 
│          ▝                                                ▗│ 
│                                                            │ 
│                                                            │ 
│     ▝                                                      │ 
│                                                            │ 
│                                                            │ 
│▖                                                           │ 
│                                                            │ 
│▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0.0
└────────────────────────────────────────────────────────────┘
   2             5             7           10            12
```

Finally, we can use `OR` to specify any number of alternative constraints on our draw.
```
urn> probability draw 1..10 from red=5, blue=7, green=3
...  where red >= 2 and blue <= 3
...  or blue > 0 and green > 1
...  or blue = 2 red >= 2 and green <= 2
...  show plot;
┌────────────────────────────────────────────────────────────┐
│                                       ▗      ▝      ▘     ▝│ 1.0
│                                                            │ 
│                                 ▘                          │ 
│                    ▖                                       │ 
│                          ▗                                 │ 
│             ▖                                              │ 
│                                                            │ 
│                                                            │ 
│                                                            │ 0.5
│                                                            │ 
│                                                            │ 
│      ▗                                                     │ 
│                                                            │ 
│                                                            │ 
│                                                            │ 
│                                                            │ 
│▖▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0.0
└────────────────────────────────────────────────────────────┘
       2             4            6            8           10
```
To exit the shell, type `quit`:
```
urn> quit;
Exiting urn.
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "urn-calculator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "calculator,probability,count,draw,random,sample,hypergeometric",
    "author": "Alex Riley",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/76/82/b7b12be5e5ef6baf5cb95fa001ad13561d2918996adcd99764fbce345395/urn-calculator-0.0.1.tar.gz",
    "platform": null,
    "description": "# urn\n\nA fast multivariate hypergeometric calculator with an intuitive language interface.\n\nFind the probability of drawing a target set of objects from a collection, either with or without replacement.\n\nDisplay the results as a table or a plot in your terminal.\n\n## Using the calculator\n\nThe `urn` program can be run as a shell:\n```\n$ urn\nurn>\n```\nComputations are described in the following form:\n```\nPROBABILITY DRAW [number of things]\nFROM [collection]\nWHERE [zero or more constraints on draw];\n```\nTo see the total count of possible draws, replace `PROBABILITY` with `COUNT`.\n\nBy default, the computation assumes that draws are made without replacement. This can be changed by specifying `DRAW [number of things] WITH REPLACEMENT`.\n\nLet's look at some examples.\n\nSuppose we want to draw _without replacement_ from an urn containing coloured marbles. We want to see the probability that we see _at least_ 2 red and _at most_ 5 blue:\n```\nurn> probability draw from red = 5, blue = 7, green = 3 where red >= 2 and blue <= 5;\n```\nThis returns the table of probabilities:\n```\n  draw size    probability\n-----------  -------------\n          2      0.0952381\n          3      0.241758\n          4      0.406593\n          5      0.566434\n          6      0.706294\n          7      0.818182\n          8      0.888889\n          9      0.895105\n         10      0.818182\n         11      0.661538\n         12      0.446154\n         13      0.2\n\n```\nNote that the query keywords such as `FROM` and `WHERE` are not case sensitive. A semicolon `;` ends the query. Whitespace is ignored.\n\nWe didn't specify a size for our draw, so the program returned _all_ draw sizes with a non-zero probability of meeting our constraints.\n\nBy default `urn` returns float numbers for probabilities. We can make it show exact rational numbers by appending `show rational`:\n```\nurn> probability draw 1..5 from red=5, blue=7, green=3 where red >= 2 and blue <= 5 show rational;\n  draw size  probability\n-----------  -------------\n          1  0\n          2  2/21\n          3  22/91\n          4  37/91\n          5  81/143\n```\nHere we also specified a range `1..5` for the draw size. Single draw sizes (e.g. `5`) are also permitted.\n\nIt's useful to create a plot (`show plot`) to see the optimal draw size at a glance:\n```\nurn> probability draw from red=5, blue=7, green=3 where red >= 2 and blue <= 5 show plot;\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502                                \u259d     \u2598                     \u2502 \n\u2502                           \u2598               \u259d                \u2502 \n\u2502                                                            \u2502 \n\u2502                     \u2597                                      \u2502 \n\u2502                                                 \u2598          \u2502 \n\u2502                                                            \u2502 \n\u2502                \u2598                                           \u2502 \n\u2502                                                            \u2502 0.5\n\u2502                                                      \u2596     \u2502 \n\u2502          \u259d                                                 \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502     \u259d                                                      \u2502 \n\u2502                                                           \u259d\u2502 \n\u2502                                                            \u2502 \n\u2502\u2598                                                           \u2502 \n\u2502\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2502 0.0\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n   2             5             7           10            12\n```\nTo see the same calculation, but in the case where we draw _with replacement_, we must specify a range and use the `WITH REPLACEMENT` modifier:\n\n```\nurn> probability draw 2..13 with replacement\n...  from red=5, blue=7, green=3\n...  where red >= 2 and blue <= 5 show plot;\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502                           \u2596    \u259d     \u2596                     \u2502 \n\u2502                                                            \u2502 \n\u2502                     \u2597                     \u259d                \u2502 \n\u2502                                                            \u2502 \n\u2502                                                 \u2598          \u2502 \n\u2502                \u2598                                           \u2502 \n\u2502                                                      \u2596     \u2502 0.5\n\u2502                                                            \u2502 \n\u2502          \u259d                                                \u2597\u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502     \u259d                                                      \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502\u2596                                                           \u2502 \n\u2502                                                            \u2502 \n\u2502\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2502 0.0\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n   2             5             7           10            12\n```\n\nFinally, we can use `OR` to specify any number of alternative constraints on our draw.\n```\nurn> probability draw 1..10 from red=5, blue=7, green=3\n...  where red >= 2 and blue <= 3\n...  or blue > 0 and green > 1\n...  or blue = 2 red >= 2 and green <= 2\n...  show plot;\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502                                       \u2597      \u259d      \u2598     \u259d\u2502 1.0\n\u2502                                                            \u2502 \n\u2502                                 \u2598                          \u2502 \n\u2502                    \u2596                                       \u2502 \n\u2502                          \u2597                                 \u2502 \n\u2502             \u2596                                              \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 0.5\n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502      \u2597                                                     \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502                                                            \u2502 \n\u2502\u2596\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2502 0.0\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n       2             4            6            8           10\n```\nTo exit the shell, type `quit`:\n```\nurn> quit;\nExiting urn.\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Alex Riley  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Multivariate hypergeometric command line calculator.",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/ajcr/urn"
    },
    "split_keywords": [
        "calculator",
        "probability",
        "count",
        "draw",
        "random",
        "sample",
        "hypergeometric"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41dfe9744c28443036d1332cfb6115c83a8b997009d5ad7ffa3adddddb97b2a3",
                "md5": "e0cc0e9332eb8c3b56a693f172f50690",
                "sha256": "b62d73693911f7e11bba061687c4774ef7f377996442b66d86cac73dc3a10918"
            },
            "downloads": -1,
            "filename": "urn_calculator-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0cc0e9332eb8c3b56a693f172f50690",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12503,
            "upload_time": "2023-11-04T14:20:14",
            "upload_time_iso_8601": "2023-11-04T14:20:14.028680Z",
            "url": "https://files.pythonhosted.org/packages/41/df/e9744c28443036d1332cfb6115c83a8b997009d5ad7ffa3adddddb97b2a3/urn_calculator-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7682b7b12be5e5ef6baf5cb95fa001ad13561d2918996adcd99764fbce345395",
                "md5": "454b9e684a3c866142d5babdf6cb8388",
                "sha256": "0c92a8c159f02facf02f40930359cf1a9167977e19c736a437a97bd9bf5a7ee2"
            },
            "downloads": -1,
            "filename": "urn-calculator-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "454b9e684a3c866142d5babdf6cb8388",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14593,
            "upload_time": "2023-11-04T14:20:15",
            "upload_time_iso_8601": "2023-11-04T14:20:15.835163Z",
            "url": "https://files.pythonhosted.org/packages/76/82/b7b12be5e5ef6baf5cb95fa001ad13561d2918996adcd99764fbce345395/urn-calculator-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-04 14:20:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ajcr",
    "github_project": "urn",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "urn-calculator"
}
        
Elapsed time: 0.33476s