BIDS / datarray

Prototyping numpy arrays with named axes for data management.
http://bids.github.com/datarray
Other
87 stars 20 forks source link

BF: fix inference example reliance on node order #76

Closed matthew-brett closed 8 years ago

matthew-brett commented 8 years ago

We were getting not-deterministic errors from the inference algorithm example script in Python 3. I believe these were due to the following code in calc_marginals_sumproduct, where G is a graph:

    for node in G.nodes():
        potential = multiply_potentials(*[messages[(src,node)] for src in G.neighbors(node)])
        marginals[node] = normalize(potential)

    return marginals, potential.sum()

This code is iterating over the elements of an underlying dictionary (G.nodes()), so potential.sum() at the end returns some value effectively randomly chosen from all the nodes in the dictionary. I think that we actually want:

    for node in G.nodes():
        potential = multiply_potentials(*[messages[(src,node)] for src in G.neighbors(node)])
        marginals[node] = normalize(potential)
        potentials[node] = potential

    return marginals, potentials[target_node].sum()

where target_node = 'burglary'.