CS5340 Lab2 report1

_get_jt_clique_and_edges()

Create a graph G using nx.Graph() and add nodes and edges to it using the input and edges. Using a helper function undirected_graph_eliminate() to get the reconstituted graph, and use nx.find_cliques() to get the jt_cliques in this graph. Create a clique graph G_c using the jt_cliques, set the sepsets’ size as edges’ weights. Get G_c’s maximum spanning tree and assign this tree’s edges as jt_edges.

_get_clique_factors()

Initialize a Factor() for all cliques in jt_cliques. For each clique, for each factor, if a factor’s variables are subset of this clique and this factor has not been assigned to another clique, assign it to this clique.

_get_clique_potentials()

Use the helper functions N() to find one node’s neighbors, use collect() and distribute() to do the inward and outward message transferring the message using the function send_message(). For each clique, multiply its factor with all messages from its neighbors and get its clique_potential.

_get_node_marginal_probabilities()

For each clique, normalize its potential’s values. To retrieve marginal probabilities for all query nodes in the graph. For each node in the query nodes, find the clique containing this node with the minimum size(number of variables in this clique), marginalize out all the other nodes in this minimum clique and then get the marginal_probability of this node.

_update_mrf_w_evidence()

Return the query node lists with all nodes except the keys in evidence. Use factor_evidence() to update factors with evidence.