Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A researcher trained five networks on five geoscience problems and reports a result for each. Each run has one hidden error. The researcher’s code runs as written, and its evidence (learning curves, confusion matrices, forecasts against observations) is rendered below each case. Your job, for each case:

  1. Diagnose. Name the cause from the evidence, in one sentence, before opening any code.

  2. Fix. Edit the function c<k>_fix() so the pipeline no longer has the error.

  3. Check. Run the cell Evaluate your fix. It tests the numbers your fix produces against the success test stated in the case’s context card (not your code), and prints PASS or FAIL.

As written, every Evaluate your fix cell prints FAIL, because c<k>_fix() still holds the researcher’s pipeline. Our fix (c<k>_our_fix(), a separate function, so it never replaces yours) and a What went wrong box follow each case; both are folded.

Words used here. The researcher is the fictional scientist whose code, evidence and claim you are given; the error is in their run. Your fix is what you write in c<k>_fix(). Our fix is one worked solution, folded until you open it; other fixes can pass the same test. Reference run (case 5 only) is the same model, data and seed trained with the loop you wrote in 4.7 section 2.4: a control experiment that shows what a correct run of this model gives.

Learning outcomes. After the five cases you can:

  • read learning curves, a confusion matrix and an error-against-time plot as evidence for one specific error;

  • link each error to the training and evaluation decisions of 4.7 and to items of the rubric;

  • state, before running it, which number would show that a fix worked, and test it.

CaseGeoscience systemWhat the researcher shows you
1Local earthquakes at one seismic stationA detector that scores 0.97 on its test set
2Igneous rocks of a continental arcThe network calls every rock granite
3A volcano during a seismic swarmA swarm detector with 98% accuracy, ready for the observatory
4A GNSS station moving with its plateA GNSS forecaster that beats persistence, until it does not
5Igneous rocks along a differentiation trendThe training loss climbs back up

In class (lecture 25). Teams of 3 or 4. For each case the slides show the context card and the evidence figure; you have 4 minutes to name the cause, propose a fix, and say which number would show the fix worked. One point for each. Then the reveal.

Alone. Run the setup cell, then any case: each case needs only the setup cell and its own cells (all its names start with c1_ to c5_). The whole notebook runs in under a minute on a laptop CPU; case 3, the longest, takes 20 to 35 s, each other case under 10 s. All data are synthetic, from mlgeo_synth, so the true cause of each error is known.

🖥️ Lecture slides, session 25, lab II (Mon Nov 30)

Setup

The shared training loop of 4.7 (one_epoch, train), a plot of the learning curves (plot_curves) and one line of an evaluation table (check). Every case uses them.

Case 1: A detector that scores 0.97 on its test set

A researcher trained an earthquake detector for one seismic station. Before using it on the continuous record, they show you this.

Geoscience systemLocal earthquakes (magnitude 1 to 4, 5 to 80 km away) recorded by one vertical-component seismometer, in background noise whose spectrum changes from record to record (power falls as f−af^{-a}, with aa between 0.5 and 2). Dominant frequency of the earthquakes: 2 to 8 Hz. Signal-to-noise ratio (SNR, peak earthquake amplitude over noise standard deviation): 0.5 to 20.
Data2000 records of 30 s at 25 Hz: 1000 contain an earthquake, 1000 contain only noise (mlgeo_synth.seismogram_dataset, seed 1). To get more training samples, each record is cut into 5 windows of 25 s, shifted by 0.5 s: 10 000 windows.
Input and targetInput: the amplitude spectrum of one window, log10, averaged in 20 frequency bands from 0.5 to 12 Hz, with its mean removed (so the amplitude scale is dropped). Target: earthquake (1) or noise (0).
How it was splitThe 10 000 windows were shuffled and split 60 / 20 / 20 into training (6000), validation (2000) and test (2000) windows.
New events1000 records the station recorded later (500 earthquakes, 500 noise; seed 2), cut into windows the same way (5000 windows). The researcher computed this score but did not use it for any choice.
ModelFully connected network 20 → 64 → 64 → 2 with ReLU; inputs standardized with the mean and standard deviation of the training windows.
How it was trainedCross-entropy loss, Adam, learning rate 0.001, batch of 64, 60 epochs, seed 0; the epoch with the lowest validation loss is kept.
The researcher’s claim“Validation accuracy 0.962 and test accuracy 0.971: the detector finds earthquakes even when they are below the noise level.”
Success test for your fixNo record has windows in both the training and the validation set; the validation accuracy and the new-events accuracy agree within 0.06; the new-events accuracy does not drop more than 0.06 below the researcher’s; the new-events accuracy is the number you report.
best epoch 59 of 60
accuracy, training     0.999
accuracy, validation   0.964
accuracy, test         0.971
accuracy, new events   0.755
earthquakes detected, by SNR bin: ['0.5-1', '1-2', '2-5', '5-20']
  test windows  [0.91 0.95 0.97 1.  ]
  new events    [0.42 0.63 0.86 0.98]
