A feed-forward neural network starts with an input layer. It receives floating-point signals from outside the network and passes them toward the hidden layer. The input-layer size should match the number of values describing one input. For a 10×10 grayscale image, that could mean 100 values—one pixel intensity per position. section 7.2 section 7.6
The input layer has a special job in this Swift implementation: it passes values through rather than calculating neuron outputs. A Layer with no previousLayer stores inputs in outputCache and returns them. Later layers calculate their outputs from those signals. Because training updates weights only after the first layer, the input layer’s values serve as inputs to trainable connections, not as weights to update there. section 7.5
func outputs(inputs: [Double]) -> [Double] {
if previousLayer == nil { // input layer (first layer)
outputCache = inputs
} else { // hidden layer or output layer
outputCache = neurons.map { $0.output(inputs: inputs) }
}
return outputCache
}
Compare the first-layer branch, which caches and returns the supplied array, with the branch that runs each neuron in later layers. section 7.5
Four measurements in, three species out
An iris classifier uses Network(layerStructure: [4, 6, 3], learningRate: 0.3). Its four input neurons correspond to four flower measurements; six neurons form the hidden layer, and three output neurons correspond to the species choices. The four incoming numbers are therefore features, not classifications. The hidden-layer size and learning rate are values to experiment with when accuracy is suboptimal. section 7.6



