Top Banner
Machine Learning Srihari 1 1 Factor Graphs and Inference Sargur Srihari [email protected]
29

Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

May 29, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

1 1

Factor Graphs and Inference

Sargur Srihari [email protected]

Page 2: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

2 2

Topics

1.  Factor Graphs 1.  Factors in probability distributions 2.  Deriving them from graphical models

2.  Exact Inference Algorithms for Tree graphs 1.  The sum-product algorithm

1.  For finding marginal probabilities

2.  The max-sum algorithm 1.  For setting of variables that maximizes a probability 2.  For value of that probability

3.  Exact inference in general graphs

Page 3: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

3

Factors in Joint Distributions •  Joint distribution written as

–  Where xs is a subset of the variables

•  Special cases: –  Directed graphs: fs(xs) are conditional distributions

–  Undirected graphs: •  factors are potential functions over maximal cliques

)x()x( ss

sfp ∏=

p(x) = p(xk | pak )k=1

K

p(x) = 1Z

ψCC∏ (xC )

p(a,b,c)=p(c|a,b)p(b|a)p(a)

P(A,B,C,D) α exp −ε1(A,B) − ε2 (B,C) − ε3(C,D) − ε4 (D,A)[ ]Partition function Z is sum of RHS over all values of A,B,C,D

Log-linear Model

Page 4: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

4 4

Factor Graph Motivation •  Joint distributions

– Can be expressed as product of factors over subsets

•  Factor graphs make this explicit – By introducing additional nodes for factors

•  Sum-prod inference algorithm (to be defined) applicable to: – undirected, directed trees, polytrees – Has simple and general form with factor graphs – Used for determining marginal probabilities

Page 5: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

5 5

Factor Graph Example

•  Factorization p(x)=fa(x1,x2)fb(x1,x2)fc(x2,x3)fd(x3)

•  Corresponding factor graph

Two factors fa and fb of the same variables

Page 6: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

6 6

Factor graphs properties •  They are bipartite since

1.  Two types of nodes 2.  All links go between nodes of

opposite type •  Representable as two rows of

nodes –  Variables on top –  Factor nodes at bottom

•  Other intuitive representations used

–  When derived from directed/undirected graphs

Page 7: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

Deriving factor graphs from Graphical Models

•  Undirected Graph •  Directed Graph

7

Page 8: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

8 8

Conversion of Undirected to Factor Graph

•  Steps in converting distribution expressed as undirected graph: 1.  Create variable nodes

corresponding to nodes in original

2.  Create factor nodes for maximal cliques xs

3.  Factors fs(xs) set equal to clique potentials

•  Several different factor graphs possible from same distribution

Single clique potential Ψ(x1,x2,x3)

With factors f(x1,x2,x3)=Ψ(x1,x2,x3)

With factors fa(x1,x2,x3)fb(x1,x2)=Ψ(x1,x2,x3)

Page 9: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

9 9

Conversion of directed to factor graph

•  Steps 1.  Variable nodes

correspond to nodes in factor graph

2.  Create factor nodes corresponding to conditional distributions

•  Multiple factor graphs possible from same graph

Factorization p(x1)p(x2)p(x3|x1,x2)

Single Factor f(x1,x2,x3)= p(x1)p(x2)p(x3|x1,x2)

With Factors fa(x1)=p(x1) fb(x2)=p(x2) fc(x1,x2,x3)=p(x3|x1,x2)

Page 10: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

10 10

Tree to Factor Graph

•  Conversion of directed or undirected tree to factor graph is a tree –  No loops –  Only one path between 2 nodes

•  In the case of a directed polytree –  Conversion to undirected graph

has loops due to moralization –  Conversion again to factor graph

results in a tree

Directed polytree

Converted to Undirected Graph with loops

Factor Graphs

Page 11: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

11 11

Removal of local cycles

•  Local cycles in a directed graph having links connecting parents

•  Can be removed on conversion to factor graph – By defining a factor function

Factor Graph with tree structure f(x1 ,x2 ,x3 )= p(x1 ) p(x2 |x1 ) p(x3 |x1 , x2 )

Page 12: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

12 12

Multiple factor graphs for same graph

•  Factor graphs are specific about factorization

•  A fully connected undirected graph •  Joint distribution in two forms

–  In general form p(x)=f(x1 ,x2 ,x3 )

– As a specific factorization p(x)=fa (x1 ,x2 )fb (x1 ,x3 )fc (x2 ,x3 )

Page 13: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

13 13

The Sum-Product Algorithm

•  Factor graph framework used to derive – Powerful class of efficient, exact inference

Algorithm for Tree- structured Graphs •  For evaluating local marginals over

subsets of nodes – Later modified to Max-sum algorithm

Page 14: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

14 14

Sum-Product Assumptions

•  Assume that all variables are discrete – Framework applicable to linear Gaussian

models where marginalization involves integration

•  Belief Propagation is a special case of sum-product algorithm

Page 15: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

15 15

Goal of Sum-Product Algorithm

•  First convert tree structured graph to a factor graph

•  Can deal with directed/undirected using same framework

•  Goal is to exploit structure of graph to: – 1. Obtain efficient inference algorithm to find

marginals – 2. When several marginals are required, to

share computations

Page 16: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

16 16

Overview of sum-product algorithm •  Finding p(x) for a variable node •  Assume all variables are hidden

– Marginal is defined as

– Substitute for p(x) the factor-graph expression

–  Interchange summations and products for efficiency

Set of variables with x removed

Page 17: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

17 17

Expressing as subtrees

•  Fragment of graph •  Tree structure allows

partitioning factors into groups

Set of nodes that are neighbors of x

Set of variables in sub-tree connected to x via factor node fs

Product of all factors in group associated with factor fs

Page 18: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

18

Messages from factor node to variable nodes

•  Substituting into p(x)

∏ ∑

∈→

=

⎥⎦

⎤⎢⎣

⎡=

ne(x)sxf

ne(x)s Xss

(x)µ

)(x,XFp(x)

s

s

Where, a set of function are defined as

∑=→

s

sX

ssxf )(x,XF(x)µ

Which are viewed as messages from factor nodes to variable node •  is product of all incoming messages at node

sf xp(x) x

Page 19: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

19

Messages from variable to factor nodes •  Each factor is described by a factor subgraph

–  Can itself be factored as

•  Resubstituting

)(x,XF ss

),x(x)G,...,x(x,xf)(x,XF sMMMMsss 1=

∑ ∑ ∏ ∑∈

→ ⎥⎦

⎤⎢⎣

⎡=

1

1x x )\xne(fm X

smm,mMsxfM s xm

s)X(xG),...,x(x,xf..(x)µ

)(xµ mfx sm→

To evaluate message sent by a factor node: •  Take product of incoming messages into factor node •  Multiply by factor associated with the node •  Marginalize over all variables associated with incoming messages

Page 20: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

20

Evaluating messages from variable nodes to factor nodes

•  Making use of sub-graph factorization

•  Substituting into expression for

•  Simply take product of incoming messages along other links

)(xµ mfx sm→

∏∈

=sm )\fne(xl

mlmlsmmm ),X(xF),X(xG

∏∈

→→ =sm

mlsm)\fne(xl

mxfmfx )(xµ)(xµ

Page 21: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

21

Sum-Product Algorithm Messages

•  Goal is to calculate marginal for variable node

•  Given by product of incoming message along all links arriving at node

•  If leaf node is a variable node then it sends

•  If leaf node is factor node it sends

x

1=→ (x)µ fx

f(x)(x)µ xf =→

Variable Node

Factor Node

Page 22: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

22

Summary of sum-product algorithm

•  To evaluate the marginal –  View node x as the root of the factor graph –  Initiate messages at leaves using

–  The message passing steps are applied recursively •  Until messages are propagated along every link •  And root node has received messages from all its neighbors

–  Required marginal is evaluated using

p(x)

1=→ (x)µ fx f(x)(x)µ xf =→

∏ ∑

∈→

=

⎥⎦

⎤⎢⎣

⎡=

ne(x)sxf

ne(x)s Xss

(x)µ

)(x,XFp(x)

s

s

Page 23: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

23

Finding marginal for every node

•  Need not run algorithm afresh for each node •  More efficient approach

–  Overlay multiple message passing algorithms to get general message passing algorithm

•  Pick any variable or factor node as root •  Propagate message from root to the leaves

Page 24: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

24

Marginal for set of variables in a factor

•  Marginal associated with a factor is –  Product of messages arriving at factor node

and –  Local factor at the node, i.e.,

∏∈

→=)ne(fi

ifxssss

si)(xµ)(xf)p(x

Page 25: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

25

Sum-product view as messages from factor nodes

•  Viewed purely as messages sent by factor nodes to other factor nodes

•  Outgoing message (blue arrow) is obtained by –  Taking product of all incoming

messages (green arrows) –  Multiplying by factor –  Marginalized over variables and

sf

1x2x

Page 26: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

26

Normalization •  If factor graph derived from a directed graph

–  then joint distribution is correctly normalized –  So marginals will be normalized correctly

•  If stated from undirected graph –  Need normalization coefficient

•  First run sum-product algorithm to find unnormalized marginals

•  Normalize any one of these marginals to obtain )(xp i

~

/Z1

/Z1

Page 27: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

27

Sum product algorithm illustration

•  Four-node factor graph with joint distribution

•  Designate as root node –  Then leaf nodes are and

•  Starting with leaf node there are a sequence of six messages

),x(x)f,x(x)f,x(xf(x)p cba 423221~ =

3x1x 4x

Page 28: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

28

Messages from leaf nodes

→→

→→→

=

=

=

=

=

=

2

23

222

4

2

4

1

2

1

323

222

422

4

212

1

1

1

xfxbxf

xfxffx

xcxf

fx

xaxf

fx

bb

cab

c

c

a

a

)µ,x(xf)(xµ

)(x)µ(xµ)(xµ

),x(xf)(xµ

)(xµ

),x(xf)(xµ

)(xµ

Page 29: Factor Graphs and Inference - University at Buffalosrihari/CSE674/Chap4/4... · 2. Exact Inference Algorithms for Tree graphs 1. The sum-product algorithm 1. For finding marginal

Machine Learning ! ! ! ! ! Srihari

29

Messages from root node to leaf nodes

→→

→→→

→→

→→→

=

=

=

=

=

=

2

24

222

2

21

222

3

2

3

2424

222

2211

222

322

3 1

xfxcxf

xfxffx

xfxaxf

xfxffx

xbxf

fx

)(x)µ,x(xf)(xµ

)(x)µ(xµ)(xµ

)(x)µ,x(xf)(xµ

)(x)µ(xµ)(xµ

),x(xf)(xµ

)(xµ

cc

bac

ab

bba

b

b