Machine Learning: a Probabilistic Perspective