How data, synapses and neurons interact with each other: a variational principle marrying gradient ascent and message passing