Function Repository Resource:

MoralizeGraph

Source Notebook

Find the moralized undirected form of a directed acyclic graph

Contributed by: Jon McLoone

ResourceFunction["MoralizeGraph"][gr]

creates the moralized undirected form of a directed acyclic graph gr.

Details and Options

The moralized counterpart of a directed acyclic graph is formed by adding edges between all pairs of non-adjacent nodes that have a common child, and then making all edges in the graph undirected.
Moral graphs are used in belief propagation on graphical models.
Moralization converts a Bayesian network to a Markov network.

Examples

Basic Examples

Find the moral graph of a directed acyclic graph:

In[1]:=
gr = Graph[{5, 11, 7, 8, 9, 10, 2}, {5 -> 11, 7 -> 11, 7 -> 8, 8 -> 9,
    11 -> 9, 11 -> 10, 11 -> 2}, VertexLabels -> Automatic]
Out[1]=
In[2]:=
ResourceFunction["MoralizeGraph"][gr]
Out[2]=
In[3]:=
gr2 = Graph[{"A", "B", "C", "D", "E", "F", "G"},
  {"A" -> "B", "A" -> "C", "B" -> "D", "C" -> "D", "C" -> "E", "E" -> "F", "F" -> "G", "D" -> "G"}, VertexLabels -> Automatic]
Out[3]=
In[4]:=
ResourceFunction["MoralizeGraph"][gr2]
Out[4]=

Publisher

Jon McLoone

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 11 March 2024

Source Metadata

Related Resources

License Information