Automating Model Comparison in Factor Graphs