randify


Namerandify JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummarySimple probability density function estimation for existing code
upload_time2024-07-01 23:17:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2024 Jonas Nebl 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 montecarlo random
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Randify

Randomize your existing code with randify.
Evaluate how your code reacts to randomly distributed inputs and evaluate the probability distributions of your code outputs.
Randify performs Monte Carlo simulations to estimate probability density distributions of your outputs. Designed for simple syntax.

Full API documentation at https://jonasnebl.github.io/randify/randify.html

## Installation
Install randify from PyPI:
```
$ pip install randify
```

## Quick guide

Randify works on functions with any number and type of input and output arguments.
In this quick example we have a function `y1, x2 = f(x1, x2)` returning the sum `x1 + x2` and the product `x1 * x2` of two arguments `x1` and `x2`. For more in-depth examples check-out the Jupyter-Notebooks in `examples`.
```
def f(x1, x2):
    return x1 + x2, x1 * x2

x1 = 1
x2 = 2
y1, x2 = f(x1, x2)
```
Now we want to evaluate how random inputs `x1` and `x2` influence the results `y1`and `y2` using randify. We can do this using two steps.
1. Define `x1`and/or `x2`as a RandomVariable. For defining the RandomVariable you need to pass a function that generates random samples of this RandomVariables.
In this example, we use functions from `numpy`'s random module, but you can also define custom functions (see the examples for that).
2. Call the `randify` function wrapper with the RandomVariables as arguments.
```
from randify import randify, RandomVariable
import numpy as np

def f(x1, x2):
    return x1 + x2, x1 * x2

x1 = RandomVariable(np.random.normal, loc=0, scale=1)
x2 = RandomVariable(np.random.uniform, low=-1, high=1)
y1, y2 = randify(f)(x1, x2)
```
`y1`and `y2` are now also RandomVariables. You can calculate the resulting statistical measure like expected value or variance. To display the estimated probability distributions, you can use randify's `plot_pdf` function:
```
print(f"E[y1] = {y1.expected_value}")
print(f"Var[y1] = {y1.variance}")

from randify import plot_pdf
plot_pdf(x1=x1, x2=x2, y1=y1, y2=y2)
```

## Documentation

Full API documentation can be found at https://jonasnebl.github.io/randify/randify.html. The documentation is generated automatically using `pdoc`.
```
$ pip install pdoc
$ pdoc randify --math
```

## Formatting 
`ruff` is used to format randify. 
```
$ pip install ruff
$ ruff format
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "randify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "montecarlo, random",
    "author": null,
    "author_email": "Jonas Nebl <jonas.nebl@tum.de>",
    "download_url": "https://files.pythonhosted.org/packages/9a/9d/bcda06fb5bd4f65400872941d14d6d679105a92838e9d8ba3bcb489ae07c/randify-0.1.0.tar.gz",
    "platform": null,
    "description": "# Randify\r\n\r\nRandomize your existing code with randify.\r\nEvaluate how your code reacts to randomly distributed inputs and evaluate the probability distributions of your code outputs.\r\nRandify performs Monte Carlo simulations to estimate probability density distributions of your outputs. Designed for simple syntax.\r\n\r\nFull API documentation at https://jonasnebl.github.io/randify/randify.html\r\n\r\n## Installation\r\nInstall randify from PyPI:\r\n```\r\n$ pip install randify\r\n```\r\n\r\n## Quick guide\r\n\r\nRandify works on functions with any number and type of input and output arguments.\r\nIn this quick example we have a function `y1, x2 = f(x1, x2)` returning the sum `x1 + x2` and the product `x1 * x2` of two arguments `x1` and `x2`. For more in-depth examples check-out the Jupyter-Notebooks in `examples`.\r\n```\r\ndef f(x1, x2):\r\n    return x1 + x2, x1 * x2\r\n\r\nx1 = 1\r\nx2 = 2\r\ny1, x2 = f(x1, x2)\r\n```\r\nNow we want to evaluate how random inputs `x1` and `x2` influence the results `y1`and `y2` using randify. We can do this using two steps.\r\n1. Define `x1`and/or `x2`as a RandomVariable. For defining the RandomVariable you need to pass a function that generates random samples of this RandomVariables.\r\nIn this example, we use functions from `numpy`'s random module, but you can also define custom functions (see the examples for that).\r\n2. Call the `randify` function wrapper with the RandomVariables as arguments.\r\n```\r\nfrom randify import randify, RandomVariable\r\nimport numpy as np\r\n\r\ndef f(x1, x2):\r\n    return x1 + x2, x1 * x2\r\n\r\nx1 = RandomVariable(np.random.normal, loc=0, scale=1)\r\nx2 = RandomVariable(np.random.uniform, low=-1, high=1)\r\ny1, y2 = randify(f)(x1, x2)\r\n```\r\n`y1`and `y2` are now also RandomVariables. You can calculate the resulting statistical measure like expected value or variance. To display the estimated probability distributions, you can use randify's `plot_pdf` function:\r\n```\r\nprint(f\"E[y1] = {y1.expected_value}\")\r\nprint(f\"Var[y1] = {y1.variance}\")\r\n\r\nfrom randify import plot_pdf\r\nplot_pdf(x1=x1, x2=x2, y1=y1, y2=y2)\r\n```\r\n\r\n## Documentation\r\n\r\nFull API documentation can be found at https://jonasnebl.github.io/randify/randify.html. The documentation is generated automatically using `pdoc`.\r\n```\r\n$ pip install pdoc\r\n$ pdoc randify --math\r\n```\r\n\r\n## Formatting \r\n`ruff` is used to format randify. \r\n```\r\n$ pip install ruff\r\n$ ruff format\r\n```\r\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2024 Jonas Nebl  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": "Simple probability density function estimation for existing code",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "montecarlo",
        " random"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "086e698a3fd346256df049b062d6bbc2840771ca1cfd38e8d142f963ac84f020",
                "md5": "103981cbb550cc8b13482ee569c87900",
                "sha256": "16b3b91b7c751dd5c98493139423a0fcede72eb2c39100be1f5cb5c3cc81fb59"
            },
            "downloads": -1,
            "filename": "randify-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "103981cbb550cc8b13482ee569c87900",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10650,
            "upload_time": "2024-07-01T23:17:00",
            "upload_time_iso_8601": "2024-07-01T23:17:00.197416Z",
            "url": "https://files.pythonhosted.org/packages/08/6e/698a3fd346256df049b062d6bbc2840771ca1cfd38e8d142f963ac84f020/randify-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a9dbcda06fb5bd4f65400872941d14d6d679105a92838e9d8ba3bcb489ae07c",
                "md5": "e828e3de71372d4c897e889f76a576a7",
                "sha256": "be551900f5f34eaabb0f26cb7cdb85074473917e9dbac31764de6899880f8771"
            },
            "downloads": -1,
            "filename": "randify-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e828e3de71372d4c897e889f76a576a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10501,
            "upload_time": "2024-07-01T23:17:07",
            "upload_time_iso_8601": "2024-07-01T23:17:07.318217Z",
            "url": "https://files.pythonhosted.org/packages/9a/9d/bcda06fb5bd4f65400872941d14d6d679105a92838e9d8ba3bcb489ae07c/randify-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-01 23:17:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "randify"
}
        
Elapsed time: 0.45343s