Machine Learning: A Probabilistic Perspective