Merging Belief Propagation and the Mean Field Approximation: A Free Energy Approach