Brent
bayesian graphical modelling and a bit of do-calculus for discrete data.
Install / Use
/learn @koaning/BrentREADME

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:
- conditional indepdence tests
- api for counterfactual queries
- more unit tests
- datasets to start/teach with
- clear logging
- 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
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
