PIXELBANKv9.1.0
Menu

Detect catastrophic forgetting by comparing model performance before and after fine-tuning.

Given performance scores on N tasks before and after fine-tuning, compute:

  1. Forgetting score per task: max(0, score_before - score_after)
  2. Average forgetting: mean of all forgetting scores
  3. Backward transfer: mean of (score_after - score_before) for all tasks

A model suffers catastrophic forgetting if average forgetting > threshold.

Input:

  • Line 1: N threshold
  • Line 2: N floats (scores before fine-tuning)
  • Line 3: N floats (scores after fine-tuning)

Output:

  • Line 1: Average forgetting, rounded to 4 decimal places
  • Line 2: Backward transfer, rounded to 4 decimal places
  • Line 3: "FORGETTING" if avg forgetting > threshold, else "OK"

Example:

Input:
4 0.1
0.9 0.8 0.7 0.6
0.5 0.85 0.75 0.4
Output:
0.1500
-0.0500
FORGETTING
Reasoning:
  • The input is processed to calculate the forgetting score per task: 0.9−0.5=0.40.9-0.5=0.4, 0.8−0.85=−0.050.8-0.85=-0.05 (so 00), 0.7−0.75=−0.050.7-0.75=-0.05 (so 00), 0.6−0.4=0.20.6-0.4=0.2
  • Then, we calculate the average forgetting: 0.4+0+0+0.24=0.64=0.15\frac{0.4+0+0+0.2}{4} = \frac{0.6}{4} = 0.15
  • The backward transfer is calculated as: (0.5−0.9)+(0.85−0.8)+(0.75−0.7)+(0.4−0.6)4=−0.4+0.05+0.05−0.24=−0.54=−0.125\frac{(0.5-0.9)+(0.85-0.8)+(0.75-0.7)+(0.4-0.6)}{4} = \frac{-0.4+0.05+0.05-0.2}{4} = \frac{-0.5}{4} = -0.125, which rounds to −0.0500-0.0500 when rounded to 4 decimal places in the context of the output format, but the actual calculation before rounding is −0.125-0.125
  • Since the average forgetting (0.150.15) is greater than the given threshold (0.10.1), the output is "FORGETTING"

Constraints:

  • 1 <= N <= 20
  • Scores are in [0, 1]
  • Threshold is in [0, 1]
  • Round to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Catastrophic Forgetting Detector - Medium | PixelBank