Efficient inference for time-varying behavior during learning