Machine Learning
in Fluid Mechanics

Lecture 4 — Surrogate models for discrete predictions

Andre Weiner

Chair of Fluid Mechanics

Gas–liquid mass transfer

Oxygen Taylor bubble with a visible colored wake; motion from left to right

Source: Schlüter group, TU Hamburg · DFG SPP 1740 — Reactive Bubbly Flows

Gas–liquid transport across scales

Gas–liquid transport across scales
Three ways to represent bubbly flow

What controls a rising bubble?

What controls a rising bubble?

Eötvös number: buoyancy and surface tension

Deformation with increasing Eötvös number

Galilei number: inertia and viscosity

Bubble dynamics with increasing Galilei number

Rising-bubble regimes

Rising-bubble regimes

From a drawn map to a predictive model

The same data on linear axes

The same data on linear axes

Raw and logarithmic features

Raw and logarithmic features

A first binary classification problem

The perceptron as an error-correction rule

What do you expect from the training?

  1. Can the loss become zero?
  2. When do the updates stop?
  3. Is the loss monotonically decreasing?

Training the perceptron

Training the perceptron

From hard decisions to class probabilities

A probability thought experiment

  1. P(Y=1∣x)P(Y=1\mid\mathbf x): well inside regime III?
  2. P(Y=1∣x)P(Y=1\mid\mathbf x): well inside regime I?
  3. P(Y=1∣x)P(Y=1\mid\mathbf x): close to the boundary?
  4. P(Y=0∣x)P(Y=0\mid\mathbf x): well inside regime I?

Turning the linear score into probabilities

Maximum likelihood

From likelihood to log-likelihood

Likelihood and log-likelihood landscapes

Likelihood and log-likelihood landscapes

Binary cross entropy

The logistic-regression update

Predicted probabilities and the decision boundary

Predicted probabilities and the decision boundary

Regime I versus regimes II and III

Rising-bubble regimes

Two component models and a learned combination

Combining two logistic models

Two sigmoid component models provide features for the combined classifier

A multilayer perceptron

Two scaled inputs, two sigmoid hidden units and one output, with explicit bias units

Component and combined probability maps

Component and combined probability maps

From two outcomes to K classes

We now distinguish all five rising-bubble regimes.

\[y_i\in\{1,2,\ldots,K\},\qquad K=5\]
\[\widehat{\mathbf y}_i=\mathbf y_\theta(\mathbf x_i),\qquad \widehat y_{ik}\approx P(Y=k\mid\mathbf x_i)\]

Each class receives its own probability.
The class identifiers imply no ordering or distance.

One-hot encoding

One target entry per class, matching the model output:

\[e_k(y)=\begin{cases}1,&y=k,\\0,&y\neq k,\end{cases}\qquad k=1,\ldots,K\]
\[\mathbf y_i=\bigl(e_1(y_i),\ldots,e_K(y_i)\bigr)^{\mathsf T}\]
\[y_{ik}\in\{0,1\},\qquad\sum_{k=1}^{K}y_{ik}=1\]

Exactly one entry identifies the observed class.

Which target vectors are valid?

For \(K=5\) and the observed class \(y_i=4\):

  1. \((0,0,0,1,0)^{\mathsf T}\)
  2. \((0,1,0,0,0)^{\mathsf T}\)
  3. \((0,0,1,1,0)^{\mathsf T}\)
  4. \((0,0,0,0,0)^{\mathsf T}\)
  5. \((0.1,0.1,0.1,0.6,0.1)^{\mathsf T}\)

The MLP with a softmax output layer

\[\mathbf h_i^{(0)}=\mathbf x_i=\bigl(\widetilde{Ga}_i,\widetilde{Eo}_i\bigr)^{\mathsf T}\]
\[\mathbf h_i^{(\ell)}=\phi_\ell\!\left(W^{(\ell)}\mathbf h_i^{(\ell-1)}+\mathbf b^{(\ell)}\right),\quad\ell=1,\ldots,L-1\]
\[\mathbf z_i=W^{(L)}\mathbf h_i^{(L-1)}+\mathbf b^{(L)}\]
\[\widehat y_{ik}=\operatorname{softmax}(\mathbf z_i)_k=\frac{\exp(z_{ik})}{\sum_{j=1}^{K}\exp(z_{ij})}\]

\(0<\widehat y_{ik}<1\),   \(\sum_k\widehat y_{ik}=1\)

\[\widehat c_i=\operatorname*{arg\,max}_{k\in\{1,\ldots,K\}}\widehat y_{ik}\]

Which probability predictions are valid?

For the true target \(\mathbf y_i=(0,0,0,1,0)^{\mathsf T}\):

  1. \((0.01,0.02,0.02,0.93,0.02)^{\mathsf T}\)
  2. \((0.04,0.80,0.04,0.08,0.04)^{\mathsf T}\)
  3. \((0.20,0.20,0.20,0.20,0.20)^{\mathsf T}\)
  4. \((0.10,0.10,0.10,0.90,0.10)^{\mathsf T}\)
  5. \((0.10,-0.10,0.10,0.80,0.10)^{\mathsf T}\)

