Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Moving to a functional interface #88

Merged
merged 56 commits into from
Nov 1, 2021

Conversation

StannisZhou
Copy link
Contributor

@StannisZhou StannisZhou commented Oct 26, 2021

This PR moves PGMax to a functional interface.

Main changes to the interface (resolves #82):

  • Instead of generating init_msgs from FactorGraph and rely on a member function (run_bp) to run belief propagation, we derive an immutable FactorGraphState based on added factors to a factor graph, and use the FactorGraphState to initialize a BPState.
  • A BP function then takes a BPState and generates 3 pure functions:
    1. run_bp, which takes log_potentials/ftov_msgs/evidence updates specified in regular python dictionaries, and outputs a BPArrays containing results after BP.
    2. get_bp_state which constructs a BPState from a BPArrays
    3. get_beliefs which calculates beliefs from a BPArrays.

The functional approach allows easy use of regular function transformations in JAX like vmap, grad. See examples/ising_model.py and examples/rbm.py for some added examples on using vmap and grad with the new functional interface. Resolves #68.

Also made various refactors/cleanups (e.g. for unit tests/docstrings/naming, etc.). Resolves #75. Resolves #71.

Copy link
Contributor

@NishanthJKumar NishanthJKumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after last couple minor comments addressed! Great work - really exciting to see the codebase this mature!

@StannisZhou StannisZhou merged commit e4f7208 into vicariousinc:master Nov 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants