Closed loop neurostimulation for epilepsy