Hidden Markov Model of Cortical Synaptic Plasticity: Derivation of the Learning Rule