<Figure size 1200x400 with 3 Axes>

What do you see?

  1. In panel (b), the validation and test windows agree with each other, and the new events score much lower. Both are earthquakes and noise at the same station, drawn from the same magnitudes, distances, SNR and noise spectra. What differs between them?

  2. In panel (c), the test windows with SNR between 0.5 and 1 are earthquakes whose peak amplitude is below the standard deviation of the noise. Is the detection rate in that bin physically plausible? How does it compare with the new events?

  3. Which step of the pipeline could make the validation and test windows easier than the new events?

Your diagnosis (one sentence):

 

                                                   value
best epoch (your fix)                                 59
validation accuracy (your split)                   0.964
validation samples with their record in training      0.975   target 0 (no record on both sides) FAIL
|validation - new events|                          0.208   target <= 0.06                FAIL
new-events accuracy                                0.755   target >= 0.695 (researcher - 0.06) PASS

Case 1 result: FAIL.   Number to report: new-events accuracy 0.755   (shared records: 0.975)
<Figure size 1200x400 with 3 Axes>

Our fix below (click to open it).

Notebook Cell
researcher's validation windows whose record also has a window in training: 0.975
Output
                                                   value
best epoch (our fix)                                   1
validation accuracy (your split)                   0.779
validation samples with their record in training      0.000   target 0 (no record on both sides) PASS
|validation - new events|                          0.013   target <= 0.06                PASS
new-events accuracy                                0.792   target >= 0.695 (researcher - 0.06) PASS

Case 1 result: PASS.   Number to report: new-events accuracy 0.792   (shared records: 0.000)
<Figure size 1200x400 with 3 Axes>

Case 2: The network calls every rock granite

Geoscience systemIgneous rocks of a continental arc. Basalt (mafic), andesite (intermediate) and granite (felsic) record how far a magma differentiated: as it evolves it gains SiO2_2 and K and loses FeO, MgO and CaO, and its density and magnetic susceptibility drop.
DataOne sample is one rock specimen; 4,000 specimens. Nine measurements per specimen, each in the unit its instrument reports: six major oxides from laboratory XRF (wt%), potassium from a portable XRF (ppm), bulk density (kg/m3^3), magnetic susceptibility from a handheld meter (10−6^{-6} SI). Synthetic: mlgeo_synth.geochem_table with a measurement-noise floor.
Input and targetX: the nine columns as they appear in the spreadsheet. Y: the lithology; granite 55%, basalt 35%, andesite 10% of the specimens.
SplitRandom, stratified by lithology: 2,400 training, 800 validation and 800 test specimens. The test specimens are held out.
ModelFully connected network 9 → 32 → 32 → 3, ReLU, one score per lithology, cross-entropy loss.
TrainingA colleague’s script: stochastic gradient descent (SGD), learning rate 0.1, batches of 64 specimens, 40 epochs, seed 2; the epoch with the lowest validation loss is kept (the shared train()).
The researcher’s claim“Validation accuracy 0.556, and the network calls 797 of the 800 validation specimens granite. These nine measurements cannot tell the three lithologies apart.”
Success test for your fixOn the 800 held-out test specimens: training loss at the last epoch below half the loss of predicting the class proportions; test accuracy at least that of a logistic regression fit to the same spreadsheet; andesite recall at least the logistic regression’s.
   SiO2 (wt%)  Al2O3 (wt%)  FeO (wt%)  MgO (wt%)  CaO (wt%)  Na2O (wt%)   K (ppm)  density (kg/m3)  susceptibility (1e-6 SI) lithology
0       74.54        14.87       4.94       0.01       8.60        2.59  26536.69          2503.87                     39.80   granite
1       87.95        14.93       2.66       0.01       1.31        3.59  30855.86          2672.75                    226.73   granite
2       57.76        15.50       9.37       9.45      10.47        3.13   8198.22          2906.34                   2556.57    basalt
3       61.85        14.40       4.14       0.01       0.01        3.70  27460.08          2529.44                    187.02   granite
4       44.84        14.38       8.46       5.64       8.74        3.37  19369.96          3032.31                    668.00    basalt 

