---
title: "Problem set 12: learning systems in hardware and signals"
heading: "Problem set 12: design problems for keyword spotters on batteries, spectral features, ADC resolution, layer timing on a roofline, steady-state sensor fusion, anomaly thresholds, fixed-point inference, serving energy, data logging, federated updates, detection with diversity, PCA compression of sensor arrays, control horizons and on-chip memory"
eyebrow: S14 · Problem set 12
type: problems
---

::: hook
The last set before the final puts learning into electrical systems: models that must run on a battery or a microcontroller, features computed from sampled signals, detectors whose false alarms are counted per day, and servers whose cost is energy per token. The numbers come from the course; the constraints come from the hardware.
:::

::: pool
pick: 12

::: check
kind: parts
given: H = 16 | 32; K = 3 | 5; C = 8 | 32; F = 16 | 64; E = 2 | 10; r = 1 | 10; Q = 200 | 1000

## A keyword spotter's main layer is a {K} × {K} convolution from {C} to {F} channels with a {H} × {H} output. Each multiply-add costs {E} pJ, and the device runs {r} inferences a second from a 3 V battery of {Q} mAh.

::: part
answer: H^2*K^2*C*F/1e6
unit: million
tolerance: 0.5%

### How many million multiply-adds does the layer take?

::: misses
- [any] $H^2K^2CF$.
:::
:::

::: part
answer: H^2*K^2*C*F*E*1e-12*1e6
unit: µJ
tolerance: 0.5%

### How much energy does one inference of it take?

::: misses
- [any] Operations times energy per operation.
:::
:::

::: part
answer: Q*3.6*3/(H^2*K^2*C*F*E*1e-12*r)/3600
unit: h
tolerance: 0.5%

### How long would the battery last if this layer were the only load?

::: misses
- [any] Battery energy (mAh × 3.6 × V joules) over power.
:::
:::
:::

::: check
kind: parts
given: f = 8000 | 16000 | 48000; d = 10 | 31.25 | 62.5; h = 2 | 4

## A sound classifier computes spectra at {f} samples a second with {d} Hz resolution, hopping by 1/{h} of a frame.

::: part
answer: f/d
unit: samples
tolerance: 0.5%

### How long is each frame?

::: misses
- [d/f] Resolution is the sample rate over the frame length.
- [any] $N = f_s/\Delta f$.
:::
:::

::: part
answer: h*d*5*(f/d)*log(f/d)/log(2)/1e6
unit: MFLOP/s
tolerance: 0.5%

### At about 5N log₂ N operations per FFT, how many million operations a second do the spectra take?

::: misses
- [any] Frames per second, $h\,\Delta f$, times $5N\log_2N$.
:::
:::
:::

::: check
kind: parts
given: V = 2 | 5; n = 0.5 | 2; k = 2 | 4

## A sensor's noise is {n} mV RMS over a {V} V input range, and the ADC's quantization noise should be {k} times smaller.

::: part
answer: sqrt(12)*n/k
unit: mV
tolerance: 0.5%

### How large can the quantization step be?

::: misses
- [n/k] Quantization noise is the step over $\sqrt{12}$.
- [any] $\Delta = \sqrt{12}\,\sigma_n/k$.
:::
:::

::: part
answer: ceil(log(V*1000/(sqrt(12)*n/k))/log(2))
unit: bits
tolerance: 0

### How many bits does the ADC need?

::: misses
- [any] $\lceil\log_2(V/\Delta)\rceil$.
:::
:::
:::

::: check
kind: parts
given: D = 1024 | 4096; H = 1024 | 4096; B = 1 | 32 | 256; F = 100 | 400; W = 1 | 2

## An int8 dense layer maps {D} inputs to {H} outputs at batch {B}, on a chip with {F} TFLOP/s and {W} TB/s.

::: part
answer: 2*D*H*B/(F*1e12)*1e6
unit: µs
tolerance: 0.5%

### How long does its arithmetic take?

::: misses
- [any] 2DHB operations.
:::
:::

::: part
answer: ((2*D*H*B/(F*1e12) + D*H/(W*1e12)) + abs(2*D*H*B/(F*1e12) - D*H/(W*1e12)))/2*1e6
unit: µs
tolerance: 0.5%

