Algorithm For Training Neural Networks