Add training function for trainer class