Skip to main content

Discrete probability distributions in Python

Project description

NEW: works with Python 3.x!

Lea is a Python package aiming at working with discrete probability distributions in an intuitive way. It allows you to model a broad range of random phenomenons, like dice throwing, coin tossing, cards hands, gambling, lottery, … with fair or unfair characteristics! More generally, Lea may be used for any finite set of discrete values having known probability: numbers, boolean variables (true/false), date/times, symbols, … Each distribution is modelled as a plain object, which can be named, displayed, queried or processed to produce new distribution objects.

As a basic example, the statements below define and display the probability distribution of one fair die.:

>>> die1 = Lea.fromVals(1,2,3,4,5,6)
>>> die1
1 : 1/6
2 : 1/6
3 : 1/6
4 : 1/6
5 : 1/6
6 : 1/6

From a given probability distribution, you are able to get the usual distribution indicators (mean, variance, etc). You may also ask to generate random samples of values with respect to that distribution, which maybe non-uniform (i.e. some value are more likely to occur than others).

Probably the most special feature of Lea is that it allows you to compute new probability distributions from existing ones, by using different transformation means: arithmetic operators, logical operators, functions, attribute retrieving and cartesian product. For example, assuming that die1 and die2 refer to distributions of the result of two thrown dice, then the expression die1 + die2 shall build the distribution of the sum of the results of these two dice. This is shown in the statements below.:

>>> die2 = die1.clone()
>>> die1 + die2
 2 : 1/36
 3 : 2/36
 4 : 3/36
 5 : 4/36
 6 : 5/36
 7 : 6/36
 8 : 5/36
 9 : 4/36
10 : 3/36
11 : 2/36
12 : 1/36

Furthermore, you may derive new Lea distributions from existing ones by specifying logical conditions, which shall constrain the set of possible values (conditional probability).

Here are the main Lea’s features, from a user point of view:

  • allows to define finite discrete probability distributions

  • provides standard distribution indicators

  • comprehensive set of operations to derive distributions from existing ones

  • conditional probabilities

  • easy to use

  • usable in Python interactive interpreter or in application files

  • Open-source project, LGPL license

From a technical / programming perspective, Lea has the following characteristics:

  • pure Python module, lightweight - no package dependency

  • requires Python 3.x or Python 2.x, starting from 2.5

  • OO design: one abstract class, Lea, and eight subclasses

  • probabilities stored as integers, hence no accuracy issues due to floating-point arithmetics

  • heavily relies on Python operator overloading and lazy evaluation (computations done as late as possible)

  • uses a generalised convolution algorithm

Lea presents, in its current version, some limitations or liabilities:

  • no formal test suite

  • no predefined standard distributions

  • not scalable, maybe inefficient for some calculation

These limitations may be addressed in future versions.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lea-1.3.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

lea-1.3.macosx-10.6-intel.tar.gz (47.5 kB view details)

Uploaded Source

File details

Details for the file lea-1.3.tar.gz.

File metadata

  • Download URL: lea-1.3.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lea-1.3.tar.gz
Algorithm Hash digest
SHA256 18af83fd23ca3017dc506ddc5ac09a8f733c3206d24d6b18a67c17a3ff8bdc27
MD5 3099fe3f642362e200aa38cb6bdb376e
BLAKE2b-256 d79b88b921fbf2b0342fe647657cc7f23eb650063f50b2a5dda92079d07baed4

See more details on using hashes here.

File details

Details for the file lea-1.3.macosx-10.6-intel.tar.gz.

File metadata

File hashes

Hashes for lea-1.3.macosx-10.6-intel.tar.gz
Algorithm Hash digest
SHA256 c8ce4d898703354661d11e5ffacacfc520310f0bab5025eddaa63ded2d8c8913
MD5 7c4e35a19c2dbbb43cf276aa07d1b1cb
BLAKE2b-256 e5160dcd27cb84f53fe6575185018056efcdd3bcbd95a8963993a83e869fc7ff

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