Unsupervised Machine Learning From First Principles