Coder Social home page Coder Social logo

koaning / brent Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 5.0 1.09 MB

bayesian graphical modelling and a bit of do-calculus for discrete data.

Home Page: https://koaning.github.io/brent/

License: MIT License

Makefile 0.19% Python 23.35% Mako 0.02% Jupyter Notebook 76.44%

brent's Introduction

Build Status Build status

They're good DAGs: brent.

What it is

Brent is a small, but fun, python library that makes it easy to explore causal graphical modelling and do-calculus on systems with discrete variables. Brent is a tool that can help out when you can write a system like below, but want to write complex queries on it.

Quickstart

You can install brent via pip:

pip install brent

Next we need to have a dataset and create a graph from it. The code below demonstrates how to do this.

from brent import DAG
from brent.common import make_fake_df

dag = (DAG(dataframe=make_fake_df(7))
       .add_edge("e", "a")
       .add_edge("e", "d")
       .add_edge("a", "d")
       .add_edge("b", "d")
       .add_edge("a", "b")
       .add_edge("a", "c")
       .add_edge("b", "c")
       .add_edge("c", "f")
       .add_edge("g", "f"))
dag.plot()

Not only do we get pretty plots, but we also can build an expressive query on top of it.

from brent import Query
q = Query(dag).given(d=1).do(a=0, c=1)
q.plot()

If you're more interested in doing the inference, that's simple too.

# we can also see updated probabilities
q.infer()
q.infer(give_table=True)

Documentation

Liked the quickstart? The documentation (which is generated with pdoc3) can be found here.

Alpha Notice

NOTE! this project is in preview stages. I think I have something fun here and I've written unit tests on what I'm doing but parts are still going under review. Also there are parts of the library currently missing but which are on a roadmap:

  1. conditional indepdence tests
  2. api for counterfactual queries
  3. more unit tests
  4. datasets to start/teach with
  5. clear logging
  6. estimator/transformers for scikit-learn

Developing Locally

After cloning you may install brent in the virtual environment via:

$ pip install -e ".[dev]"

You can generate documentation locally by running:

$ pdoc --html --overwrite --template-dir doc-settings --http 0.0.0.0:12345 brent

brent's People

Contributors

koaning avatar mbrouns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

brent's Issues

implement v1 of counterfact model

this seems like a nice enough API design

q1 = Query(dag).do(a=0).given(g=1).do(b=1)
q2 = CounterFact(dag).when(q1).suppose_do(e=0).suppose_given(b=0).infer()

sklearn model needs to support NaN

Currently the sklearn model can be refactored a bit such that we can deal with missing values in the dataframe. Should add tests for this as well.

events that *never* happened

this is a graph for the RISK boardgame.

from brent import DAG, Query 
from brent.examples import generate_risk_dag

dag = generate_risk_dag()
q = Query(dag).given(losses=1).given(best_a1=1).given(best_a2=1)
q.plot()

image

when querying this we get an empty result

> q.infer()
{'d2': {},
 'best_d2': {},
 'd1': {},
 'best_d1': {},
 'a1': {},
 'a2': {},
 'a3': {},
 'best_a2': {},
 'best_a1': {},
 'losses': {}}

it's certainly not bad behavior but maybe a better way of dealing with this can be thought of.

dataset api

there's a data folder now. probably want to turn this into a proper API instead. think about file-sizes too.

names of queries

When looking at Judea Pearl's slide here it dawns on me that it might make sense to have three query objects. Might this be a nicer API design?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.