training samples 2400, validation 800, test 800 (held out)
training loss: epoch 0 0.948, epoch 39 0.923
best validation epoch 16, validation accuracy 0.556
<Figure size 1200x400 with 2 Axes>

What do you see?

  1. The training loss stays between 0.92 and 0.95 for all 40 epochs. What loss does a model reach if it ignores the measurements and predicts the class proportions (55%, 35%, 10%) for every specimen? Compute −∑kpkln⁡pk-\sum_k p_k \ln p_k.

  2. In notebook 4.7 (section 1), the scatter of MgO against SiO2_2 separates granite from basalt by eye. Is the information missing from these nine columns, or is the network not using it? Which quick experiment would tell the two apart?

  3. Look at the printed rows of the table: which numbers enter the first layer of the network?

Your diagnosis (one sentence):

 

your fix; class-proportion loss 0.928 nats; logistic baseline: accuracy 0.963, andesite recall 0.793
training loss, last epoch (nats)                   0.923   target < 0.464 (half)         FAIL
test accuracy                                      0.557   target >= 0.963 (logistic)    FAIL
andesite recall, test                              0.000   target >= 0.793 (logistic)    FAIL
<Figure size 1200x400 with 2 Axes>
Case 2, your fix: FAIL

Our fix below (click to open it).

Notebook Cell
Output
our fix; class-proportion loss 0.928 nats; logistic baseline: accuracy 0.963, andesite recall 0.793
training loss, last epoch (nats)                   0.051   target < 0.464 (half)         PASS
test accuracy                                      0.985   target >= 0.963 (logistic)    PASS
andesite recall, test                              0.939   target >= 0.793 (logistic)    PASS
<Figure size 1200x400 with 2 Axes>
Case 2, our fix: PASS

Case 3: A swarm detector with 98% accuracy, ready for the observatory

One seismometer sits on a volcano during a seismic swarm. Small local earthquakes arrive among the continuous background noise of the station (wind, ocean, the volcano itself). The observatory wants an automatic detector that flags every 30-s window holding an earthquake, so that the analyst on duty reviews those windows and nothing else.

Geoscience systemVertical ground velocity at one station during a swarm: earthquakes of magnitude 1 to 4, 5 to 80 km from the station (P and S waves), on top of background noise whose amplitude falls with frequency.
Data7983 windows of 30 s, 100 samples per second: 66.5 hours of record (synthetic, mlgeo_synth.seismogram_dataset). An analyst marked 183 windows as holding an earthquake (signal-to-noise ratio of 2 or more).
Input and targetInput: one window band-passed 2 to 8 Hz, resampled to 20 samples per second (600 values) and divided by its largest absolute value. Target: 1 for an earthquake window, 0 for noise.
SplitIn time: the first 50% of the record (33.3 h) for training, the next 25% for validation, the last 25% (16.6 h) for testing.
ModelConvolutional network: two layers of 8 kernels of 9 samples, max pooling, one score per window. The probability of an earthquake is the sigmoid of the score; the detector fires when it is 0.5 or more.
TrainingBinary cross-entropy (BCEWithLogitsLoss), Adam, learning rate 0.001, batches of 128, 15 epochs, the best validation epoch kept, seed 0.
Claim“Accuracy 0.98 on 16.6 hours of record the network never saw. The detector is ready to run at the observatory.”
Success test for your fixThe observatory’s requirement: at least 3 of 4 earthquakes detected (recall 0.75) and at most one false alarm per hour (24 per day). It must hold on the validation record, where the threshold and every other choice are made, and on the 16.6 h of test record.
record: 7983 windows = 66.5 h; test: 1996 windows = 16.6 h
test accuracy: 0.979
case 3 pipeline: 3.4 s
<Figure size 1200x400 with 2 Axes>

What do you see?

  1. Read the confusion matrix row by row. How many earthquakes are in the 16.6 hours of test record, and how many did the detector report?

  2. What accuracy would a detector reach that never fires at all? Compare it with 0.98.

  3. What two numbers does the analyst on duty need to know about this detector, that accuracy does not give?

Your diagnosis (one sentence):

 

