Murphy's book treats dropout as multiplicative Bernoulli noise on a unit's outgoing weights, with , and gives two ways to predict with a trained network:
Implement mc_dropout_predict(X, layers, p, S, seed) for a ReLU MLP:
X: inputs, shape (N, D). layers: list of (W, b) with W of shape (d_in, d_out); a layer computes h @ W + b. Every layer except the last is followed by ReLU; the last is linear.rng = np.random.default_rng(seed) once. For pass , and within a pass for hidden layers in order, draw keep = rng.random((N, d_out)) < 1 - p (one independent mask per example and unit).Return (mean, var, scaled), each of shape (N, d_out_last): the mean and the population variance (divide by ) of the stochastic outputs, and the weight-scaled prediction.