Categorical cross entropy

We minimize the negative mean log-probability
assigned to the observed classes.

\[\mathcal L_{\mathrm{train}}(\theta)=-\frac{1}{N_{\mathrm{train}}}\sum_{i\in\mathcal T}\sum_{k=1}^{K}y_{ik}\log(\widehat y_{ik})\]
\[=-\frac{1}{N_{\mathrm{train}}}\sum_{i\in\mathcal T}\log(\widehat y_{i,y_i})\]
\[\theta^{(n+1)}=\theta^{(n)}-\eta\,\nabla_\theta\mathcal L_{\mathrm{train}}\!\left(\theta^{(n)}\right)\]

The one-hot target selects the observed-class probability.

One training trajectory, several snapshots

One training trajectory, several snapshots

Validation-based early stopping

Validation-based early stopping

Review — Lecture 4

Why does a reactor model need information from smaller scales?
It cannot resolve every bubble interface, boundary layer and molecular process. Detailed investigations inform closures used at larger scales; the assumptions and uncertainty of those closures remain relevant.
What does the Eötvös number compare, and which length is used here?
Buoyancy relative to surface tension. We use the initial radius: \(Eo=\rho_l gR^2/\sigma\), following the light-gas convention of the reference study.
How does the Galilei number differ from a Reynolds number based on measured rise velocity?
It uses a gravitational velocity scale, \(\sqrt{gR}\), rather than the unknown rise velocity. Here \(Ga=\rho_l\sqrt{gR^3}/\mu_l\).
Why can we not directly use the paper’s hand-drawn boundaries as a classifier?
A picture does not provide an evaluable input–label function. Drawing boundaries also involves subjective judgment; a fitted model gives an explicit rule and quantitative criteria for comparing it with data.
Why do we take logarithms before min–max scaling?
The dimensionless inputs span wide ranges. Logarithms spread small values and compress large ones. Min–max scaling then sets a common range; neither transformation creates samples or guarantees uniform coverage.
Which samples determine the min–max scaling for the validation example?
Only training samples. The same extrema are applied to validation samples, which can consequently fall outside the training interval.
What defines the decision boundary of the linear binary model?
The zero-score line \(z=\mathbf w^{\mathsf T}\mathbf x=0\). The Heaviside rule predicts one for positive scores and zero otherwise.
How does the perceptron correct a wrong prediction?
It applies \(\mathbf w\leftarrow\mathbf w+\eta(y_i-\widehat y_i)\mathbf x_i\). A missed positive raises its score; a false positive lowers it. Correct predictions cause no update.
Does a perceptron correction always lower the total classification error?
No. It moves the current sample’s score in the desired direction but can change predictions at other samples. Finite convergence requires separable data with a positive margin.
What is the difference between the predicted class-one probability and the probability of the observed label?
The model predicts \(\widehat y_i=P_{\mathbf w}(Y=1\mid\mathbf x_i)\). The observed-label probability is \(\widehat y_i\) if the target is one and \(1-\widehat y_i\) if it is zero.
How do we turn a linear score into a probability?
We apply \(\sigma(z)=1/(1+\exp(-z))\). Its value is between zero and one for finite scores; its half-probability boundary is the zero-score line.
Why do likelihood and log-likelihood have the same maximizing weights?
The natural logarithm is strictly increasing. It preserves the ordering of positive likelihood values while turning the probability product into a sum.
How does binary cross entropy relate to maximum likelihood?
It is the negative log-likelihood averaged over samples. We minimize BCE instead of maximizing the likelihood product. A stable implementation evaluates the loss from scores.
Does zero training error imply finite maximum-likelihood weights in unregularized logistic regression?
No. For these separable samples, increasing the magnitude along a separating direction keeps improving the likelihood without a finite maximizing weight vector.
Why do two sigmoid component models allow a nonlinear combined boundary?
Their sigmoid outputs are nonlinear features for the next layer. Combining only their raw affine scores would still give an affine score and a straight boundary.
Why do we use one-hot targets for mutually exclusive classes?
They provide one entry per class, matching the predicted probability vector, without imposing a numerical distance between class identifiers. Integer targets can implement the same loss implicitly.
What properties make softmax suitable for K mutually exclusive classes?
Its components are positive and sum to one. Adding the same constant to all logits leaves them unchanged, and the largest logit has the largest probability.
How is the categorical prediction obtained from softmax probabilities?
We select the class with the largest probability, using a stated tie convention. With more than two classes, the winning probability need not exceed one half.
How can validation cross entropy worsen while the number of validation errors stays unchanged?
Cross entropy also measures confidence in the observed labels. A model can become more confidently wrong without changing which class wins.
What state does early stopping return, and why is validation not an independent test score?
It restores the checkpoint selected by validation loss, rather than the last state. Because validation guided model selection, it does not provide an independent final test score.