Skip to main content

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

Metadata

Release files for probcalc 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for probcalc 0.5.0
File Size Uploaded
probcalc-0.5.0.tar.gz 22.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for probcalc 0.5.0
File Interpreter ABI Platform
probcalc-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / probcalc-0.5.0.tar.gz

Download URL probcalc-0.5.0.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e64e0f5c1d8363df3f06e91630bfe8d415fc33c91bd21c075e906a51e2f801b5
BLAKE2b-256 checksum
How to use checksums
2515c5768bcc2a363e8aaba3b15e8ea6d01c4785f04a935ce56125b33fed7805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / probcalc-0.5.0-py3-none-any.whl

Download URL probcalc-0.5.0-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74e6c988d2b8244ca012347ee25ba5a6c671f0a315a85af4dbc4fdb97ff14508
BLAKE2b-256 checksum
How to use checksums
15e250c2ab0a6229335a3c33551db47794b42f334123e20fa4b204ed3ba1ed2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page