A Normative Theory of Adaptive Dimensionality Reduction in Neural Networks