Applications Of The Free Energy Principle To Machine Learning And Neuroscience