← SnapRecaps

But what is a convolution?

► 3,551,112 views ⏲ 23:01 Watch on YouTube ↗

Summary

Convolution unifies probability, polynomial multiplication, and image processing; direct computation is slow, but FFT speeds it ~1000x, and CNNs learn its kernels.

Executive Summary

Convolution is a fundamental yet underappreciated way to combine lists or functions, distinct from addition and multiplication, and the video demystifies it with intuitive examples like rolling dice, moving averages, and image blurring. It shows how the same operation underlies probability distributions, polynomial multiplication, and computer vision effects such as edge detection and sharpening, with a small reusable kernel sliding over data. A key practical highlight is that direct convolution is slow, but using clever algorithms like FFT can speed up computation by roughly a thousandfold—NumPy's standard convolve took 4.87 seconds on a large array while SciPy's fftconvolve took just 4.3 milliseconds. The video also explains why the kernel flip in convolution is inherited naturally from pure mathematics, not an arbitrary computer science convention, and notes that convolutional neural networks learn their kernel values from data instead of relying on hand-designed filters. Ultimately, convolution is a beautiful, unifying mathematical tool whose insights deliver measurable real-world performance gains in programming.

Key Points

  • ▶ 0:00 Convolution is introduced as a third fundamental way to combine lists or functions, as important as addition and multiplication but far less commonly discussed; unlike pointwise operations, it is a genuinely new kind of combination.
  • ▶ 0:45 Convolution is highly versatile and appears across image processing, probability, and differential equations, and most viewers have already encountered it when multiplying polynomials.
  • ▶ 1:01 A visual explanation is especially valuable because the formula looks intimidating, but unpacking it reveals an incredibly beautiful operation; the video's scope is the discrete case, building toward an unexpected and clever algorithm.
  • ▶ 2:12 Convolutions are introduced through rolling two dice and summing outcomes, rather than image processing, because the dice problem is a cleaner, more representative example.
  • ▶ 3:53 For non-uniform dice, convolutions are computed by flipping one probability array, sliding it across the other, and summing the pairwise products at each offset.
  • ▶ 5:50 The convolution is denoted as $(a * b)n = \sum a_i b_j$, which sums pairwise products over all index pairs where $i + j = n$.
  • ▶ 7:34 Convolution can be viewed as a moving average: take a smaller kernel list whose values sum to 1 and slide it across a larger data list.
  • ▶ 7:59 At each fully overlapping position, multiply each data value by the kernel weight (e.g., 1/5) and sum them—this is exactly the average of the data within the window.
  • ▶ 8:18 The kernel need not be uniform; as long as its entries sum to 1, it performs a weighted moving average that still smooths the data while preserving its scale.
  • ▶ 8:33 Two-dimensional convolution provides a straightforward algorithm for blurring an image by applying a small grid of weights across the image.
  • ▶ 9:42 The blurred image is formally a convolution of the original with a 180-degree rotated version of the grid, though rotation doesn't matter for symmetric grids.
  • ▶ 10:06 Using a 5×5 grid with weights sampled from a Gaussian bell curve creates a more realistic blur that simulates lens defocusing.
  • ▶ 10:50 Convolution is a general tool, not just for blurring; a new kernel with positive values on the left and negative values on the right is introduced.
  • ▶ 11:11 The demonstration simplifies images to grayscale, representing each pixel by a single number.
  • ▶ 11:18 Negative output values are possible during convolution, as shown when positive kernel values align over black pixels (value zero) while negative values produce a negative result.
  • ▶ 11:36 Zero-sum kernels produce very negative results where pixel values vary strongly, with negative responses colored red and positive ones blue.
  • ▶ 11:47 Uniform image patches give a convolution result of zero because the kernel's entries sum to zero, unlike blurring kernels whose values sum to one and act as a moving average.
  • ▶ 12:04 This zero-sum convolution detects vertical edges by responding to left-to-right variation; at ▶ 12:16, rotating the kernel to vary top-to-bottom detects horizontal edges.
  • ▶ 12:30 The kernel is introduced as a reusable grid that slides over the image, serving as the core tool for producing image-processing effects.
  • ▶ 12:33 Choosing different kernels enables different transformations, such as blurring, edge detection, and sharpening (sharpening noted at ▶ 12:39).
  • ▶ 12:41 In convolutional neural networks, the key idea is to learn kernel values from data rather than designing them by hand.
  • ▶ 12:53 Convolution output length is a practical issue, with one option being to only compute positions where the windows fully overlap, reducing output size.

  • ▶ 13:02 In image processing, the desired output often matches the original image size rather than growing larger.

  • ▶ 13:07 A pure mathematical convolution always produces an array larger than the two inputs, contrasting with the need to truncate or restrict output in applied contexts.

  • ▶ 13:25 In computer science, flipping the kernel before sliding it across an image or signal feels unintuitive and uncalled for.
  • ▶ 13:32 The flip is not an arbitrary CS convention—it is inherited directly from the pure mathematics definition of convolution.
  • ▶ 13:35 In pure math, the flip arises naturally from the underlying structure, making it an elegant operation rather than a strange added step.
  • ▶ 13:43 A practical example compares NumPy's convolve with SciPy's fftconvolve to highlight the real performance impact of a faster convolution algorithm.

  • ▶ 14:13 On large arrays of 100,000 random elements, NumPy's convolve averages 4.87 seconds, while SciPy's fftconvolve averages only 4.3 milliseconds — a speedup of roughly three orders of magnitude.

  • ▶ 14:30 The two functions produce the same output; the dramatic speedup comes entirely from the cleverer internal algorithm, showing that these mathematical ideas have measurable practical value for programmers.

  • ▶ 14:54 Convolution is not specific to probability; for any two lists, the operation is a table of all pairwise products, then summing along diagonals.
  • ▶ 15:08 This pairwise-product view is especially natural for multiplying polynomials, where the lists become coefficients/terms like (1+2x+3x^2) and (4+5x+6x^2).
  • ▶ 15:41 Expanding a polynomial and collecting like terms is exactly the same process as convolution.
  • ▶ 15:48 Multiplying polynomials pointwise at sample inputs is equivalent to convolving their coefficient lists, turning a complex operation into simple multiplication.
  • ▶ 16:10 Convolution is computationally expensive: directly combining two 100-coefficient polynomials requires ~10,000 multiplications (O(n²)), whereas pointwise multiplication is only O(n).
  • ▶ 17:07 Polynomials can be uniquely recovered from finitely many samples — n outputs determine an n-coefficient polynomial — framing sampling as a system of equations where outputs let us solve for unknown coefficients.
  • ▶ 18:04 The system of equations formed by polynomial sampling is linear, which is convenient and sufficient to recover the original polynomial coefficients, enabling an indirect way to compute convolution.
  • ▶ 18:12 The strategy has four steps: treat the lists as polynomial coefficients, sample the polynomials at enough points, multiply the sample values point-wise, and solve the linear system to recover the convolution coefficients.
  • ▶ 18:27 This process is described as a "sneaky backdoor way" to find the convolution, transforming the problem from direct product-and-sum into sampling, pointwise multiplication, and solving a linear system.
  • ▶ 18:31 The naive plan is rejected as computationally inefficient: sampling polynomials and solving the resulting system are both too expensive.
  • ▶ 18:39 Sampling a polynomial already takes on the order of n² operations, and solving the system is equally as difficult as direct convolution.
  • ▶ 18:53 The polynomial–convolution connection is still valuable, but it requires a smarter approach—leading toward roots of unity and the FFT.
  • ▶ 19:18 The key trick is the "freedom of choice" in which inputs we evaluate the polynomial at, allowing specially selected complex numbers instead of arbitrary real inputs.
  • ▶ 19:29 These special inputs are evenly spaced on the unit circle—the roots of unity—which create a "friendlier system" for computation.
  • ▶ 19:46 Evaluating at roots of unity produces a cycling pattern with lots of redundancy, which can be leveraged to save work—this is the conceptual foundation for the FFT. The resulting output is called the discrete Fourier transform of the coefficients.
  • ▶ 20:25 Naive evaluation is redundant; FFT computes coefficients-to-outputs in O(n log n) instead of ~n².
  • ▶ 20:40 FFT is reversible, allowing transformation from outputs back to coefficients, which is essential for convolution.
  • ▶ 20:46 Final convolution algorithm: FFT each input, multiply point-wise, then apply inverse FFT.
  • ▶ 21:23 Polynomial multiplication is a specific instance of convolution, yet understanding it in this context "opens the doors" to an algorithm with far broader relevance.
  • ▶ 21:28 The derived fast convolution algorithm applies "everywhere else where convolutions might come up," including adding probability distributions and large image processing (e.g., filtering or blurring).
  • ▶ 21:34 This transferability means the fast method for polynomial convolution directly benefits other convolution-heavy applications beyond algebra.
  • ▶ 21:38 Seeing the same mathematical operation appear in unrelated fields is a reason to be excited about its broader significance.
  • ▶ 21:48 Homework: explain why ordinary multiplication is essentially a convolution of digits, with carrying as an extra step.
  • ▶ 22:07 Because fast convolution exists, very large integers can be multiplied faster than the elementary method: O(n log n) instead of O(n²), though the numbers must be enormous to be practical.

Video Sections

  • ▶ 0:00 Introduction & Scope (0:00 - 1:59) - Framing why convolutions are everywhere, why they suit visual explanation, and the video’s focus on the discrete case.
  • ▶ 1:59 From Dice to Convolution (1:59 - 7:26) - Dice-sum probabilities motivate the convolution sum, its notation, and a worked discrete example.
  • ▶ 7:26 Convolution in Image Processing (7:26 - 13:43) - Shows blurring, edge detection, kernels, output-size concerns, and the flip-and-slide convention.
  • ▶ 13:43 Polynomials, FFT & Fast Convolution (13:43 - 21:38) - Links convolution to polynomial multiplication and speeds it up using sampling, roots of unity, and the FFT.
  • ▶ 21:38 Conclusion & Homework (21:38 - 22:40) - Highlights the value of cross-area connections, sets up the digit-multiplication homework, and looks ahead.

Exact Transcript

Load the full timestamped transcript on demand and click any time to jump in the video.