Case 3, your fix: 16.6 h of test record, 42 earthquakes, threshold 0.500
researcher (threshold 0.5): accuracy 0.979, recall 0.00, false alarms/day 0.0
your fix (threshold 0.50): accuracy 0.979, recall 0.00, false alarms/day 0.0
validation: earthquakes detected (recall)           0.00   target >= 0.75                FAIL
validation: false alarms per day                     0.0   target <= 24 (1 per hour)     PASS
test: earthquakes detected (recall)                 0.00   target >= 0.75                FAIL
test: false alarms per day                           0.0   target <= 24 (1 per hour)     PASS
Case 3 verdict: FAIL
(1.1 s)
<Figure size 1200x400 with 2 Axes>

Our fix below (click to open it).

Notebook Cell
Output
validation: threshold 0.44, recall 0.98, false alarms/day 11.5
Case 3, our fix: 16.6 h of test record, 42 earthquakes, threshold 0.440
researcher (threshold 0.5): accuracy 0.979, recall 0.00, false alarms/day 0.0
our fix (threshold 0.44): accuracy 0.992, recall 0.95, false alarms/day 18.8
validation: earthquakes detected (recall)           0.98   target >= 0.75                PASS
validation: false alarms per day                    11.5   target <= 24 (1 per hour)     PASS
test: earthquakes detected (recall)                 0.95   target >= 0.75                PASS
test: false alarms per day                          18.8   target <= 24 (1 per hour)     PASS
Case 3 verdict: PASS
(1.1 s)
<Figure size 1200x400 with 2 Axes>

Case 4: A GNSS forecaster that beats persistence, until it does not

Geoscience systemA continuous GNSS station on a plate interior, moving east at a steady 12 mm/yr (interseismic plate motion), with an annual and semi-annual hydrological loading cycle of a few mm and temporally correlated (flicker and random-walk) noise. Synthetic daily east positions from mlgeo_synth.gnss_series (10 years, 2015-2024, seed 4), standing in for a Nevada Geodetic Laboratory daily position series.
DataOne sample is 30 consecutive daily east positions (mm) and the position on the next day. 3,622 samples, one per day from 2015-01-31 to 2024-12-30.
Input and targetInput: the east positions of the last 30 days (mm). Target: the east position tomorrow (mm).
SplitBy time. Test: every day of 2022-2024 (1,095 samples), never used for a choice. Validation: every April, August and December of 2015-2021 (644 samples), so that validation covers all seasons. Training: the other months of 2015-2021 (1,883 samples).
ModelFully connected network, 30 inputs, two hidden layers of 32 neurons with tanh activations, one output. Inputs and target standardized with the mean and standard deviation of the training positions.
TrainingShared train() loop: mean squared error, Adam, learning rate 0.001, batch of 64, 60 epochs, seeded starting weights (seed 4), the epoch with the lowest validation loss kept.
BaselinePersistence: tomorrow’s position is today’s position.
Success test for your fixOn the test days of 2022-2024: (1) mean absolute error at least 5% below persistence on the same days; (2) no growth of error with time, measured as the MAE of 2024 divided by the MAE of 2022, at most 1.2.
The researcher’s claim“Validation mean absolute error (MAE) is 1.34 mm against 1.44 mm for persistence. The network forecasts tomorrow’s position better than repeating today’s, and is ready to run on new days.”
MAE (mm)                    network  persistence
validation (2015-2021)         1.34         1.44
test (2022-2024)               8.57         1.53
  test, 2022                   3.06         1.49
  test, 2023                   8.19         1.55
  test, 2024                  14.46         1.54
<Figure size 1200x400 with 2 Axes>

What do you see?

  1. On validation the network beats persistence; on the test years it does not. Besides the date, what differs between a validation day and a test day?

  2. In panel b, when does the prediction leave the observations, and where is it then relative to the shaded band?

  3. The test error grows from 2022 to 2024. Which property of this station grows at the same pace?

Your diagnosis (one sentence):

 

your fix: next-day forecasts of 1095 test days, 2022-2024
test MAE (mm)                                       8.57   target <= 1.45 (0.95 x pers.) FAIL
MAE 2024 / MAE 2022                                 4.72   target <= 1.20                FAIL
Case 4: FAIL
<Figure size 1200x400 with 2 Axes>

Our fix below (click to open it).

Notebook Cell
Output
our fix: next-day forecasts of 1095 test days, 2022-2024
test MAE (mm)                                       1.31   target <= 1.45 (0.95 x pers.) PASS
MAE 2024 / MAE 2022                                 1.02   target <= 1.20                PASS
Case 4: PASS
<Figure size 1200x400 with 2 Axes>

