# -*- coding: utf-8 -*-
# Copyright (C) 2011-2019 by
# Julien Klaus <email@example.com>
# All rights reserved.
# BSD license.
# Copyright 2016-2019 NetworkX developers.
# NetworkX is distributed under a BSD license
# Authors: Julien Klaus <firstname.lastname@example.org>
r"""Function for computing the moral graph of a directed graph."""
import networkx as nx
from networkx.utils import not_implemented_for
__all__ = ['moral_graph']
r"""Return the Moral Graph
Returns the moralized graph of a given directed graph.
G : NetworkX graph
H : NetworkX graph
The undirected moralized graph of G
A moral graph is an undirected graph H = (V, E) generated from a
directed Graph, where if a node has more than one parent node, edges
between these parent nodes are inserted and all directed edges become
..  Wray L. Buntine. 1995. Chain graphs for learning.
In Proceedings of the Eleventh conference on Uncertainty
in artificial intelligence (UAI'95)
if G is None:
raise ValueError("Expected NetworkX graph!")
H = G.to_undirected()
for preds in G.pred.values():
predecessors_combinations = itertools.combinations(preds, r=2)