Optimal Population Codes for Control and Estimation