Consistency regularisation asks a model to give the same prediction for an input and a perturbed copy. Virtual adversarial training (VAT) chooses the perturbation that changes the prediction most. Use a softmax regression model with W of shape (C, D) and b of shape (C,).
vat_perturbation(W, b, x, d, xi, eps): for one input x (shape (D,)) and a random direction d, compute evaluated at , treating as a constant, and return . Compute the gradient analytically.
consistency_loss(P, Q, kind): for two (N, C) arrays of distributions, return the sum over rows of when kind == "mse", or of (natural log) when kind == "kl".
ssl_objective(W, b, X_lab, y_lab, X_unl, X_pert, lam, kind): the summed negative log-likelihood of the labeled points plus lam times consistency_loss between the predictions on X_unl and on X_pert.
Return Python floats for the losses.