Probabilistic Inference (CO-493)
Graphical ModelsMarc Deisenroth
Department of ComputingImperial College London
January 15, 2019
Probabilistic Pipeline
Build model Discover patterns Predict and explore
Criticize model
Adopted from NIPS-2016 Tutorial by Blei et al.
Assumptions Data
§ Use knowledge and assumptions about the data to build a model§ Use model and data to discover patterns§ Predict and explore§ Criticize/revise the model
Inference is the key algorithmic problem:What does the model say about the data?Goal: general and scalable approaches to inference
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 2
Probabilistic Pipeline
Build model Discover patterns Predict and explore
Criticize model
Adopted from NIPS-2016 Tutorial by Blei et al.
Assumptions Data
§ Use knowledge and assumptions about the data to build a model§ Use model and data to discover patterns§ Predict and explore§ Criticize/revise the modelInference is the key algorithmic problem:What does the model say about the data?Goal: general and scalable approaches to inference
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 2
Probabilistic Machine Learning
§ Probabilistic model: Joint distribution of latent variables z andobserved variables x (data):
ppx, zq
§ Inference: Learning about the unknowns z through the posteriordistribution
ppz|xq “ppx, zqppxq
, ppxq “ż
ppx|zqppzqdz
§ Normally: Denominator (marginal likelihood/evidence)intractable (i.e., we cannot compute the integral analytically)
Approximate inference to get the posterior
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 3
Probabilistic Machine Learning
§ Probabilistic model: Joint distribution of latent variables z andobserved variables x (data):
ppx, zq
§ Inference: Learning about the unknowns z through the posteriordistribution
ppz|xq “ppx, zqppxq
, ppxq “ż
ppx|zqppzqdz
§ Normally: Denominator (marginal likelihood/evidence)intractable (i.e., we cannot compute the integral analytically)
Approximate inference to get the posterior
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 3
Probabilistic Machine Learning
§ Probabilistic model: Joint distribution of latent variables z andobserved variables x (data):
ppx, zq
§ Inference: Learning about the unknowns z through the posteriordistribution
ppz|xq “ppx, zqppxq
, ppxq “ż
ppx|zqppzqdz
§ Normally: Denominator (marginal likelihood/evidence)intractable (i.e., we cannot compute the integral analytically)
Approximate inference to get the posterior
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 3
Some Options for Posterior Inference
§ Exact inference (in some cases)§ Conjugate models (see CO-496 for some examples)§ Belief propagation and sum-product algorithm (Lauritzen &
Spiegelhalter, 1988; Kschischang et al., 2001)
§ Approximate inference§ Sampling and Markov Chain Monte Carlo (to sample from the
posterior)§ Laplace approximation§ Expectation propagation (Minka, 2001)§ Variational inference (Jordan et al., 1999)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 4
Graphical Models
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 5
Reading Material
Bishop: Pattern Recognition and Machine Learning, Chapter 8
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 6
Probabilistic Models
§ Quantity of interest: Joint distribution ppx, zq “ ppzqppx|zq of allobserved x and unobserved (latent) z random variables
Probabilistic model
§ Comprises information about the prior, the likelihood and theposterior
§ Joint distribution ppx, zq itself can be complicated
§ Does not tell us anything about structural properties of theprobabilistic model (e.g., factorization, independence)
Probabilistic graphical models
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 7
Probabilistic Models
§ Quantity of interest: Joint distribution ppx, zq “ ppzqppx|zq of allobserved x and unobserved (latent) z random variables
Probabilistic model
§ Comprises information about the prior, the likelihood and theposterior
§ Joint distribution ppx, zq itself can be complicated
§ Does not tell us anything about structural properties of theprobabilistic model (e.g., factorization, independence)
Probabilistic graphical models
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 7
Probabilistic Graphical Models
a b
c
a b
c
a b
c
Three types of probabilistic graphical models:§ Bayesian networks (directed graphical models)§ Markov random fields (undirected graphical models)§ Factor graphs
§ Nodes: (Sets of) random variables§ Edges: Probabilistic/functional relations between variablesGraph captures the way in which the joint distribution over all
random variables can be decomposed into a product of factorsdepending only on a subset of these variables
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 8
Probabilistic Graphical Models
a b
c
a b
c
a b
c
Three types of probabilistic graphical models:§ Bayesian networks (directed graphical models)§ Markov random fields (undirected graphical models)§ Factor graphs
§ Nodes: (Sets of) random variables§ Edges: Probabilistic/functional relations between variables
Graph captures the way in which the joint distribution over allrandom variables can be decomposed into a product of factorsdepending only on a subset of these variables
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 8
Probabilistic Graphical Models
a b
c
a b
c
a b
c
Three types of probabilistic graphical models:§ Bayesian networks (directed graphical models)§ Markov random fields (undirected graphical models)§ Factor graphs
§ Nodes: (Sets of) random variables§ Edges: Probabilistic/functional relations between variablesGraph captures the way in which the joint distribution over all
random variables can be decomposed into a product of factorsdepending only on a subset of these variables
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 8
Why are they useful?
§ Simple way to visualize the structure of a probabilistic model
§ Insights into properties of the model (e.g., conditionalindependence) by inspection of the graph
§ Can be used to design/motivate new models
§ Complex computations for inference and learning can beexpressed in terms of graphical manipulations
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 9
Why are they useful?
§ Simple way to visualize the structure of a probabilistic model
§ Insights into properties of the model (e.g., conditionalindependence) by inspection of the graph
§ Can be used to design/motivate new models
§ Complex computations for inference and learning can beexpressed in terms of graphical manipulations
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 9
Why are they useful?
§ Simple way to visualize the structure of a probabilistic model
§ Insights into properties of the model (e.g., conditionalindependence) by inspection of the graph
§ Can be used to design/motivate new models
§ Complex computations for inference and learning can beexpressed in terms of graphical manipulations
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 9
Why are they useful?
§ Simple way to visualize the structure of a probabilistic model
§ Insights into properties of the model (e.g., conditionalindependence) by inspection of the graph
§ Can be used to design/motivate new models
§ Complex computations for inference and learning can beexpressed in terms of graphical manipulations
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 9
Importance of Visualization
From Kim et al. (NIPS, 2015)
From Kim et al. (NIPS, 2015)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 10
Importance of Visualization
From Kim et al. (NIPS, 2015)
From Kim et al. (NIPS, 2015)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 10
Bayesian Networks (Directed Graphical Models)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 11
Directed Graphical Models
a
e
d
b
c
§ Nodes: Random variables
§ Shaded nodes: Observed random variables
§ Unshaded nodes: Unobserved (latent) random variables
§ Directed arrow from a to b: Conditional distribution ppb|aq.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 12
From Joints to Graphs
Consider the joint distribution
ppa, b, cq “ ppc|a, bqppb|aqppaq
Building the corresponding graphical model:
1. Create a node for all random variables
2. For each conditional distribution, we add a directed link (arrow)to the graph from the nodes corresponding to the variables onwhich the distribution is conditioned on
a b
c
Graph layout depends on the choice of factorization
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 13
From Joints to Graphs
Consider the joint distribution
ppa, b, cq “ ppc|a, bqppb|aqppaq
Building the corresponding graphical model:
1. Create a node for all random variables
2. For each conditional distribution, we add a directed link (arrow)to the graph from the nodes corresponding to the variables onwhich the distribution is conditioned on
a b
c
Graph layout depends on the choice of factorization
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 13
From Joints to Graphs
Consider the joint distribution
ppa, b, cq “ ppc|a, bqppb|aqppaq
Building the corresponding graphical model:
1. Create a node for all random variables
2. For each conditional distribution, we add a directed link (arrow)to the graph from the nodes corresponding to the variables onwhich the distribution is conditioned on
a b
c
Graph layout depends on the choice of factorizationGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 13
From Graphs to Joints
x1 x2
x3 x4
x5
§ Joint distribution is the product of a set of conditionals, one foreach node in the graph
§ Each conditional depends only on the parents of thecorresponding node in the graph
ppx1, x2, x3, x4, x5q “ ppx1qppx5qppx2|x5qppx3|x1, x2qppx4|x2q
In general: ppxq “ ppx1, . . . , xKq “śK
k“1 ppxk|parentspxkqq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 14
From Graphs to Joints
x1 x2
x3 x4
x5
§ Joint distribution is the product of a set of conditionals, one foreach node in the graph
§ Each conditional depends only on the parents of thecorresponding node in the graph
ppx1, x2, x3, x4, x5q “ ppx1qppx5qppx2|x5qppx3|x1, x2qppx4|x2q
In general: ppxq “ ppx1, . . . , xKq “śK
k“1 ppxk|parentspxkqq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 14
From Graphs to Joints
x1 x2
x3 x4
x5
§ Joint distribution is the product of a set of conditionals, one foreach node in the graph
§ Each conditional depends only on the parents of thecorresponding node in the graph
ppx1, x2, x3, x4, x5q “ ppx1qppx5qppx2|x5qppx3|x1, x2qppx4|x2q
In general: ppxq “ ppx1, . . . , xKq “śK
k“1 ppxk|parentspxkqq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 14
From Graphs to Joints
x1 x2
x3 x4
x5
§ Joint distribution is the product of a set of conditionals, one foreach node in the graph
§ Each conditional depends only on the parents of thecorresponding node in the graph
ppx1, x2, x3, x4, x5q “ ppx1qppx5qppx2|x5qppx3|x1, x2qppx4|x2q
In general: ppxq “ ppx1, . . . , xKq “śK
k“1 ppxk|parentspxkqq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 14
Graphical Model for (Bayesian) Linear Regression
x
t
0 1
−1
0
1
From PRML (Bishop, 2006)
We are given a data setpx1, y1q, . . . , pxN , yNqwhere
yi “ f pxiq ` ε, ε „ N`
0, σ2˘
with f unknown.Find a (regression) model that
explains the data
§ Consider polynomials f pxq “řM
j“0 wjxj with parametersw “ rw0, . . . , wMs
J.§ Bayesian linear regression: Place a conjugate Gaussian prior on
the parameters: ppwq “ N`
0, α2I˘
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 15
Graphical Model for (Bayesian) Linear Regression
x
t
0 1
−1
0
1
From PRML (Bishop, 2006)
We are given a data setpx1, y1q, . . . , pxN , yNqwhere
yi “ f pxiq ` ε, ε „ N`
0, σ2˘
with f unknown.Find a (regression) model that
explains the data
§ Consider polynomials f pxq “řM
j“0 wjxj with parametersw “ rw0, . . . , wMs
J.§ Bayesian linear regression: Place a conjugate Gaussian prior on
the parameters: ppwq “ N`
0, α2I˘
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 15
Graphical Model for Linear Regression
x
t
0 1
−1
0
1
From PRML (Bishop, 2006)
ppy|xq “ N`
y | f pxq, σ2˘
f pxq “Mÿ
j“0
wjxj
ppwq “ N`
0, α2I˘
w
y1 yN
w
yn
n = 1, ..., N
α w
x n yn σ
n = 1, ..., N
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 16
Graphical Model for Linear Regression
x
t
0 1
−1
0
1
From PRML (Bishop, 2006)
ppy|xq “ N`
y | f pxq, σ2˘
f pxq “Mÿ
j“0
wjxj
ppwq “ N`
0, α2I˘
w
y1 yN
w
yn
n = 1, ..., N
α w
x n yn σ
n = 1, ..., N
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 16
Graphical Model for Linear Regression
x
t
0 1
−1
0
1
From PRML (Bishop, 2006)
ppy|xq “ N`
y | f pxq, σ2˘
f pxq “Mÿ
j“0
wjxj
ppwq “ N`
0, α2I˘
w
y1 yN
w
yn
n = 1, ..., N
α w
x n yn σ
n = 1, ..., N
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 16
Conditional Independence
a b
c
a KK b|c ðñ ppa|b, cq “ ppa|cqðñ ppa, b|cq “ ppa|cqppb|cq
§ (Conditional) independence allows for a factorization of the jointdistribution More efficient inference
§ Conditional independence properties of the joint distribution canbe read directly from the graph
§ No analytical manipulations required.d-separation (Pearl, 1988)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 17
D-Separation (Directed Graphs)
AC
B
Directed, acyclic graph in which A, B, Care arbitrary, non-intersecting sets ofnodes. Does A KK B|C hold?Note: C is observed if we condition on it(and the nodes in the GM are shaded)
Consider all possible paths from any node in A to any node in B.Any such path is blocked if it includes a node such that either
§ Arrows on the path meet either head-to-tail or tail-to-tail at thenode, and the node is in the set C or
§ Arrows meet head-to-head at the node and neither the node norany of its descendants is in the set C
If all paths are blocked, then A is d-separated (conditionally indep.)from B by C, and the joint distribution satisfies A KK B|C.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 18
D-Separation (Directed Graphs)
AC
B
Directed, acyclic graph in which A, B, Care arbitrary, non-intersecting sets ofnodes. Does A KK B|C hold?Note: C is observed if we condition on it(and the nodes in the GM are shaded)
Consider all possible paths from any node in A to any node in B.
Any such path is blocked if it includes a node such that either§ Arrows on the path meet either head-to-tail or tail-to-tail at the
node, and the node is in the set C or§ Arrows meet head-to-head at the node and neither the node nor
any of its descendants is in the set CIf all paths are blocked, then A is d-separated (conditionally indep.)from B by C, and the joint distribution satisfies A KK B|C.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 18
D-Separation (Directed Graphs)
AC
B
Directed, acyclic graph in which A, B, Care arbitrary, non-intersecting sets ofnodes. Does A KK B|C hold?Note: C is observed if we condition on it(and the nodes in the GM are shaded)
Consider all possible paths from any node in A to any node in B.Any such path is blocked if it includes a node such that either
§ Arrows on the path meet either head-to-tail or tail-to-tail at thenode, and the node is in the set C or
§ Arrows meet head-to-head at the node and neither the node norany of its descendants is in the set C
If all paths are blocked, then A is d-separated (conditionally indep.)from B by C, and the joint distribution satisfies A KK B|C.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 18
D-Separation (Directed Graphs)
AC
B
Directed, acyclic graph in which A, B, Care arbitrary, non-intersecting sets ofnodes. Does A KK B|C hold?Note: C is observed if we condition on it(and the nodes in the GM are shaded)
Consider all possible paths from any node in A to any node in B.Any such path is blocked if it includes a node such that either
§ Arrows on the path meet either head-to-tail or tail-to-tail at thenode, and the node is in the set C or
§ Arrows meet head-to-head at the node and neither the node norany of its descendants is in the set C
If all paths are blocked, then A is d-separated (conditionally indep.)from B by C, and the joint distribution satisfies A KK B|C.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 18
D-Separation (Directed Graphs)
AC
B
Directed, acyclic graph in which A, B, Care arbitrary, non-intersecting sets ofnodes. Does A KK B|C hold?Note: C is observed if we condition on it(and the nodes in the GM are shaded)
Consider all possible paths from any node in A to any node in B.Any such path is blocked if it includes a node such that either
§ Arrows on the path meet either head-to-tail or tail-to-tail at thenode, and the node is in the set C or
§ Arrows meet head-to-head at the node and neither the node norany of its descendants is in the set C
If all paths are blocked, then A is d-separated (conditionally indep.)from B by C, and the joint distribution satisfies A KK B|C.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 18
Example
a
e
d
b
c
(a) a KK b|c?
a
e
d
b
c
(b) a KK b|d?
A path is blocked if it includes a node such that either
§ The arrows on the path meet either head-to-tail or tail-to-tail atthe node, and the node is in the set C (observed) or
§ The arrows meet head-to-head at the node, and neither the nodenor any of its descendants is in the set C (observed)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 19
Markov Random Fields (Undirected Graphical Models)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 20
Markov Random Fields
a b
c
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 21
Joint Distribution
a
b
c
d
a
b
c
d
§ Express joint distribution ppx1, . . . , xnq “: ppxq as a product offunctions defined on subsets of variables that are local to thegraph
§ If xi, xj are not connected directly by a link then xi KK xj|xztxi, xju
(conditionally independent given everything else)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 22
Joint Distribution
a
b
c
d
a
b
c
d
§ Express joint distribution ppx1, . . . , xnq “: ppxq as a product offunctions defined on subsets of variables that are local to thegraph
§ If xi, xj are not connected directly by a link then xi KK xj|xztxi, xju
(conditionally independent given everything else)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 22
Factorization of the Joint Distribution
§ If xi KK xj|xztxi, xju then xi, xj never appear in a common factor inthe factorization of the joint
Joint distribution as a product of cliques (fully connectedsubgraphs)
§ Define factors in the decomposition of the joint to be functions ofthe variables in (maximum) cliques:
ppxq9ź
CψCpxCq
Example: ppa, b, c, dq9ψ1pa, bqψ2pb, c, dq
a
b
c
d
a
b
c
d
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 23
Factorization of the Joint Distribution
§ If xi KK xj|xztxi, xju then xi, xj never appear in a common factor inthe factorization of the joint
Joint distribution as a product of cliques (fully connectedsubgraphs)
§ Define factors in the decomposition of the joint to be functions ofthe variables in (maximum) cliques:
ppxq9ź
CψCpxCq
Example: ppa, b, c, dq9ψ1pa, bqψ2pb, c, dq
a
b
c
d
a
b
c
d
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 23
Factorization of the Joint Distribution
§ If xi KK xj|xztxi, xju then xi, xj never appear in a common factor inthe factorization of the joint
Joint distribution as a product of cliques (fully connectedsubgraphs)
§ Define factors in the decomposition of the joint to be functions ofthe variables in (maximum) cliques:
ppxq9ź
CψCpxCq
Example: ppa, b, c, dq9ψ1pa, bqψ2pb, c, dq
a
b
c
d
a
b
c
d
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 23
Factorization of the Joint Distribution
More generally:
ppxq “1Z
ź
C
ψCpxCq
§ C: maximal clique
§ xC: all variables in this clique
§ ψCpxCq: clique potential
§ Z “ř
xś
C ψCpxCq: normalization constant
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 24
Clique Potentials
ppxq “1Z
ź
C
ψCpxCq
Clique potentials ψCpxCq:
§ ψCpxCq ě 0
§ Unlike directed graphs, no probabilistic interpretation necessary(e.g., marginal or conditional)
Greater flexibility but computational challenges
§ If we convert a directed graph into an MRF, the clique potentialsdo have a probabilistic interpretation
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 25
Clique Potentials
ppxq “1Z
ź
C
ψCpxCq
Clique potentials ψCpxCq:
§ ψCpxCq ě 0
§ Unlike directed graphs, no probabilistic interpretation necessary(e.g., marginal or conditional)
Greater flexibility but computational challenges
§ If we convert a directed graph into an MRF, the clique potentialsdo have a probabilistic interpretation
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 25
Clique Potentials
ppxq “1Z
ź
C
ψCpxCq
Clique potentials ψCpxCq:
§ ψCpxCq ě 0
§ Unlike directed graphs, no probabilistic interpretation necessary(e.g., marginal or conditional)
Greater flexibility but computational challenges
§ If we convert a directed graph into an MRF, the clique potentialsdo have a probabilistic interpretation
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 25
Normalization Constant
ppxq “1Z
ź
C
ψCpxCq
§ Flexibility in the definition the factorization in an MRF
§ Normalization constant (also: partition function) Z is required forparameter learning (not covered in here) and model selection
§ In a discrete model with M discrete nodes each having K states,the evaluation Z requires summing over KM states
Exponential in the size of the model
§ In a continuous model, we need to solve integralsIntractable in many cases
Major limitation of MRFs
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 26
Normalization Constant
ppxq “1Z
ź
C
ψCpxCq
§ Flexibility in the definition the factorization in an MRF
§ Normalization constant (also: partition function) Z is required forparameter learning (not covered in here) and model selection
§ In a discrete model with M discrete nodes each having K states,the evaluation Z requires summing over KM states
Exponential in the size of the model
§ In a continuous model, we need to solve integralsIntractable in many cases
Major limitation of MRFsGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 26
Conditional Independence
AC
B
Two easy checks for conditional independence:§ A KK B|C if and only if all paths from A to B pass through C.
(Then, all paths are blocked)§ Alternative: Remove all nodes in C from the graph. If there is a
path from A to B then A KK B|C does not holdGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 27
Potentials as Energy Functions
§ Look only at potential functions with ψCpxCq ą 0ψCpxCq “ expp´EpxCqq for some energy function E
§ Joint distribution is the product of clique potentialsTotal energy is the sum of the energies of the clique potentials
´ log ppxq “ ´ logź
C
expp´EpxCqqloooooomoooooon
“ψCpxCq
“ÿ
C
EpxCq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 28
Potentials as Energy Functions
§ Look only at potential functions with ψCpxCq ą 0ψCpxCq “ expp´EpxCqq for some energy function E
§ Joint distribution is the product of clique potentialsTotal energy is the sum of the energies of the clique potentials
´ log ppxq “ ´ logź
C
expp´EpxCqqloooooomoooooon
“ψCpxCq
“ÿ
C
EpxCq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 28
Example: Image De-Noising
From PRML (Bishop, 2006)
§ Binary image, corrupted by 10% binary noise (pixel values flipwith probability 0.1).
§ Objective: Restore noise-free image
Pairwise MRF that has all its variables joined in cliques of size 2
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 29
Example: Image De-Noising (2)
xi
yi
§ MRF-based approach
§ Latent variables xi P t´1,`1u are the binary noise-free pixelvalues that we wish to recover
§ Observed variables yi P t´1,`1u are the noise-corrupted pixelvalues
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 30
Example: Image De-Noising (2)
xi
yi
§ MRF-based approach
§ Latent variables xi P t´1,`1u are the binary noise-free pixelvalues that we wish to recover
§ Observed variables yi P t´1,`1u are the noise-corrupted pixelvalues
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 30
Clique Potentials
xi
yi
Two types of clique potentials:
§ ´ log ψxypxi, yiq “ Epxi, yiq “ ´ηxiyi , η ą 0Strong correlation between observed and latent variables
§ ´ log ψxxpxi, xjq “ Epxi, xjq “ ´βxixj , β ą 0for neighboring pixels xi, xj
Favor similar labels for neighboring pixels (smoothness prior)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 31
Clique Potentials
xi
yi
Two types of clique potentials:
§ ´ log ψxypxi, yiq “ Epxi, yiq “ ´ηxiyi , η ą 0Strong correlation between observed and latent variables
§ ´ log ψxxpxi, xjq “ Epxi, xjq “ ´βxixj , β ą 0for neighboring pixels xi, xj
Favor similar labels for neighboring pixels (smoothness prior)Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 31
Energy Function
Total energy:
Epx, yq “ ´ηÿ
i
xiyi
loooomoooon
latent-observed
´βÿ
ti,ju
xixj
looooomooooon
latent-latent
`γÿ
i
xi
loomoon
bias
§ Bias term places a prior on the latent pixel values, e.g., `1.
§ Joint distribution ppx, yq “ 1Z expp´Epx, yqq
§ Fix y-values to the observed ones Implicitly define ppx|yq
§ Example of an Ising model Statistical physics
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 32
ICM Algorithm for Image De-Noising
Noise-corrupted image, ICM, Graph-cut (From PRML (Bishop, 2006))
Iterated Conditional Modes (ICM, Kittler & Foglein, 1984)
1. Initialize all xi “ yi
2. Pick any xj: Evaluate total energyEpxzj Y t`1u, yq, Epxzj Y t´1u, yq
3. Set xj to whichever state (˘1) has the lower energy
4. RepeatLocal optimum
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 33
Relation to Directed Graphs
a b
c d
c
a b
PUD
§ Directed and undirected graphs express different conditionalindependence properties
§ Left: a KK b|H, a zKK b|c has no MRF equivalent
§ Center: a zKK b|H, c KK d|aY b, a KK b|cY d has no Bayesnetequivalent
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 34
Factor Graphs
Good references:
Kschischang et al.: Factor Graphs and the Sum-Product Algorithm.IEEE Transactions on Information Theory (2001)
Loeliger: An Introduction to Factor Graphs. IEEE Signal ProcessingMagazine, (2004)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 35
Factor Graphs
a b
c
§ (Un)directed graphical models express a global function ofseveral variables as a product of factors over subsets of thosevariables
§ Factor graphs make this decomposition explicit by introducingadditional nodes for the factors themselves
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 36
Factorizing the Joint
The joint distribution is a product of factors:
ppxq “ź
sfspxsq
§ x “ px1, . . . , xnq
§ xs: Subset of variables§ fs: Factor; non-negative function of the variables xs
§ Building a factor graph as a bipartite graph:§ Nodes for all random variables (same as in (un)directed graphical
models)§ Additional nodes for factors (black squares) in the joint
distribution
§ Undirected links connecting each factor node to all of the variablenodes the factor depends on
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 37
Factorizing the Joint
The joint distribution is a product of factors:
ppxq “ź
sfspxsq
§ x “ px1, . . . , xnq
§ xs: Subset of variables§ fs: Factor; non-negative function of the variables xs
§ Building a factor graph as a bipartite graph:§ Nodes for all random variables (same as in (un)directed graphical
models)§ Additional nodes for factors (black squares) in the joint
distribution
§ Undirected links connecting each factor node to all of the variablenodes the factor depends on
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 37
Example
x1 x2 x3
fa fb fc fd
ppxq “ fapx1, x2q fbpx1, x2q fcpx2, x3q fdpx3q
Efficient inference algorithms for factor graphs (e.g., sum-productalgorithm)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 38
Example
x1 x2 x3
fa fb fc fd
ppxq “ fapx1, x2q fbpx1, x2q fcpx2, x3q fdpx3q
Efficient inference algorithms for factor graphs (e.g., sum-productalgorithm)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 38
Converting Graphs
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 39
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
1. Moralization:
§ Add additional undirected links between all pairs of parents foreach node in the graph
§ Drop arrows on original links
2. Identify (maximum) cliques3. Initialize all clique potentials to 14. Take each conditional distribution factor in the directed graph,
multiply it into one of the clique potentials
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
1. Moralization:§ Add additional undirected links between all pairs of parents for
each node in the graph
§ Drop arrows on original links
2. Identify (maximum) cliques3. Initialize all clique potentials to 14. Take each conditional distribution factor in the directed graph,
multiply it into one of the clique potentials
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
1. Moralization:§ Add additional undirected links between all pairs of parents for
each node in the graph§ Drop arrows on original links
2. Identify (maximum) cliques3. Initialize all clique potentials to 14. Take each conditional distribution factor in the directed graph,
multiply it into one of the clique potentials
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
ψ1234
ψ35
1. Moralization:§ Add additional undirected links between all pairs of parents for
each node in the graph§ Drop arrows on original links
2. Identify (maximum) cliques
3. Initialize all clique potentials to 14. Take each conditional distribution factor in the directed graph,
multiply it into one of the clique potentials
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
ψ1234
ψ35
1. Moralization:§ Add additional undirected links between all pairs of parents for
each node in the graph§ Drop arrows on original links
2. Identify (maximum) cliques3. Initialize all clique potentials to 1
4. Take each conditional distribution factor in the directed graph,multiply it into one of the clique potentials
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
Directed Graph Ñ MRF
x1
x2
x3
x4 x5
x1
x2
x3
x4 x5
ψ1234
ψ35
1. Moralization:§ Add additional undirected links between all pairs of parents for
each node in the graph§ Drop arrows on original links
2. Identify (maximum) cliques3. Initialize all clique potentials to 14. Take each conditional distribution factor in the directed graph,
multiply it into one of the clique potentialsGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 40
MRF Ñ Factor Graph
x1 x2
x3
x1 x2
x3
x1 x2
x3
f fafb
1. Take variable nodes from MRF
2. Create additional factor nodes corresponding to the maximalcliques xs
3. The factors fspxsq equal the clique potentials
4. Add appropriate links
Multiple factor graphs may correspond to the same undirected graphGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 41
Example: MRF Ñ Factor Graph
x1 x2
x3
x1 x2
x3
x1 x2
x3
f fafb
Multiple factor graphs may correspond to the same undirected graph
§ MRF with clique potential ψpx1, x2, x3q
§ Factor graph with factor f px1, x2, x3q “ ψpx1, x2, x3q
§ Factor graph with factors, such thatfapx1, x2, x3q fbpx2, x3q “ ψpx1, x2, x3q
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 42
Directed Graphical Model Ñ Factor Graph
1. Take variable nodes from Bayesian network
2. Create additional factor nodes corresponding to the conditionaldistributions
3. Add appropriate links
Not unique
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 43
Example: Directed Graph Ñ Factor Graph
x1 x2
x3
x1 x2
x3
x1 x2
x3
f fcfbfa
§ Directed graph with factorization ppx1qppx2qppx3|x1, x2q
§ Factor graph with factor f px1, x2, x3q “ ppx1qppx2qppx3|x1, x2q
§ Factor graph with factors fa “ ppx1q, fb “ ppx2q, fc “ ppx3|x1, x2q
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 44
Removing Cycles
x1 x2
x3 x1 x2
x3
f (x1, x2, x3)x1 x2
x3
§ Local cycles in an (un)directed graph (due to links connectingparents of a node) can be removed on conversion to a factorgraph
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 45
Exact Inference in Factor Graphs
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 46
Sum-Product Algorithm for Factor Graphs
§ Factor graphs give a uniform treatment to message passing,which is used for inference in graphs
§ Inference: Find (marginal) posterior distributions
§ Idea: Local message passing between nodes and factors§ Two different types of messages:
§ Messages µxÑ f pxq from variable nodes to factors§ Messages µ fÑxpxq from factors to variable nodes
§ Repeated sending of these messages through the graph converges
§ Factors transform messages into evidence for the receiving node
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 47
Sum-Product Algorithm for Factor Graphs
§ Factor graphs give a uniform treatment to message passing,which is used for inference in graphs
§ Inference: Find (marginal) posterior distributions
§ Idea: Local message passing between nodes and factors§ Two different types of messages:
§ Messages µxÑ f pxq from variable nodes to factors§ Messages µ fÑxpxq from factors to variable nodes
§ Repeated sending of these messages through the graph converges
§ Factors transform messages into evidence for the receiving node
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 47
Sum-Product Algorithm for Factor Graphs
§ Factor graphs give a uniform treatment to message passing,which is used for inference in graphs
§ Inference: Find (marginal) posterior distributions
§ Idea: Local message passing between nodes and factors§ Two different types of messages:
§ Messages µxÑ f pxq from variable nodes to factors§ Messages µ fÑxpxq from factors to variable nodes
§ Repeated sending of these messages through the graph converges
§ Factors transform messages into evidence for the receiving node
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 47
Variable-to-Factor Message
xm
f1
fK
µxm→fs(x)
fs
µ fK→xm(xm)
µf1→xm (x
m )
µxmÑ fspxmq “ź
lPnepxmqz fs
µ flÑxmpxmq
§ Take the product of all incoming messages along all other links
§ A variable node can send a message to a factor node once it hasreceived messages from all other neighboring factors
§ The message that a node sends to a factor is made up of themessages that it receives from all other factors.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 48
Variable-to-Factor Message
xm
f1
fK
µxm→fs(x)
fs
µ fK→xm(xm)
µf1→xm (x
m )
µxmÑ fspxmq “ź
lPnepxmqz fs
µ flÑxmpxmq
§ Take the product of all incoming messages along all other links§ A variable node can send a message to a factor node once it has
received messages from all other neighboring factors
§ The message that a node sends to a factor is made up of themessages that it receives from all other factors.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 48
Variable-to-Factor Message
xm
f1
fK
µxm→fs(x)
fs
µ fK→xm(xm)
µf1→xm (x
m )
µxmÑ fspxmq “ź
lPnepxmqz fs
µ flÑxmpxmq
§ Take the product of all incoming messages along all other links§ A variable node can send a message to a factor node once it has
received messages from all other neighboring factors§ The message that a node sends to a factor is made up of the
messages that it receives from all other factors.Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 48
Factor-to-Variable Message
x1
xM
xµfs→x(x)
fsfsµ xM
→fs(x
M)
µx1→fs (x
1 )
µ fsÑxpxq “
ÿ
x1
¨ ¨ ¨ÿ
xM
fspx, x1, . . . , xMq
ź
mPnep fsqzx
µxmÑ fspxmq
§ Take the product of the incoming messages along all other linkscoming into the factor node
§ Multiply by the factor associated with that node§ Marginalize over all variables associated with the incoming
messages
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 49
Factor-to-Variable Message
x1
xM
xµfs→x(x)
fsfsµ xM
→fs(x
M)
µx1→fs (x
1 )
µ fsÑxpxq “
ÿ
x1
¨ ¨ ¨ÿ
xM
fspx, x1, . . . , xMqź
mPnep fsqzx
µxmÑ fspxmq
§ Take the product of the incoming messages along all other linkscoming into the factor node
§ Multiply by the factor associated with that node
§ Marginalize over all variables associated with the incomingmessages
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 49
Factor-to-Variable Message
x1
xM
xµfs→x(x)
fsfsµ xM
→fs(x
M)
µx1→fs (x
1 )
µ fsÑxpxq “ÿ
x1
¨ ¨ ¨ÿ
xM
fspx, x1, . . . , xMqź
mPnep fsqzx
µxmÑ fspxmq
§ Take the product of the incoming messages along all other linkscoming into the factor node
§ Multiply by the factor associated with that node§ Marginalize over all variables associated with the incoming
messagesGraphical Models Marc Deisenroth @Imperial College London, January 15, 2019 49
Initialization
§ If the leaf node is a variable node, initialize the correspondingmessages to 1:
µxÑ f pxq “ 1
§ If the leaf node is a factor node, the message should be
µ fÑxpxq “ f pxq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 50
Example (1)
x1 x2 x3
x4
fa fb
fc
From PRML (Bishop, 2006)
µx1Ñ fapx1q “ 1
µ faÑx2px2q “ÿ
x1
fapx1, x2q ¨ 1
µx4Ñ fcpx4q “ 1
µ fcÑx2px2q “ÿ
x4
fcpx2, x4q ¨ 1
µx2Ñ fbpx2q “ µ faÑx2px2qµ fcÑx2px2q
µ fbÑx3px3q “ÿ
x2
fbpx2, x3qµx2Ñ fbpx2q
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 51
Example (2)
x1 x2 x3
x4
fa fb
fc
From PRML (Bishop, 2006)
µx3Ñ fbpx3q “ 1
µ fbÑx2px2q “ÿ
x3
fbpx2, x3q ¨ 1
µx2Ñ fapx2q “ µ fbÑx2px2qµ fcÑx2px2q
µ faÑx1px1q “ÿ
x2
fapx1, x2qµx2Ñ fapx2q
µx2Ñ fcpx2q “ µ faÑx2px2qµ fbÑx2px2q
µ fcÑx4px4q “ÿ
x2
fcpx2, x4qµx2Ñ fcpx2q
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 52
Marginals
x
f1
fK
µx←fs(x)
fs
µ fK→x(x)
µf1→x (x)
For a single variable node the marginal is given as the product of allincoming messages:
ppxq “ź
fiPnepxq
µ fiÑxpxq
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 53
Observed Variables Posterior
§ Thus far, we have focused on the case where all variables areunobserved.
§ Posterior is always conditioned on observations
§ Partition x “ hY v, h: hidden variables, v: visible variables withobservations v
§ ppv “ vq “ś
i Ipvi “ viq
§ ppxqppv “ vq “ pph, v “ vq 9 pph|v “ vq
§ Marginal posteriors pphi|v “ vq can be obtained via sum-productalgorithm and some local computations
(Koller & Friedman, 2009)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 54
Exact Inference in (Un)Directed Graphical Models
§ Loops are possible Junction Tree Algorithm (Lauritzen &Spiegelhalter, 1988)
§ Alternative: Loopy Belief Propagation (Frey & MacKay 1998)
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 55
Applications of Inference in Graphical Models
§ Ranking: TrueSkill (Herbrich et al., 2007)§ Computer vision: de-noising, segmentation, semantic labeling, ...
(e.g., Sucar & Gillies, 1994; Shotton et al., 2006; Szeliski et al., 2008)§ Coding theory: Low-density parity-check codes, turbo codes, ...
(e.g., McEliece et al., 1998)§ Linear algebra: Solve linear equation systems (Shental et al., 2008)§ Signal processing: Iterative state estimation (e.g., Bickson et al.,
2007; Deisenroth & Mohamed, 2012)Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 56
Summary
a b
c
a b
c
a b
c
§ Three types of graphical models: directed, undirected, factorgraphs
§ Conditional independence
§ Sum-product algorithm for exact inference in factor graphs
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 57
References I
[1] D. Bickson, D. Dolev, O. Shental, P. H. Siegel, and J. K. Wolf. Linear Detection via Belief Propagation. In Proceedings of theAnnual Allerton Conference on Communication, Control, and Computing, 2007.
[2] C. M. Bishop. Pattern Recognition and Machine Learning. Information Science and Statistics. Springer-Verlag, 2006.
[3] M. P. Deisenroth and S. Mohamed. Expectation Propagation in Gaussian Process Dynamical Systems. In Advances inNeural Information Processing Systems, pages 2618–2626, 2012.
[4] B. J. Frey and D. J. C. MacKay. A Revolution: Belief Propagation in Graphs with Cycles. In Advances in Neural InformationProcessing Systems, 1998.
[5] R. Herbrich, T. Minka, and T. Graepel. TrueSkill(TM): A Bayesian Skill Rating System. In Advances in Neural InformationProcessing Systems, pages 569–576. MIT Press, 2007.
[6] M. I. Jordan, Z. Ghahramani, T. S. Jaakkola, and L. K. Saul. An Introduction to Variational Methods for Graphical Models.Machine Learning, 37:183–233, 1999.
[7] B. Kim, J. A. Shah, and F. Doshi-Velez. Mind the Gap: A Generative Approach to Interpretable Feature Selection andExtraction. In C. Cortes, N. D. Lawrence, D. D. Lee, M. Sugiyama, and R. Garnett, editors, Advances in Neural InformationProcessing Systems, pages 2260–2268, 2015.
[8] J. Kittler and J. Foglein. Contextual Classification of Multispectral Pixel Data. IMage and Vision Computing, 2(1):13–29, 1984.
[9] F. R. Kschischang, B. J. Frey, and H.-A. Loeliger. Factor Graphs and the Sum-Product Algorithm. IEEE Transactions onInformation Theory, 47:498–519, 2001.
[10] S. L. Lauritzen and D. J. Spiegelhalter. Local Computations with Probabilities on Graphical Structures and theirApplication to Expert Systems. Journal of the Royal Statistical Society, 50:157–224, 1988.
[11] H.-A. Loeliger. An Introduction to Factor Graphs. IEEE Signal Processing Magazine, 21(1):28–41, 2004.
[12] R. J. McEliece, D. J. C. MacKay, and J.-F. Cheng. Turbo Decoding as an Instance of Pearl’s “Belief Propagation” Algorithm.IEEE Journal on Selected Areas in Communications, 16(2):140–152, 1998.
[13] T. P. Minka. A Family of Algorithms for Approximate Bayesian Inference. PhD thesis, Massachusetts Institute of Technology,Cambridge, MA, USA, Jan. 2001.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 58
References II
[14] J. Pearl. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference. Morgan Kaufmann, 1988.
[15] O. Shental, D. Bickson, J. K. W. P. H. Siegel and, and D. Dolev. Gaussian Belief Propagatio Solver for Systems of LinearEquations. In IEEE International Symposium on Information Theory, 2008.
[16] J. Shotton, J. Winn, C. Rother, and A. Criminisi. TextonBoost: Joint Appearance, Shape and Context Modeling forMulit-Class Object Recognition and Segmentation. In Proceedings of the European Conference on Computer Vision, 2006.
[17] L. E. Sucar and D. F. Gillies. Probabilistic Reasoning in High-Level Vision. Image and Vision Computing, 12(1):42–60, 1994.
[18] R. Szeliski, R. Zabih, D. Scharstein, O. Veksler, A. A. Vladimir Kolmogorov, M. Tappen, and C. Rother. A ComparativeStudy of Energy Minimization Methods for Markov Random Fields with Smoothness-based Priors. IEEE Transactions onPattern Analysis and Machine Intelligence, 30(6):1068–1080, 2008.
Graphical Models Marc Deisenroth @Imperial College London, January 15, 2019 59