A Theoretical Framework for Inference and Learning in Predictive Coding Networks