Pattern classification by memristive crossbar circuits with ex-situ and in-situ training