Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Deep-ML | Binary GP Classification with the Laplace ApproximationBinary GP Classification with the Laplace Approximation
Binary GP Classification with the Laplace Approximation
Two negatives at -2 and -1 and two positives at 1 and 2. The latent mode is negative on the left and positive on the right; at x = 0 the prediction is exactly 0.5 by symmetry, and far away (x = 8) it returns to 0.5 because the prior mean is zero.
For binary labels yn∈{0,1} a GP classifier puts a GP prior on a latent function and squashes it: p(yn=1∣fn)=σ(fn) with the logistic sigmoid. The posterior over f (without hyperparameter priors) is no longer Gaussian. Approximate it with a Gaussian at its mode (the Laplace approximation).
Use the SE kernel k(x,x′)=σf2exp(−∥x−x′∥2/(2ℓ2)). Implement gpc_laplace(X, y, X_star, ell, sf, n_newton=20):
Mode finding: start at f=0 and run exactly n_newton Newton steps on logp(y∣f)−21f⊤K−1f in the stable form: π=σ(f), W=diag(π(1−π)), B=I+W1/2KW1/2=LL⊤, b=Wf+(y−π), a=b−W1/2L⊤\(L\(W1/2Kb)), f←Ka.
Prediction at the mode f^ (recompute π, W, L there): latent mean fˉ∗=k∗⊤(y−π^), latent variance V∗=k∗∗−v⊤v with v=L\(W1/2k∗), and the probit-approximated class probability p∗=σ(fˉ∗/1+πV∗/8).
Approximate log marginal likelihood: −21a^⊤f^+∑nlogp(yn∣f^n)−∑nlogLnn, with a^ from the last Newton step.
Return a dict with "f_hat", "mean", "var", "p" (the last three for the test inputs) and "log_ml".