### How long does the layer take, reading its weights once?

::: misses
- [any] The larger of the arithmetic and weight-reading times.
:::
:::
:::

::: check
kind: parts
given: q = 0.01 | 0.1; r = 0.5 | 4

## A slowly drifting quantity changes by a random walk with variance {q} per step and is measured each step with noise variance {r}.

::: part
answer: (-q + sqrt(q^2 + 4*q*r))/2
tolerance: 0.5%

### What steady-state posterior variance does a Kalman filter reach?

::: misses
- [sqrt(q*r)] That's the leading term; solve $P = (P + q)r/(P + q + r)$ exactly.
- [any] Solve $P^2 + qP - qr = 0$.
:::
:::

::: part
answer: ((-q + sqrt(q^2 + 4*q*r))/2 + q)/((-q + sqrt(q^2 + 4*q*r))/2 + q + r)
tolerance: 0.5%

### What gain does it apply to each measurement?

::: misses
- [any] $K = (P + q)/(P + q + r)$.
:::
:::
:::

::: check
kind: parts
given: f = 0.01 | 0.001; R = 1 | 100; k = 2 | 3

## A two-feature Gaussian model of normal operation flags samples whose squared Mahalanobis distance exceeds a threshold, at {R} samples a second, raising an alarm after {k} flags in a row.

::: part
answer: -2*ln(f)
tolerance: 0.5%

### What threshold flags a fraction {f} of normal samples?

::: misses
- [-ln(f)] In two dimensions $P(d^2 > t) = e^{-t/2}$.
- [any] $t = -2\ln f$.
:::
:::

::: part
answer: f^k*R*86400
tolerance: 0.5%

### About how many false alarms per day result, with independent samples (a number of alarms)?

::: misses
- [f*R*86400] An alarm needs k flags in a row.
- [any] $f^k$ per sample.
:::
:::
:::

::: check
kind: parts
given: D = 16 | 128; c = 1 | 4; f = 16 | 80; e = 0.5 | 3

## A microcontroller runs fixed-point logistic regression on {D} features, at {c} cycles per multiply-add plus 200 cycles for the sigmoid, clocked at {f} MHz and drawing {e} mW.

::: part
answer: (D*c + 200)/f
unit: µs
tolerance: 0.5%

### How long does an inference take?

::: misses
- [D*c/f] Include the sigmoid's cycles.
- [any] Cycles over clock rate.
:::
:::

::: part
answer: (D*c + 200)/f*e*1e-3
unit: µJ
tolerance: 0.5%

### How much energy does it use?

::: misses
- [any] Power times time.
:::
:::
:::

::: check
kind: parts
given: t = 20 | 50; U = 64 | 512; P = 700 | 10000

## A server gives each of {U} users {t} tokens a second, drawing {P} W.

::: part
answer: t*U
unit: tokens/s
tolerance: 0.5%

### What is its total throughput?

::: misses
- [any] Users times rate.
:::
:::

::: part
answer: P/(t*U)
unit: J
tolerance: 0.5%

### How much energy does each token take?

::: misses
- [any] Power over throughput.
:::
:::
:::

::: check
kind: parts
given: S = 8 | 64; R = 100 | 10000; b = 12 | 16 | 24; G = 32 | 512

## A logger records {S} channels at {R} samples a second, {b} bits each, onto a {G} GB card.

::: part
answer: S*R*b/8*86400/1e9
unit: GB
tolerance: 0.5%

### How much data does it collect per day?

::: misses
- [S*R*b*86400/1e9] Divide bits by 8.
- [any] Channels × rate × bits per day.
:::
:::

::: part
answer: G/(S*R*b/8*86400/1e9)
unit: days
tolerance: 0.5%

### How many days fill the card?

::: misses
- [any] Capacity over daily volume.
:::
:::
:::

::: check
kind: parts
given: P = 1 | 10 | 100; u = 2 | 20; b = 32 | 8

## Each device in a federated system uploads a model update of {P} million parameters at {b} bits each over a {u} Mb/s uplink.

