A network with M tanh hidden units and one linear output, y(x) = b + Σj wj tanh(aj(x)), is trained by full-batch gradient descent (Adam) on the sum-of-squares error, with the gradient computed by backpropagation. The dashed curves are the outputs zj = tanh(aj) of the individual hidden units (rescaled to fit the plot); the red curve is the network function. The lower right panel compares every backpropagated derivative with a central finite difference.
Data: x uniform on (0, 1) for sin(2πx) and on (−1, 1) for the other targets, plus Gaussian noise with the chosen standard deviation. Training minimises E(w)/N + (λ/2)‖w‖2 with Adam, full batch, from weights drawn N(0, 1) (first layer) and N(0, 1/M) (second layer); the error curves show the RMS error √(2E/N). All random numbers are seeded, so a class sees the same pictures.
code/ch05_neural_networks.py (class Net, adam_train, Figures 5.3, 5.9, 5.10, 5.12, 5.13) and the checks in code/checks_ch05.py. The data, initial weights and Adam steps of this page are the same as data_sine, init_weights and adam_train with JSRandom(seed), number for number.