lea 1.2
Discrete probability distributions in Python
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 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.
File | Type | Py Version | Uploaded on | Size | |
---|---|---|---|---|---|
lea-1.2.tar.gz (md5) | Source | 2013-12-07 | 27KB | ||
- Downloads (All Versions):
- 8 downloads in the last day
- 52 downloads in the last week
- 353 downloads in the last month
- Author: Pierre Denis
- Home Page: http://code.google.com/p/lea/
- License: LGPL
- Package Index Owner: pdenis
- DOAP record: lea-1.2.xml