Case 5: The training loss climbs back up

A researcher wants to know whether a network classifies igneous rocks better than a linear boundary does. Granite, andesite and basalt sit along one differentiation trend: the more evolved the magma, the more SiO2_2 and K2_2O and the less FeO, MgO and CaO. The question is whether the boundaries between the three rock types along that trend are curved enough to need hidden layers.

Geoscience systemIgneous rocks along a differentiation trend, basalt to andesite to granite (synthetic table, mlgeo_synth.geochem_table, the table of 4.7)
Data3000 rock samples. One sample is one rock: 9 measurements, seven major-element oxides (wt%), density (g/cm3^3) and magnetic susceptibility (SI). Granite 56%, basalt 34%, andesite 10%
Input and targetInput: the 9 measurements. Target: the rock type (3 classes)
SplitRandom, 2250 training and 750 validation samples. Features standardized with the mean and standard deviation of the training samples only, then the measurement-noise floor of 4.7 (one standard deviation per feature) added to every sample
ModelFully connected network, 9 inputs, two hidden layers of 64 neurons with ReLU, 3 class scores (4995 weights). Starting weights random with seed 0
TrainingCross-entropy, Adam, learning rate 0.001, batches of 128, 30 epochs. The researcher wrote their own epoch loop (in the code below) and passed it to the course’s train(), which keeps the weights of the epoch with the lowest validation loss
ComparisonReference run: the same model, split, seed and settings, trained with the epoch loop of 4.7 section 2.4 (the four lines you wrote). It shows what a correct run of this model gives, as a control does in a lab experiment. A logistic regression (scikit-learn) was fit on the same split
The researcher’s claim“The network reaches a validation accuracy of 0.939, below the 0.951 of logistic regression. Hidden layers do not help on this table; we report the linear model.”
Success test for your fixSame data, model, seed and 30 epochs. Validation accuracy within 0.005 of the reference run; training loss at the last epoch at most 1.2 times the reference run’s; the training loss rises by more than 10% from one epoch to the next at most once
                                    researcher  reference  logistic
validation accuracy                      0.939      0.953     0.951
one standard error of a validation accuracy near 0.953 on 750 samples: 0.008
researcher  training loss: lowest 0.182 at epoch 5, last epoch 0.311; best validation epoch 5
reference   training loss: lowest 0.105 at epoch 29, last epoch 0.105; best validation epoch 14
size of the gradient at update 1 and update 540: researcher 0.84 -> 64.77, reference 0.84 -> 0.16
<Figure size 1200x400 with 3 Axes>

What do you see?

  1. Panel A: after its low at epoch 5, the researcher’s training loss jumps up and down and ends higher. The data, the model and the learning rate are the same as in panel B. What could make a network fit the same 2250 samples worse with more training?

  2. Panel C: in the first epochs the loss falls in both runs. What should happen to the size of the gradient as the network approaches a minimum of the loss, and what happens in the researcher’s run?

  3. Read the researcher’s c5_researcher_epoch next to the four lines you wrote in 4.7 section 2.4.

Your diagnosis (one sentence):

 

validation accuracy                                0.939   target >= 0.948 (0.953-0.005) FAIL
training loss at the last epoch                    0.311   target <= 0.125 (1.2 x 0.105) FAIL
epochs where training loss rises > 10%                 8   target <= 1                   FAIL

Case 5: FAIL
<Figure size 1200x400 with 2 Axes>

Our fix below (click to open it).

Notebook Cell
Output
validation accuracy                                0.953   target >= 0.948 (0.953-0.005) PASS
training loss at the last epoch                    0.105   target <= 0.125 (1.2 x 0.105) PASS
epochs where training loss rises > 10%                 0   target <= 1                   PASS

Case 5: PASS
<Figure size 1200x400 with 2 Axes>
3000 new rocks (seed 55): fixed network 0.944, logistic regression 0.942, one standard error 0.004

The five errors in one table

Reflection

Two or three sentences each.

  1. What you learned. Which case took your team longest to diagnose, and which piece of evidence finally gave the cause away?

  2. What you learned from the agents. If an assistant helped you diagnose or fix a case, which of its suggestions was wrong, and how did you find out (which number, which figure)?

  3. How to improve this game. Which case was too easy or too hard, and which error from your own project would you add as a sixth case?