Optimal architecture for deep neural networks