object BeliefPropagation
Example code for Belief Propagation (BP)
This provides a template for building customized BP algorithms for different types of graphical models.
This example:
- Ising model on a grid
- Parallel Belief Propagation using colored fields
Ising models are probabilistic graphical models over binary variables xi. Each binary variable xi corresponds to one vertex, and it may take values -1 or +1. The probability distribution P(X) (over all xi) is parameterized by vertex factors ai and edge factors bij:
P(X) = (1/Z) * exp[ \sum_i a_i x_i + \sum_{ij} b_{ij} x_i x_j ]
where Z is the normalization constant (partition function). See Wikipedia for more information on Ising models.
Belief Propagation (BP) provides marginal probabilities of the values of the variables xi, i.e., P(xi) for each i. This allows a user to understand likely values of variables. See Wikipedia for more information on BP.
We use a batch synchronous BP algorithm, where batches of vertices are updated synchronously. We follow the mean field update algorithm in Slide 13 of the talk slides from: Wainwright. "Graphical models, message-passing algorithms, and convex optimization."
The batches are chosen according to a coloring. For background on graph colorings for inference, see for example: Gonzalez et al. "Parallel Gibbs Sampling: From Colored Fields to Thin Junction Trees." AISTATS, 2011.
The BP algorithm works by:
- Coloring the graph by assigning a color to each vertex such that no neighboring vertices share the same color.
- In each step of BP, update all vertices of a single color. Alternate colors.
- Alphabetic
- By Inheritance
- BeliefPropagation
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- case class EdgeAttr(b: Double) extends Product with Serializable
- case class VertexAttr(a: Double, belief: Double, color: Int) extends Product with Serializable
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def main(args: Array[String]): Unit
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
runBPwithGraphFrames(g: GraphFrame, numIter: Int): GraphFrame
Run Belief Propagation.
Run Belief Propagation.
This implementation of BP shows how to use GraphFrame's aggregateMessages method.
- Color GraphFrame vertices for BP scheduling.
- Run BP using GraphFrame's aggregateMessages API.
- Augment the original GraphFrame with the BP results (vertex beliefs).
- g
Graphical model created by
org.graphframes.examples.Graphs.gridIsingModel()
- numIter
Number of iterations of BP to run. One iteration includes updating each vertex's belief once.
- returns
Same graphical model, but with GraphFrame.vertices augmented with a new column "belief" containing P(xi = +1), the marginal probability of vertex i taking value +1 instead of -1.
-
def
runBPwithGraphX(g: GraphFrame, numIter: Int): GraphFrame
Run Belief Propagation.
Run Belief Propagation.
This implementation of BP shows how to use GraphX's aggregateMessages method. It is simple to convert to and from GraphX format. This method does the following:
- Color GraphFrame vertices for BP scheduling.
- Convert GraphFrame to GraphX format.
- Run BP using GraphX's aggregateMessages API.
- Augment the original GraphFrame with the BP results (vertex beliefs).
- g
Graphical model created by
org.graphframes.examples.Graphs.gridIsingModel()
- numIter
Number of iterations of BP to run. One iteration includes updating each vertex's belief once.
- returns
Same graphical model, but with GraphFrame.vertices augmented with a new column "belief" containing P(xi = +1), the marginal probability of vertex i taking value +1 instead of -1.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )