trainrp optimiser function