sumproduct
===========
An implementation of Belief Propagation for factor graphs, also known as
the sum product algorithm.
.. figure:: http://f.cl.ly/items/2P021j2y3A2Q191F451h/unnamed0.png
:alt: Simple factor graph
Simple factor graph
The factor graph used in ``test.py``.
Usage
-----
Check ``test.py`` for details, but:
Create a factor graph
~~~~~~~~~~~~~~~~~~~~~
::
g = FactorGraph() # init the graph
x1 = Variable('x1', 2) # init a variable with 2 states
x2 = Variable('x2', 3) # init a variable with 3 states
f12 = Factor('f12', np.array([
[0.8,0.2],
[0.2,0.8],
[0.5,0.5]
])) # create a factor node potentials for p(x1 | x2)
# connect the parents to their children
g.add(f12)
g.append('f12', x2)
g.append('f12', x1)
Run Inference
~~~~~~~~~~~~~
sum-product algorithm
^^^^^^^^^^^^^^^^^^^^^
::
g.compute_marginals(max_iter=500, tolerance=1e-6)
g.nodes['x1'].marginal()
Brute force marginalization and conditioning
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The sum-product algorithm can only compute exact marginals for acyclic
graphs. Check against the brute force method (at great computational
expense) if you have a loopy graph.
::
res = g.brute_force()
g.nodes['x1'].bfmarginal
Implementation Details
----------------------
See block comments in the code's methods for details, but implementation
strategy comes from Chapter 5 of `David Barber's
book <http://web4.cs.ucl.ac.uk/staff/D.Barber/pmwiki/pmwiki.php?n=Brml.HomePage>`__.
===========
An implementation of Belief Propagation for factor graphs, also known as
the sum product algorithm.
.. figure:: http://f.cl.ly/items/2P021j2y3A2Q191F451h/unnamed0.png
:alt: Simple factor graph
Simple factor graph
The factor graph used in ``test.py``.
Usage
-----
Check ``test.py`` for details, but:
Create a factor graph
~~~~~~~~~~~~~~~~~~~~~
::
g = FactorGraph() # init the graph
x1 = Variable('x1', 2) # init a variable with 2 states
x2 = Variable('x2', 3) # init a variable with 3 states
f12 = Factor('f12', np.array([
[0.8,0.2],
[0.2,0.8],
[0.5,0.5]
])) # create a factor node potentials for p(x1 | x2)
# connect the parents to their children
g.add(f12)
g.append('f12', x2)
g.append('f12', x1)
Run Inference
~~~~~~~~~~~~~
sum-product algorithm
^^^^^^^^^^^^^^^^^^^^^
::
g.compute_marginals(max_iter=500, tolerance=1e-6)
g.nodes['x1'].marginal()
Brute force marginalization and conditioning
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The sum-product algorithm can only compute exact marginals for acyclic
graphs. Check against the brute force method (at great computational
expense) if you have a loopy graph.
::
res = g.brute_force()
g.nodes['x1'].bfmarginal
Implementation Details
----------------------
See block comments in the code's methods for details, but implementation
strategy comes from Chapter 5 of `David Barber's
book <http://web4.cs.ucl.ac.uk/staff/D.Barber/pmwiki/pmwiki.php?n=Brml.HomePage>`__.
Metadata
Release files for sumproduct 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sumproduct-0.0.1.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sumproduct-0.0.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 15.0 kB
Release files / sumproduct-0.0.1.tar.gz
| Download URL | sumproduct-0.0.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abeae1bc306f273da3443d7ac39fa85bdcdff1644a8b0c149c208f6d8297c462
|
|
BLAKE2b-256 checksum How to use checksums |
06b447dfa73df423114b486399dd29384df165e932093db17bf9d8f4b7162ddb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / sumproduct-0.0.1-py2.py3-none-any.whl
| Download URL | sumproduct-0.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
20c02612ba0d2befe4393bca1b8e05a962481374de6ef4d534c920132a909a05
|
|
BLAKE2b-256 checksum How to use checksums |
0a8cddd2e28d2035b22e7db235e3e5787d0f3143eb4d4e61cabcd929dc8b00a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |