Learning method for ex-situ training of memristor crossbar based multi-layer neural network