Iterative Algorithms for Inference and Optimization, with Applications in Communications and Compressed Sensing