THE VR SCHOOL
  • Schools & Districts
    • License the academy
    • Free program for your students
    • Request a demo
  • Catalog
    • AI & Data
    • Cybersecurity & Web
    • Programming
    • Health Science
    • All Guilds
    • All courses
  • Families
  • Accreditation
  • Log In
  • Request a demo
  • Home
  • Courses

RLP AI Design B — Case Studies, Prototypes, Patents and Capstone

Curriculum

  • 4 Sections
  • 20 Lessons
  • Lifetime
Expand all sectionsCollapse all sections
  • Unit 1: AI in the Clinic: Case Studies from Past to Present
    5
    • 1.1
      Posters, Press Releases and Proof: How Health Technology Is Sold
      50 mins
    • 1.2
      Storyboarding a Talk: Sticky Notes, Props and the Stage
      100 mins
    • 1.3
      Talking to Machines: A Structured Written Debate on Mental Health Chatbots
      100 mins
    • 1.4
      Radiology, Prediction and Telemedicine: Writing the Talk
      150 mins
    • 1.5
      Portfolio Task — Case Talk: Success, Challenge or Failure
      200 mins
  • Unit 2: Building Small Models: Testing AI as Designers
    5
    • 2.1
      Artists and Machines: From AARON to Trained Collaborators
      50 mins
    • 2.2
      Train, Test, Tally: A Controlled Experiment on a Classifier
      100 mins
    • 2.3
      Ninety Percent Accurate? Base Rates and Honest Accuracy Graphics
      50 mins
    • 2.4
      Sequences and Anomalies: Coding a Heart-Rate Flag
      150 mins
    • 2.5
      Portfolio Task — Tested Prototype Exhibit
      200 mins
  • Unit 3: Engineering Design and the Patent Drawing
    5
    • 3.1
      The Art of the Patent Drawing and the Inventor’s Process
      50 mins
    • 3.2
      Drawing to Patent Standard: Views, Numerals and Line
      100 mins
    • 3.3
      Reading a Real Patent: Claims, Drawings and What Can Be Owned
      100 mins
    • 3.4
      From Sketch to Prototype: Engineering a Biomedical Design
      150 mins
    • 3.5
      Portfolio Task — Engineering Design Portfolio and Hypothetical Patent
      200 mins
  • Unit 4: Capstone: A Biomedical AI Innovation from Concept to Exhibition
    5
    • 4.1
      Showing the Future: Exhibitions, Pitches and the Capstone Launch
      50 mins
    • 4.2
      Paper Prototypes and Think-Aloud Testing
      100 mins
    • 4.3
      Money, Rules and Ethics: A Review Panel on the Record
      100 mins
    • 4.4
      Resume, Portfolio and Recorded Mock Interview
      150 mins
    • 4.5
      Portfolio Task — Capstone Exhibition: A Biomedical AI Innovation
      250 mins

Sequences and Anomalies: Coding a Heart-Rate Flag

Unit 2  ·  Studio Production Workshop  ·  Lesson 9 of 20

Sequences and Anomalies: Coding a Heart-Rate Flag

MA:Pr5A.IIIRLP-AIDB
Hands beside two abstract pulse graphs: one shows a false alarm, while the improved graph flags only two spikes.
By the end of this lesson I can…

code, test and improve a rule that flags unusual readings in a heart-rate sequence, and explain how it compares with a learned sequence model.

Instruction

The approved course offers the option of building a model that detects heart-rate anomalies. Training a real recurrent network needs large labeled datasets and computing resources, so here you will build a transparent rule that also uses recent history, test it, find its weakness and fix it. Understanding why a simple rule fails is the best preparation for understanding what a learned model has to get right.

The data. You will use the illustrative sequence from Semester A (invented for teaching, not a real patient): twelve readings one minute apart, 72, 74, 71, 73, 75, 72, 70, 96, 98, 74, 73, 72 beats per minute. You do not measure or record anyone’s heart rate, yours or a family member’s, for this lesson; every series you test is provided in the reading.

