A tree-structured Bayesian network is a cheap model of a joint distribution over discrete variables. The Chow-Liu algorithm picks the tree that maximizes the total pairwise mutual information between connected variables. It is a maximum spanning tree problem where each edge weight is a mutual information.
Implement two functions.
mutual_information(a, b): the mutual information in bits between two 1-D discrete arrays of the same length. Use the empirical joint distribution.chow_liu_tree(X): X is an n by d array of discrete columns. Return a sorted list of (i, j) tuples with i < j for the edges of a maximum spanning tree over the d columns.mutual_information raises ValueError if the inputs are not 1-D with the same length.chow_liu_tree raises ValueError if X is not 2-D. It returns [] when d = 1.d - 1 edges for d >= 1.Kruskal's algorithm works directly: sort the pairs by mutual information in descending order, then add each edge that joins two different components. A small union-find handles the components.
No results yet
Run your code to check it against the examples, or submit to run every test.