Metadata-Version: 2.4
Name: pylea
Version: 0.1.0
Summary: Discrete probabilistic programming in Python
Author: Benedikt Peterseim
License-Expression: MIT
Project-URL: Documentation, https://benediktpeterseim.github.io/Pylea/
Project-URL: Source, https://github.com/BenediktPeterseim/Pylea
Project-URL: Issues, https://github.com/BenediktPeterseim/Pylea/issues
Keywords: probabilistic programming,exact inference,tensor networks,Bayesian networks,fault trees
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: cotengra
Requires-Dist: cotengrust
Provides-Extra: gpu
Requires-Dist: torch; extra == "gpu"
Provides-Extra: search
Requires-Dist: kahypar; extra == "search"
Requires-Dist: optuna; extra == "search"
Requires-Dist: cmaes; extra == "search"
Provides-Extra: docs
Requires-Dist: pdoc; extra == "docs"
Requires-Dist: jupytext; extra == "docs"
Requires-Dist: nbclient; extra == "docs"
Requires-Dist: nbconvert; extra == "docs"
Requires-Dist: ipykernel; extra == "docs"
Requires-Dist: matplotlib; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: matplotlib; extra == "test"
Requires-Dist: ipython; extra == "test"
Dynamic: license-file

# Pylea

Discrete probabilistic programming in Python.

Pylea computes probabilities, expected values and probability mass functions in
probabilistic models in which every variable takes only finitely many values.  A model is
written as a discrete probabilistic program (DPP): a Python function decorated with
`@DPP`, in which coin flips are drawn with `flip` and events are conditioned on with
`observe`.

## Installation

```
pip install pylea
```

Pylea requires Python 3.12 or later.  `pip install "pylea[gpu]"` also installs PyTorch,
for evaluation on a GPU, and `pip install "pylea[search]"` installs kahypar, optuna and
cmaes, which cotengra uses where installed when it searches for a contraction order for the
costliest programs (macOS and Linux only).

## Example

A disease occurs in a fraction 10⁻⁴ of the population.  A test for it is positive for 99%
of the patients who have the disease and for 2% of those who do not.  The probability that
a patient has the disease, given one positive and one negative test result:

```python
from pylea import DPP, Bool, flip, observe, prob


@DPP
def test(has_it: Bool) -> Bool:
    positive_given_disease = flip(0.99)     # true positive rate
    positive_given_no_disease = flip(0.02)  # false positive rate
    return (has_it & positive_given_disease) | (~has_it & positive_given_no_disease)


@DPP
def has_disease() -> Bool:
    x = flip(1e-4)                          # prevalence
    observe(test(x) & ~test(x))             # one positive, one negative result
    return x


print(prob(has_disease))                    # 5.0512703945042225e-05
```

## Documentation

<https://benediktpeterseim.github.io/Pylea/>

## Licence

MIT; see [LICENSE](https://github.com/BenediktPeterseim/Pylea/blob/main/LICENSE).