Rule version 1. Compare each reading with the average of the three readings before it (its baseline). If it differs by more than 15 bpm, flag it. Work through minutes 8 to 11. Minute 8 (96): the baseline is (75 + 72 + 70) ÷ 3 ≈ 72.3; the difference is about 23.7, so it is flagged. Minute 9 (98): the baseline is (72 + 70 + 96) ÷ 3 ≈ 79.3; the difference is about 18.7, flagged. Minute 10 (74): the baseline is (70 + 96 + 98) ÷ 3 = 88; the difference is 14, not flagged. Minute 11 (73): the baseline is (96 + 98 + 74) ÷ 3 ≈ 89.3; the difference is about 16.3, so it is flagged, even though 73 is a perfectly ordinary reading. The spike contaminated the baseline, and the rule raised a false alarm on the return to normal.

Rule version 2. Build the baseline only from readings that were not flagged. Now minutes 8 and 9 are flagged (baseline about 72.3 for both), and minutes 10, 11 and 12 are not, because their baselines (about 72.3, 72.0 and 72.3) come from normal readings. One design change removed the false alarm.

// Illustrative data: invented for teaching, not a real patient
let bpm = [72, 74, 71, 73, 75, 72, 70, 96, 98, 74, 73, 72];
let limit = 15;

function setup() {
  createCanvas(520, 300);
  textSize(11);
  noLoop();
}

function draw() {
  background(250);
  let normal = [];                    // readings used for the baseline
  for (let i = 0; i < bpm.length; i++) {
    let flagged = false;
    if (normal.length >= 3) {
      let n = normal.length;
      let baseline = (normal[n - 1] + normal[n - 2] + normal[n - 3]) / 3;
      flagged = abs(bpm[i] - baseline) > limit;
    }
    if (!flagged) {
      normal.push(bpm[i]);            // version 2: only unflagged readings
    }
    let x = map(i, 0, bpm.length - 1, 50, width - 40);
    let y = map(bpm[i], 40, 120, 270, 30);
    noStroke();
    if (flagged) {
      fill(200, 70, 40);
    } else {
      fill(40, 90, 160);
    }
    circle(x, y, 12);
    fill(60);
    text(i + 1, x - 4, 292);
  }
}

To see version 1, change the baseline so it uses the three previous readings of bpm directly instead of the normal list.

What the rule cannot do. It does not know context. A rise after climbing stairs is normal; the same rise at rest might not be. It uses one fixed threshold for everyone. A learned sequence model such as an RNN could, with enough labeled data, learn patterns across context and people, but it would be harder to explain and could learn shortcuts from its data. That trade-off between a transparent rule and a more capable but opaque model is central to AI design in medicine.

Design it. Add a legend, axis labels and on-screen text stating that the data is illustrative and the flag is not a diagnosis. Consider interaction: a slider or keys to change limit so viewers can see how the threshold changes the flags.

Option: a rule-based clinic-guide chatbot. If you prefer, build a p5.js chatbot that answers questions about your Semester A brochure topic (what happens in an MRI, how a blood pressure cuff works) from a fixed list of sourced answers, never gives advice or a diagnosis, and always offers “talk to a clinician” and the 988 Lifeline where relevant. Test it with 20 questions and tally correct, unanswered and wrong responses.

📖 Read for this lesson

The reading opens over the lesson; close it to come back to exactly where you were. The checks below draw on it.

  • Heart-Rate Series, Worksheet and Answer Key for the Anomaly FlagSeries A, B and C are constructed teaching data written for this course and are illustrative, not patient data; reference range from MedlinePlus, National Library of Medicine, Pulse (retrieved 2026-09-26) · about 4 min

    Three recorded heart-rate series to code against, a worked worksheet, and the flags every rule and threshold should produce so you can check your code.

Vocabulary in context

  • baseline — The expected or typical value a new reading is compared against, often an average of recent readings.
  • anomaly detection — Finding readings that differ markedly from what is expected.
  • threshold — The cut-off value above which a rule or model gives a positive result.
  • transparent model — A model whose reasoning people can read and check, such as a written rule.

