Algorithms for probabilistic graphical models