A training dataset pairs inputs with expected outputs. A neural network uses each pair to calculate error, backpropagate it, and update its weights. section 7.5
One training pass
For each input array, the network computes outputs, compares them with the corresponding expected-output array, then updates its weights. section 7.5
/// train() uses the results of outputs() run over
/// many *inputs* and compared against *expecteds* to feed
/// backpropagate() and updateWeights()
func train(inputs: [[Double]], expecteds: [[Double]], printError: Bool =
false, threshold: Double? = nil) {
for (location, xs) in inputs.enumerated() {
let ys = expecteds[location]
let outs = outputs(input: xs)
if (printError) {
let diff = sub(outs, ys)
let error = sqrt(sum(mul(diff, diff)))
print("\(error) error in run \(location)")
}
backpropagate(expected: ys)
updateWeights()
}
}
The train() implementation shows how input and expected-output arrays drive forward passes, error reporting, backpropagation, and weight updates. section 7.5



































