liveBook · Manning

Inner product

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

A dot product is the scalar obtained by multiplying corresponding components of two equal-length vectors and summing the products.

An inner product, also called a dot product here, multiplies corresponding components of two equal-length vectors and adds the results to produce one number. In a neuron, the two vectors are its input signals and weights. The neuron applies an activation function to that number before passing an output onward. section 7.2 section 7.3

Use the dot product in a neuron

In Swift, the core of `Neuron.output(inputs:)` is `outputCache = dotProduct(inputs, weights)` followed by `return activationFunction(outputCache)`. Caching the value before activation matters: backpropagation later uses it to calculate the neuron's delta. section 7.5

The same operation appears during backpropagation. For a hidden neuron, collect the relevant weights and deltas from the next layer, then take their dot product when calculating its delta. This is a second use of the operation, not another pass of input signals through the neuron. section 7.5

/// Find the dot product of two vectors
/// assuming that they are of the same length
/// using SIMD instructions to speed computation
func dotProduct(_ xs: [Double], _ ys: [Double]) -> Double {
    var answer: Double = 0.0
    vDSP_dotprD(xs, 1, ys, 1, &answer, vDSP_Length(xs.count))
    return answer
}

The Swift `dotProduct` helper calls Accelerate's `vDSP_dotprD`. It assumes equal-length `[Double]` inputs and returns the computed scalar; it does not check their lengths. section 7.3

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

How deep it goes
Shows a Swift implementation and two network call sites, but does not develop the underlying vector mathematics or derive training formulas.
Examples
Uses an Accelerate-backed `dotProduct` helper, a neuron's `output(inputs:)`, and a hidden layer's delta calculation.
What it assumes
Assumes some Swift and vector familiarity while allowing readers to follow the code without a full mathematical explanation.
What you can do after
Apply it via Accelerate's `vDSP_dotprD` to implement neuron outputs and hidden-layer delta calculations.
How it connects
Links the dot product to activation functions, feed-forward neural networks, backpropagation, and SIMD acceleration.

Also explained in

Compare how 12 books explain inner product →

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.