Calculate with and analyze probability densities.
Project description
probability_calculator
Calculate with and analyze probability densities.
Usage
Initialization and plotting
The package provides simple ways to define discrete densities, for instance a dice:
from probability_calculator.density import Dice
density = Dice(6) # initialize a fair dice with 6 sides
fig, ax = density.plot() # plot the density using matplotlib
For the general case, the class DiscreteDensity
can be used:
from probability_calculator.density import DiscreteDensity
density = DiscreteDensity(outcomes=[
{ "value": 0, "prob": 0.2 },
{ "value": 1, "prob": 0.3 },
{ "value": 2.5, "prob": 0.1 },
{ "value": 3, "prob": 0.4 },
]) # initialize a discrete density with 4 different outcomes
fig, ax = density.plot() # plot the density using matplotlib
combine discrete densities
The discrete density of throwing a dice two times can be modelled by multiplying the density with itself:
densityForOneThrow = Dice(6)
densitySumOfTwoThrows = densityForOneThrow * densityForOneThrow # same as densityForOneThrow**2
fig, ax = densitySumOfTwoThrows.plot()
Note that the operations on densities are defined in a way to comply with operations of probability-generating functions. This means multiplication of densities return the density of the sum of the two underlying random variables
Limitations
Continuous densities are not supported at the moment.
Multiplying a lot of densities might get stuck due to a lot of possible outcomes. In general, multiplying 10 densities with 10 outcomes each lead to $10^{10}$ outcomes. However, simple cases like the dice work, Dice(10)**10
is no problem.
Contributing
We greatly appreciate fixes and new features for probability_calculator. All contributions to this project should be sent as pull requests on github.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for probability_calculator-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a7ebf7c533dc3449d7672e52bb4b6cb5f4bf86b717c794e9d59ab939403030c |
|
MD5 | f8d6b5eb431941ea51827b8eb29e0c39 |
|
BLAKE2b-256 | 86cfe1b07959fbc3c8689f7bae0672749bd2cc0bd3bc6936fad2239e160c7640 |
Hashes for probability_calculator-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4af5fe91c988064a6f470b3102cb3461066090c4acfaf371e4e787460bcec6af |
|
MD5 | d96bee2d630434028700b25e79ecfae3 |
|
BLAKE2b-256 | 99a269ea31331765497d276378d9a40c7bd76396a951462a3d1e07b91f1d8fbe |