百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

py-factorgraph

> 编程语言
开源

在 Python 中实现因子图和循环信念传播

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

在 Python 中实现因子图和循环信念传播

py-factorgraph

This is a tiny python library that allows you to build factor graphs and run the (loopy) belief propagation algorithm with ease. It depends only on numpy.

Installation

bash
pip install factorgraph

Example

Code (found in examples/simplegraph.py)

…

Run with python -m examples.simplegraph. Output:

LBP ran for 3 iterations. Converged = True

Current outgoing messages:
	b -> f(b, a) 	[ 0.33333333  0.33333333  0.33333333]
	f(a) -> a 	[ 0.3  0.7]
	a -> f(a) 	[ 0.23333333  0.76666667]
	a -> f(b, a) 	[ 0.3  0.7]
	f(b, a) -> b 	[ 0.34065934  0.2967033   0.36263736]
	f(b, a) -> a 	[ 0.23333333  0.76666667]

Marginals for RVs (normalized):
a
	 0 	 0.11538461538461539
	 1 	 0.8846153846153845
b
	 0 	 0.34065934065934067
	 1 	 0.29670329670329676
	 2 	 0.3626373626373626

Visualization

You can use factorgraph-viz to visualize factor graphs interactively in your web browser.

Tests

bash
pip install pytest-cov coveralls
py.test --cov=factorgraph tests/

Projects using py-factorgraph

Open an issue or send a PR if you'd like your project listed here.

  • verbphysics

Contributing

There's plenty of low-hanging fruit to work on if you'd like to contribute to this project. Here are some ideas:

  • Unit tests
  • Auto-generated python docs (what's popular these days?)
  • Performance: measure bottlenecks and improve them (ideas: numba; parallelization for large graphs;)
  • Remove or improve ctrl-C catching (the E_STOP)
  • Cleaning up the API (essentially duplicate constructors for RVs and Factors within the Graph code; probably should have a node superclass for RVs and Factors that pulls out common code).

Releasing

Notes for myself on how to release new versions:

bash
# Bump version in setup.py. Then,
python setup.py sdist
pip install twine
twine upload dist/*

Thanks

  • to Matthew R. Gormley and Jason Eisner for the Structured Belief Propagation for NLP Tutorial, which was extremely helpful for me in learning about factor graphs and understanding the sum product algorithm.

  • to Ryan Lester for pyfac, whose tests I used directly to test my implementation

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonfactorfactor-graphgraphlbp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言