// Create clique trees by minimum (or maximum) spanning tree method
clique_trees = JunctionTree(nx.minimum_spanning_tree(complete_graph).edges())
factor = self.factors[0]
factor = factor.product(*[self.factors[i] for i in
range(1, len(self.factors))])
if set(factor.scope()) != set(self.nodes()):
ValueError("Factor for all the random variables not specified")
all_vars = set(self.nodes())
for node in clique_trees.nodes():
marginalised_nodes = all_vars - set(node)factor_copy = factor.marginalize(list(marginalised_nodes),
inplace=False)
clique_trees.add_factors(factor_copy)
return clique_trees