Metadata-Version: 2.1
Name: BayNet
Version: 0.2.2
Summary: (another) Python Bayesian Network library
Home-page: https://github.com/Stoffle/BayNet
Author: Chris Robinson
Author-email: c.f.robinson@sussex.ac.uk
License: UNKNOWN
Platform: UNKNOWN
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: python-igraph (<0.8.0)
Requires-Dist: numpy (>=1.17.2)
Requires-Dist: pandas (>=0.25)
Requires-Dist: protobuf
Requires-Dist: graphviz
Requires-Dist: pyparsing
Provides-Extra: ci
Requires-Dist: pytest (>=3.3.2) ; extra == 'ci'
Requires-Dist: pytest-cov (>=2.6.0) ; extra == 'ci'
Requires-Dist: networkx ; extra == 'ci'
Provides-Extra: dev
Requires-Dist: black ; extra == 'dev'
Requires-Dist: mypy (>=0.720) ; extra == 'dev'
Requires-Dist: pylint (>=2.0) ; extra == 'dev'
Requires-Dist: pytest (>=3.3.2) ; extra == 'dev'
Requires-Dist: pytest-cov (>=2.6.0) ; extra == 'dev'
Requires-Dist: pre-commit ; extra == 'dev'
Requires-Dist: pydocstyle ; extra == 'dev'
Requires-Dist: networkx ; extra == 'dev'

# BayNet

BayNet is a Python library for generating, sampling data from, comparing, and visualising Bayesian Networks.

## Installation
```bash
pip install BayNet
```

## Usage
### Generate a 10-node Forest Fire DAG, and parameters, then sample data from it:
```python
from baynet import DAG
dag = DAG.forest_fire(10, .5, seed=1) # Creates a DAG
dag.generate_discrete_parameters(seed=1) # Samples parameters for each node
data = dag.sample(1_000) # Samples data, returning a pandas DataFrame
```
### Generate a 5-node Barabasi-Albert (preferential attachment) graph and plot it:
```python
from baynet import DAG
DAG.barabasi_albert(5, seed=1).plot() # Saves 'DAG.png' in working directory
```
![Example DAG.png](example_DAG.png)


### Generate two 5-node Erdos-Renyi DAGs and compare them:
```python
from baynet import DAG, metrics
dag_1 = DAG.erdos_renyi(5, 0.5, seed=1)
dag_2 = DAG.erdos_renyi(5, 0.5)
print(metrics.shd(dag_1, dag_2)) # prints DAG SHD, in this case 6
print(metrics.shd(dag_1, dag_2, skeleton=True)) # prints skeleton SHD, in this case 3
dag_1.compare(dag_2).plot() # saves 'comparison.png' in working directory
```
![Example comparison.png](example_comparison.png)

Taking dag_1 to be the ground truth and dag_2 to be a structure learning result:
- Dashed red arcs represent false negatives
- Blue arcs are represent positives
- Green arcs represent incorrectly directed arcs





