Classification on Two Moons Toy Data#
This toy example shows how to train a variational neural network for binary classification on the two moons dataset using implicit regularization via SGD initialized to the prior, as described in this paper. This approach avoids the computational cost of explicit regularization for non-trivial variational families and preserves beneficial inductive biases.
You can run this example yourself via the corresponding standalone script.
Data#
We begin by generating synthetic training and test data based on the two moons classification technique.
Model#
Next, we define a fully-connected stochastic neural network using a pre-defined models.MLP.
- PyTorch
nn.Modules can be used as part ofinfernomodels.
Training#
We train the model via the expected loss, \( \bar{\ell}(\theta) = \mathbb{E}_{q_\theta(w)}[\ell(y, f_w(X))] \) i.e. the average loss of the model when drawing weights from the variational distribution \(q_\theta(w)\). In practice, for efficiency we only use a single sample per batch during training.