Applications of the Free Energy Principle to Machine Learning and Neuroscience