Skip to main content

Calculate values for probability distributions in Python, specifically designed for IPython

Project description

probcalc is a library that aims to provide a probability calculator in any Python REPL. It's mainly aimed at IPython, since this is often regarded as the best Python REPL, but any of them will work with this library.

In statistics, we are often faced with random variables which are distributed as certain probability distributions and we need to work out the probability of certain things happening. This is often tedious and error-prone. probcalc is the solution.

Let's say you flip a coin 100 times and want to work out the probability of getting at least 30 but less than 50 heads. You can say that X is a random variable representing the number of heads you get in 100 throws and then X is distributed as a binomial distribution with 100 trials and probability of one half. This is where probcalc comes in. You just define the variables and let the computer do the work:

>>> from probcalc import P, B
>>> X = B(100, 0.5)
>>> P(10 < X <= 20)
0.4601893013

Or, let's say there's a call center that gets an average of 5 calls every minute and you want to know the probability that they get more than 10 calls in a minute. For this, we can use a Poisson distribution:

>>> from probcalc import Po
>>> Y = Po(5)
>>> P(Y > 10)
0.3840393452

And of course, you can use the normal distribution:

>>> from probcalc import N
>>> Z = N(0, 1)
>>> P(-1 < Z < 1)
0.6826894723

This project will implement more distributions in the future, and they will all be able to be used like this.

For ease of use, you can also set the desired number of significant figures in your answer:

>>> P(-1 < Z < 1)
0.6826894723
>>> P.set_sig_figs(4)
>>> P(-1 < Z < 1)
0.6827

The full docs are available here.

Changelog

[Unreleased]

v0.5.0

  • Add geometric distribution

v0.4.0

  • Allow setting number of sig figs in result

v0.3.2

  • Disallow keyword arguments when using P()
  • Make backend attributes and methods non-public
  • Use readthedocs.io for documentation

v0.3.1

  • Improve performance of normal distribution CDF with stdlib

v0.3.0

  • Add normal distribution
  • Use more efficient calculations of binomial PMF
  • Check for nonsense in inequality assignment

v0.2.8

  • Remove SciPy dependency by implemeting Poisson pmf with stdlib

v0.2.7

  • Fix bug in ProbabilityCalculator with resetting bounds after getting an error
  • Deal with edge case in BinomialDistribution.calculate()

v0.2.6

  • Handle edge case in binomial distributions
  • Allow Poisson to handle much larger numbers

v0.2.5

  • Add nice repr for probability calculator
  • Implement != functionality

v0.2.4

  • Fix mistake in publish workflow

v0.2.3

  • Fix bug in automated tests

v0.2.2

  • Add changelog

v0.2.1

  • Set up PyPI stuff and GitHub Action for PyPI

v0.2.0

  • Add Poisson distribution

v0.1.2

  • Fix minor issues

v0.1.1

  • Improve documentation and add alias table

0.1.0

  • Initial version
  • Add Binomial distribution
  • Add P() syntax

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

probcalc-0.5.0.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

probcalc-0.5.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file probcalc-0.5.0.tar.gz.

File metadata

  • Download URL: probcalc-0.5.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for probcalc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e64e0f5c1d8363df3f06e91630bfe8d415fc33c91bd21c075e906a51e2f801b5
MD5 a2f2ab76b4c95614ffd600fe559db59e
BLAKE2b-256 2515c5768bcc2a363e8aaba3b15e8ea6d01c4785f04a935ce56125b33fed7805

See more details on using hashes here.

File details

Details for the file probcalc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: probcalc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for probcalc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74e6c988d2b8244ca012347ee25ba5a6c671f0a315a85af4dbc4fdb97ff14508
MD5 aa4d83e6ab2bbd883028b20ba557ed3c
BLAKE2b-256 15e250c2ab0a6229335a3c33551db47794b42f334123e20fa4b204ed3ba1ed2b

See more details on using hashes here.

Supported by

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