Formative check

Work through these before moving on. They are not graded — they tell you whether the standard below has landed yet.

+50 XP

Under rule version 1, why is minute 11 (73 bpm) flagged?

The earlier spike raised the baseline, producing a false alarm.
+50 XP

With a threshold of 25 bpm instead of 15, which minutes does rule version 2 flag?

Minute 8 differs from its baseline of about 72.3 by about 23.7, so it is not flagged and joins the baseline. Minute 9’s baseline becomes (72 + 70 + 96) / 3, about 79.3, so 98 differs by about 18.7: not flagged either. A missed first anomaly lets the spike into the baseline.
Myth or Fact?

A learned sequence model is always a better choice for a medical flag than a transparent rule.

Learned models can be more capable but are harder to explain and can learn shortcuts; the choice is a trade-off.

Simulation & tools

Code and test the anomaly flag

Open the p5.js web editor (no sign-in needed) and paste the lesson sketch. Run it and record which minutes are flagged. Then (1) switch to version 1 by basing the baseline on the three previous bpm readings and record the flags again; (2) try thresholds of 10, 15 and 25 and record the flags for each in a table; (3) add a line of on-screen text saying the data is illustrative and the flag is not a diagnosis. Answer: which threshold would you choose, and what does each choice trade off between missed anomalies and false alarms? Without a computer, apply both rules by hand to the twelve readings, recording each baseline and difference in the worksheet printed in this lesson’s reading.

Open p5.js Web Editor ↗  ·  p5.js Web Editor, Processing Foundation · LGPL-2.1 open source

Quick self-check

How confident are you that you can code, test and improve an anomaly-flag rule and compare it with a learned sequence model?

Not yetVery confident

Practice

Work these on paper or in your notebook, then open Check your answer. Aim for all of Fluency and Application; try at least one Challenge.

Printable version: this unit’s practice workbook (PDF)

Fluency

Build speed and accuracy with the core skill.

  1. Define baseline, anomaly detection and transparent model.
    Check your answer
    Answer: Baseline: the expected value a new reading is compared against, often an average of recent readings. Anomaly detection: finding readings that differ markedly from what is expected. Transparent model: a model whose reasoning people can read and check, such as a written rule.
    The rule in this lesson is a transparent model that uses recent history.
  2. State rule version 1 and rule version 2 in one sentence each.
    Check your answer
    Answer: Version 1: compare each reading with the average of the three readings before it, and flag it if it differs by more than 15 bpm. Version 2: the same, but build the baseline only from readings that were not flagged.
    Version 2 keeps a spike from contaminating the baseline.
  3. Compute the version-1 baseline (average of the three previous readings) for minute 5 (previous readings 72, 74, 71) and minute 7 (previous readings 73, 75, 72). Is either reading flagged at 15 bpm?
    Check your answer
    Answer: Minute 5: baseline 72.3, reading 75, difference 2.7 (calculated from the unrounded baseline: 2.67). Minute 7: baseline 73.3, reading 70, difference 3.3. Neither is flagged.
    (72 + 74 + 71) / 3 = 217 / 3 = 72.33; 75 – 72.33 = 2.67. (73 + 75 + 72) / 3 = 220 / 3 = 73.33; 73.33 – 70 = 3.33.

Application

