Entropy minimisation can be derived from maximising the mutual information between inputs and predicted labels. Over a batch of unlabeled points with softmax predictions and batch-mean prediction , the empirical estimate is
, with natural-log entropies. Implement:
mi_terms(probs): for an (N, C) array of distributions, return the tuple (cond_entropy, marginal_entropy, loss) of Python floats, where cond_entropy , marginal_entropy and loss .
mi_loss_and_grad(logits): for an (N, C) array of logits, return (loss, grad) where loss is computed from the softmax of each row and grad is the exact (N, C) gradient of the loss with respect to the logits.
Use a numerically stable softmax (subtract each row's max).