A maximum entropy (maxent) classifier scores each class with its own feature vector and a single shared weight vector :
The features are given as an array Phi of shape (N, C, F) with Phi[n, c] = .
Implement:
maxent_proba(Phi, w): the (N, C) matrix of class probabilities (stable softmax).maxent_nll_grad(Phi, y, w): return (nll, grad) for the summed negative log-likelihood and its gradient with respect to w (shape (F,)).maxent_fit(Phi, y, lr, n_iter): gradient descent on the summed NLL from , n_iter steps of ; return w.block_features(X, C): for an (N, D) input build Phi of shape (N, C, C*D) where places in block (entries ) and zeros elsewhere.With block_features, reshaped to (C, D) is exactly the weight matrix of multinomial logistic regression.