liveBook · Manning

Input layer

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

An input layer is the first neural-network layer that receives input signals and passes them into the network.

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

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines the layer and shows its Swift pass-through implementation, while deferring calculus-based derivations.
Examples
Uses pixel intensities from a 10×10 image and four iris measurements feeding a [4, 6, 3] network.
What it assumes
Assumes familiarity with Swift arrays, classes, and functions while defining feed-forward layers and their signal flow.
What you can do after
Build it from scratch by sizing a Swift input layer to its features and passing its values to the next layer.
How it connects
Connects input features to hidden layers, output layers, feed-forward networks, and weight updates.

Also explained in

Compare how 4 books explain input layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.