PES learning rule

Stole the implementation from 98d02dae242357b0c94a6d6f617bf88b9353027f and made it work in the new codebase.