Learning and Optimization for Shape-based Representations