Refactored MultilayerPerceptronTrainer

Previously, the '_cost' function had two responsabilities: updating the
weights of the network and calculating the cost gradient wrt. the
weights. Now, it only calculates the gradient; updating the weights is
handled in the 'train' function, instead.