Adaptive optimal training of animal behavior