Skip to main content

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

png

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

png

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()

png

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

Apache License 2.0

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

probability_calculator-0.2.0.tar.gz (34.8 kB view hashes)

Uploaded Source

Built Distribution

probability_calculator-0.2.0-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page