Optimal reverse prediction: a unified perspective on supervised, unsupervised and semi-supervised learning