Learning and Inference in Factor Graphs with Applications to Tactile Perception