Reinforcement learning in the presence of rare events