Neural Networks Fail to Learn Periodic Functions and How to Fix It