Use the skill in context. Show your reasoning.

  1. Using the illustrative series (72, 74, 71, 73, 75, 72, 70, 96, 98, 74, 73, 72), apply version 1 with a threshold of 10 bpm to minutes 8 to 12. Which minutes are flagged?
    Check your answer
    Answer: Minutes 8, 9, 10 and 11 are flagged; minute 12 is not.
    Baselines and differences: minute 8, 72.3, 23.7; minute 9, 79.3, 18.7; minute 10, 88.0, 14.0; minute 11, 89.3, 16.3; minute 12, (98 + 74 + 73) / 3 = 81.7, 9.7. All above 10 except minute 12.
  2. Apply version 1 with a threshold of 20 bpm. Which minutes are flagged, and what does this show about raising the threshold?
    Check your answer
    Answer: Only minute 8 (difference 23.7). Minute 9 (difference 18.7) is missed. Raising the threshold removes false alarms but can miss real anomalies.
    Minute 9: baseline (72 + 70 + 96) / 3 = 79.3; 98 – 79.3 = 18.7, under 20. Minutes 10 and 11 differ by 14.0 and 16.3, also under 20.
  3. Apply version 2 with a threshold of 20 bpm. Which minutes are flagged? Compare with version 1 at 20 bpm.
    Check your answer
    Answer: Minutes 8 and 9. Version 2 catches minute 9, because the flagged 96 is kept out of its baseline, which stays at about 72.3, so 98 differs by about 25.7.
    Minute 8 is flagged and left out of the baseline, so minute 9’s baseline is (75 + 72 + 70) / 3 = 72.3; 98 – 72.3 = 25.7 > 20. Version 1 used 96 in the baseline and missed it.
  4. Name two things the rule cannot do, and the trade-off the lesson describes between this rule and a learned sequence model.
    Check your answer
    Answer: It does not know context (a rise after climbing stairs is normal; the same rise at rest might not be), and it uses one fixed threshold for everyone. A learned model such as an RNN could, with enough labeled data, learn patterns across context and people, but it would be harder to explain and could learn shortcuts. The trade-off is transparency versus capability.
    That trade-off is central to AI design in medicine.
  5. Write the on-screen text and legend for the heart-rate flag sketch, following the lesson’s design advice.
    Check your answer
    Answer: Model: Legend: blue circle = reading used for baseline; orange-red circle = flagged (differs from recent baseline by more than 15 bpm). Text: ‘Illustrative data, invented for teaching. A flag is not a diagnosis.’ Axis labels: ‘minute’ and ‘beats per minute’.
    The lesson asks for a legend, axis labels and on-screen text stating the data is illustrative and the flag is not a diagnosis.

Challenge

Stretch problems. Expect to think before you write.

  1. The optional clinic-guide chatbot is tested with 20 questions: 14 answered correctly, 4 unanswered (it says ‘I don’t have a sourced answer; please talk to a clinician’), 2 answered wrongly. Give each as a percentage, and argue which number matters most for safety.
    Check your answer
    Answer: Correct 70%, unanswered 20%, wrong 10%. The wrong answers matter most: an unanswered question sends the user to a clinician, but a wrong answer can mislead. The redesign should target the 2 wrong responses first.
    14 / 20 = 70%; 4 / 20 = 20%; 2 / 20 = 10%. The chatbot must never give advice or a diagnosis and should offer ‘talk to a clinician’ and 988 where relevant.

Review

Keep earlier skills sharp.

  1. Review (Semester A, Unit 4): Under the Semester A mapping map(bpm, 40, 120, 270, 30), where is the 74 bpm reading drawn?
    Check your answer
    Answer: y = 168.
    (74 – 40) / 80 = 0.425; 0.425 x 240 = 102; 270 – 102 = 168. The lesson sketch uses the same vertical mapping.

Missouri Learning Standards — Media Arts addressed: MA:Pr5A.III, MA:Cr2A.II, MA:Cr3A.II, RST.11-12.3, WHST.11-12.2

Instructional focus: Creative coding, testing and revision of an interactive prototype

Reading

Heart-Rate Series, Worksheet and Answer Key for the Anomaly Flag

Series A, B and C are constructed teaching data written for this course and are illustrative, not patient data; reference range from MedlinePlus, National Library of Medicine, Pulse (retrieved 2026-09-26) · SLS original (constructed teaching data), with a public-domain reference range from the U.S. National Library of Medicine

Why this reading. The workshop asks you to code a flag, record which minutes it flags, try three thresholds and choose one. That needs a recorded series and the answer to check your code against. This reading prints three series, a worksheet for the lesson’s series with every baseline and difference worked out, the flags every rule and threshold should produce, and a normal-range reference. All series are invented for teaching: none is a real patient, and a flag here is never a diagnosis.

