So far almost every model in the course was linear: \mathbf{y} = X\boldsymbol\beta, solved by least squares, limma or a penalty. This week is about what lies beyond.
“Linear” means linear in the parameters\boldsymbol\beta. A curve can still be a linear model.
Some biology is truly nonlinear: a dose–response curve. We fit it with nls(), which has to search.
A neural network is matrix × vector, then a bend, repeated. Without the bend it collapses to one matrix.
Flat vs curved latent spaces: PCA gives a flat map of the cells; some data need a curved one. That sets up UMAP and variational autoencoders.
Pictures and small examples only.
“Linear” means linear in the parameters
Growth rate of a bacterium peaks at some temperature: a curve. Yet
\text{growth} = a + b\cdot\text{temp} + c\cdot\text{temp}^2
is a linear model. \text{temp}^2 is just one more column of X:
X = \begin{pmatrix} 1 & 22 & 484 \\ 1 & 24 & 576 \\ 1 & 26 & 676 \\ \vdots & \vdots & \vdots \end{pmatrix}, \qquad \boldsymbol\beta = \begin{pmatrix} a \\ b \\ c \end{pmatrix}
lm(growth ~ temp + I(temp^2)) gives c = -0.0064, optimum at 33.0\,^\circC.
“Linear” is about a, b, c, not about the shape in temp.
A model is linear if parameters only multiply data
Ask: is every parameter only multiplying something I can compute from the data?
Model
Linear in the parameters?
y = a + b x + c x^2
yes: columns 1, x, x^2
y = a + b \log(x)
yes: column \log(x)
y = a + b\sin(2\pi t/24) + c\cos(2\pi t/24)
yes: a Fourier basis with a known period
y = a + b x + c\, x z
yes: an interaction column
y = \dfrac{a\, x}{b + x} (Michaelis–Menten)
no: b sits in the denominator
y = a\, e^{b x}
no: b sits in the exponent
y = a\sin(2\pi t / P), P unknown
no: P sits inside the sine
Linear in the parameters → one exact least-squares solution. Not linear → the computer has to search.
A truly nonlinear model: dose–response
Cells treated with a drug at 8 concentrations, in duplicate. Viability falls along an S-shaped curve (the Hill or four-parameter logistic curve):
The formula is the curve written out; R treats every name that is not in the data as a parameter.
Starting values are required. Read them off the plot: plateaus near 100 and 0, half-way at about 1 µM.
A bad start can fail: from ec50 = 10 R stops with “Missing value or an infinity produced”.
EC50 = 0.85 µM, with a standard error, as for any regression coefficient.
Local minima: where you start matters
A clock reporter, measured every 2 h. Fit \text{signal} = m + a\cos(2\pi t/P) + b\sin(2\pi t/P) with the periodP unknown.
Start at P = 20 h → P = 23.6 h, SSE 18: the circadian rhythm.
Start at P = 12 h → P = 10.7 h, SSE 97: a dip in the SSE curve, but not the lowest. A local minimum.
R reports success both times. Plot the fit, and try several starts.
A neural network is a matrix, a bend, then a matrix
\begin{pmatrix} u \\ v \\ w \end{pmatrix} = \text{ReLU}\!\left(A\begin{pmatrix} x \\ y \end{pmatrix} + \mathbf{b}\right), \qquad \text{out} = C\begin{pmatrix} u \\ v \\ w \end{pmatrix} + d, \qquad \text{ReLU}(s) = \max(0, s)
Every line is one number in A or C. Training = searching for all of them at once, as nls() does.
Check: (2, 1)\cdot(1, 2) = 4, the “without the bend” answer.
2 layers, or 100 layers, of matrices with no bend in between = one matrix. Shifts \mathbf{b}, d do not help: still a straight-line map.
So a deep network without nonlinearities is just a linear model, however big.
The bend between the matrices is what lets a network draw curves.
Many bends let a network follow any smooth curve
One input (log dose), three hidden units. Each unit is a hinge: flat, then rising. The output adds the hinges with weights: a bent line that follows the dose–response data.
More hidden units → more hinges → any smooth curve, as closely as you like.
With the hinges fixed, the output weights are an ordinary lm(): the hinges are just columns of X.
The price: many weights with no biological meaning, which need lots of data, a penalty or cross-validation, and a search with local minima.
Some data need a curved map, not a flat one like PCA
Cycling cells trace out a ring in two marker genes. One number should be enough to say where a cell is in the cycle.
PC1 (flat): the two marked cells, in different phases, get the same score. A straight axis folds the ring onto itself.
The angle round the ring (Polar coordinates) keeps all phases in order: a curved coordinate, which no matrix can give.
Where this week goes
Map from genes to a few numbers
Map back to genes
PCA
flat (a matrix)
flat (a matrix)
UMAP
curved, built from a kNN graph
none
Autoencoder / VAE
curved: a neural network
curved: a neural network
kNN graphs & UMAP: a curved 2D picture of the cells, drawn from who-is-near-whom.
Variational autoencoders: the encoder and decoder are networks like today’s, so the latent space can bend. With no bends, they reduce to PCA.
Summary
Idea
In one line
Linear model
linear in the parameters: x^2, \log x, sines and interactions are just columns of X
Nonlinear model
a parameter sits inside the curve (EC50, a period, a Michaelis constant)
nls()
least squares by search: starting values, steps, repeat
Local minimum
a fit that converged but is not the best; plot it, try several starts
Neural network
matrix × vector, then ReLU, repeated; weights found by search
No bend
stacked matrices collapse to one matrix (CA): a linear model
Latent space
PCA gives a flat map; rings and trajectories need a curved one