Towards a theoretical foundation of neural networks