personally I would just make this method into a Cost class that expects the MLP to have the last layer be Linear