::: part
answer: P*1e6*b/(u*1e6)
unit: s
tolerance: 0.5%

### How long does one upload take?

::: misses
- [P*1e6*b/8/(u*1e6)] The link rate is in bits, not bytes.
- [any] Bits over bit rate.
:::
:::
:::

::: check
kind: parts
given: E = 4 | 7 | 9.6

## A binary detector's two classes produce antipodal features in Gaussian noise at an energy-to-noise ratio of {E} dB per decision.

::: part
answer: 0.5*erfc(sqrt(10^(E/10)))
tolerance: 1%

### What is its error rate?

::: misses
- [0.5*erfc(sqrt(10^(E/10)/2))] Antipodal classes give $Q(\sqrt{2E/N_0}) = \frac12\text{erfc}(\sqrt{E/N_0})$.
- [any] $\frac12\text{erfc}(\sqrt{E/N_0})$.
:::
:::

::: part
answer: 0.5*erfc(sqrt(2*10^(E/10)))
tolerance: 1%

### And when it combines two independent observations of each decision coherently?

::: misses
- [any] Combining doubles the energy.
:::
:::
:::

::: check
kind: parts
given: D = 64 | 256; r = 0.5 | 0.8; M = 4 | 16

## A sensor array's {D} channels have covariance eigenvalues proportional to $r^k$ (k = 1, 2, …) with r = {r}, and PCA keeps {M} components.

::: part
answer: D/M
tolerance: 0.5%

### By what factor does it compress each sample?

::: misses
- [any] Channels over components.
:::
:::

::: part
answer: -10*M*log(r)
unit: dB
tolerance: 1%

### What signal-to-reconstruction-error ratio does it achieve (treating the spectrum as infinitely long)?

::: misses
- [-10*log(r)] The discarded share is $r^M$.
- [any] Total over discarded variance: $1/r^M$.
:::
:::
:::

::: check
kind: parts
given: R = 10 | 100 | 1000; T = 1 | 10; e = 0.001 | 0.01

## A learned power-management policy acts {R} times a second and should look about {T} s ahead.

::: part
answer: 1 - 1/(R*T)
tolerance: 0.5%

### What discount factor gives that horizon?

::: misses
- [any] $1/(1 - \gamma) = RT$.
:::
:::

::: part
answer: ln(e)/ln(1 - 1/(R*T))
unit: sweeps
tolerance: 0.5%

### How many value-iteration sweeps shrink an error by a factor of {e}?

::: misses
- [any] $\ln\epsilon/\ln\gamma$.
:::
:::
:::

::: check
kind: parts
given: S = 256 | 1024; A = 40 | 160; b = 8 | 4

## A microcontroller has {S} KB of RAM, {A} KB of which hold activations and buffers; the rest holds {b}-bit weights.

::: part
answer: (S - A)*1024*8/b
unit: parameters
tolerance: 0.5%

### How many parameters fit?

::: misses
- [(S - A)*1000*8/b] A kilobyte is 1024 bytes here.
- [any] Free bytes × 8/b.
:::
:::

::: part
answer: floor(((S - A)*1024*8/b - 10)/(64 + 1 + 10))
unit: units
tolerance: 0

### How wide a 64-input hidden layer, followed by a 10-output layer, fits (with biases)?

::: misses
- [any] Solve $65H + 10(H + 1) \le$ the budget.
:::
:::
:::

::: check
kind: parts
given: m = 0.5 | 1; s = 0.01 | 0.03; N = 64 | 256

## An analog in-memory multiplier computes a dot product of {N} terms, each a weight of size {m} times a unit input; each weight's conductance varies randomly by a fraction {s}.

::: part
answer: s*m*sqrt(N)
tolerance: 0.5%

### What is the standard deviation of the result's error?

::: misses
- [s*m*N] Independent errors add in quadrature.
- [any] $\sigma m\sqrt N$.
:::
:::

::: part
answer: 20*log(N*m/(s*m*sqrt(N)))
unit: dB
tolerance: 0.5%

### What signal-to-noise ratio does a full-scale result (all terms adding) have?

::: misses
- [any] $20\log[Nm/(\sigma m\sqrt N)]$.
:::
:::
:::
:::