Reference: what is a normal resting pulse?

MedlinePlus (U.S. National Library of Medicine) lists a normal resting heart rate of 60 to 100 beats per minute for children 10 and older and adults, and 40 to 60 for well-trained athletes. It says continually high or low resting rates are worth discussing with a provider. Note that the rules below do not use this range: they flag a change from a recent baseline, so a reading of 96 can be normal in isolation and still be flagged.

The three series (SLS original, illustrative)

Minute123456789101112
Series A (the lesson)727471737572709698747372
Series B (jittery)708464806683627968776692
Series C (slow drift)7071737578818488929699102

The rules: version 1 compares each reading with the mean of the three readings before it (from minute 4 on) and flags it when the absolute difference is more than the limit; version 2 builds the baseline only from readings that were not flagged. The first three readings are never flagged because they have no baseline. A difference exactly equal to the limit is not flagged.

Worksheet: Series A, limit 15

MinbpmV1 baselineV1 |diff|V1V2 baselineV2 |diff|V2
172——n/a——n/a
274——n/a——n/a
371——n/a——n/a
47372.330.67no72.330.67no
57572.672.33no72.672.33no
67273.001.00no73.001.00no
77073.333.33no73.333.33no
89672.3323.67FLAG72.3323.67FLAG
99879.3318.67FLAG72.3325.67FLAG
107488.0014.00no72.331.67no
117389.3316.33FLAG72.001.00no
127281.679.67no72.330.33no

Minute 11 is the false alarm of version 1: baseline (96 + 98 + 74) / 3 = 89.33, and |73 − 89.33| = 16.33 > 15, although 73 is an ordinary reading. In version 2 the baseline for minutes 10 to 12 comes only from unflagged readings, so the spike does not contaminate it.

Answer key: which minutes each rule flags

SeriesLimit (bpm)Version 1 flags minutesVersion 2 flags minutes
A108, 9, 10, 118, 9
A158, 9, 118, 9
A25nonenone
B106, 7, 126, 12
B151212
B25nonenone
C10nonenone
C15nonenone
C25nonenone

Ground truth for scoring (constructed): in Series A the anomaly is minutes 8 and 9 (the spike); in Series B it is minute 12 only; in Series C there is a sustained climb from 70 to 102 that a clinician would want noticed, but no single reading jumps.

Scoring version 2 on Series A and B together (24 readings, 3 true anomalies):

LimitTPFPFNTNAccuracySensitivity
103102095.8%100%
1530021100.0%100%
250032187.5%0%

What the trade-off looks like: at a limit of 10 the rule catches every anomaly but raises a false alarm at minute 6 of Series B (83 against a baseline of 70.0, difference 13.0); at 15 it catches all three with no false alarm; at 25 it misses all three, yet its accuracy is still 87.5% (21 of 24) because most readings are normal. Series C shows the rule’s blind spot: no limit flags the slow climb, because each reading is close to the average of the three before it. That is what a learned sequence model, or a rule about trend, would have to add, and the price of a learned model is that you can no longer read its reasoning.

If you cannot run code

Fill the worksheet by hand for Series A, then find the version 2 flags for Series B at limits 10, 15 and 25 and check them against the answer key. The three numbers to look for are the baseline at minute 6 of Series B (70.00), its difference (13.00) and the baseline at minute 12 (70.33).

Sources: MedlinePlus, Pulse (U.S. National Library of Medicine) (medlineplus.gov)

Up NextComplete & Continue →

Leave a Reply Cancel reply

Ninety Percent Accurate? Base Rates and Honest Accuracy Graphics
Prev
Portfolio Task — Tested Prototype Exhibit
Next

© 2026 The VR School | Career content by Wiley | Powered by Sejal Learning Systems.

Join free · Accreditation · Privacy Policy · Terms of Service

Modal title

Main Content