Thomas, a library for working with Bayesian Networks.
Project description
Thomas
Very simple (almost naive ;-) bayesian network implementation.
Contains examples (thomas.core.examples
) from the book "Probabilistic
Graphical Models: Principles and Techniques" from Koller and Friedman (PGM
Stanford) and from the lecture by Adnan
Darwiche on YouTube:
- 6a. Inference by Variable Elimination I (Chapter 6).
- 6b. Inference by Variable Elimination II (Chapter 6).
Table of contents
Regular installation
To install the latest version from PyPI:
pip install thomas-core
Additional packages
If you're using JupyterLab, I recommend also installing the Widget that can display Bayesian Networks.
pip install thomas-jupyter-widget
See the repository (or the screenshot above) for details on how to use it.
Alternatives
If you don't feel like installing thomas locally, there are two alternative ways to give the platform a try.
Docker
If you have docker available, the following command will start a JupyterLab server listening on http://localhost:8888:
docker run --rm -it -p 8888:8888 mellesies/thomas-core
Binder
mybinder.org courteously provides an environment where you can try out Thomas without any local installation. Just click here (or the badge above) and after some waiting, JupyterLab should open in your browser.
You can also directly open one of the example notebooks:
- notebooks/1. Factors.ipynb
- notebooks/2. Bags of factors.ipynb
- notebooks/3. Conditional probability tables.ipynb
- notebooks/4. Bayesian Networks.ipynb
Usage
To get started with querying a network, launch python3
and try the following:
from thomas.core import examples
# Load an example network
Gs = examples.get_student_network()
# This should output the prior probability of random variable 'S' (SAT score).
print(Gs.P('S'))
print()
# Expected output:
# P(S)
# S
# s0 0.725
# s1 0.275
# dtype: float64
# Query for the conditional probability of S given the student is intelligent.
print(Gs.P('S|I=i1'))
# Expected output:
# P(S)
# S
# s0 0.2
# s1 0.8
# dtype: float64
Development installation
To do a development install:
git clone https://github.com/mellesies/thomas-core
cd thomas-core
pip install -e .
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
Built Distribution
File details
Details for the file thomas-core-0.1.3.tar.gz
.
File metadata
- Download URL: thomas-core-0.1.3.tar.gz
- Upload date:
- Size: 98.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e87354eaab0026c950c140b429a4bbb3049a3860ca9420842fd30cc30ff179b9 |
|
MD5 | 5c0d02235a039103b57a5fc0eb71a5cd |
|
BLAKE2b-256 | 7fc6b2467b4a1c13af36f3e85f4832739988010eef71bee46fe5df0304a60d41 |
File details
Details for the file thomas_core-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: thomas_core-0.1.3-py3-none-any.whl
- Upload date:
- Size: 108.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d991868454f35e5c5cdc18229af5128904b6b4d2dd50ef67295b3ec2aea5e1e9 |
|
MD5 | d0f35505d5b7208f9dcb3864e7b60535 |
|
BLAKE2b-256 | 7bccf1a7cf81d288cffe21658a9317731c984511c950ef4c38ee256d65ce4076 |