Regression
regression ¶
Regression detection stopper for evolution termination on score decline.
This module provides a RegressionStopper that terminates evolution when the current best score declines compared to the score from a configurable lookback window ago, preventing wasted compute once performance regresses relative to a previous baseline.
| ATTRIBUTE | DESCRIPTION |
|---|---|
RegressionStopper | Stop evolution when score declines relative to the score from N iterations ago, using a bounded TYPE: |
Examples:
Basic usage with default window:
from gepa_adk import RegressionStopper
stopper = RegressionStopper() # window=3
# Use stopper in evolution config
Custom lookback window:
from gepa_adk import RegressionStopper
stopper = RegressionStopper(window=5) # Stop if score drops vs 5 iters ago
Composing with other stoppers:
from gepa_adk import RegressionStopper
from gepa_adk.adapters.stoppers import CompositeStopper, ScoreThresholdStopper
composite = CompositeStopper(
[RegressionStopper(window=3), ScoreThresholdStopper(0.99)],
mode="any",
)
See Also
gepa_adk.ports.stopper.StopperProtocol: Protocol interface for stop conditions.gepa_adk.domain.stopper.StopperState: Immutable snapshot of evolution state for stopper decisions.
RegressionStopper ¶
Stops evolution when best score declines over a lookback window.
Detects regression by comparing the current best score to the best score from window iterations ago. Returns True (stop) when the current score is strictly lower than the score window steps prior.
Requires at least window + 1 calls before any regression can be detected. Call setup() (or let the engine call it) to reset history between runs.
| ATTRIBUTE | DESCRIPTION |
|---|---|
window | Number of iterations to look back for comparison. TYPE: |
| PARAMETER | DESCRIPTION |
|---|---|
window | Number of iterations to look back for comparison. Must be >= 1. Default is 3. TYPE: |
Examples:
Detecting degrading runs:
from gepa_adk import RegressionStopper
from gepa_adk.domain.stopper import StopperState
stopper = RegressionStopper(window=3)
# Simulated evolution calls (StopperState requires all 6 fields)
stopper(
StopperState(
iteration=0,
best_score=0.5,
stagnation_counter=0,
total_evaluations=0,
candidates_count=1,
elapsed_seconds=0.0,
)
) # False (cold start)
stopper(
StopperState(
iteration=1,
best_score=0.6,
stagnation_counter=0,
total_evaluations=1,
candidates_count=1,
elapsed_seconds=1.0,
)
) # False
stopper(
StopperState(
iteration=2,
best_score=0.7,
stagnation_counter=0,
total_evaluations=2,
candidates_count=1,
elapsed_seconds=2.0,
)
) # False
stopper(
StopperState(
iteration=3,
best_score=0.4,
stagnation_counter=0,
total_evaluations=3,
candidates_count=1,
elapsed_seconds=3.0,
)
) # True (0.4 < 0.5, the baseline from window=3 ago)
Notes
Equal scores (plateau) are NOT considered regression. Only strictly lower scores trigger a stop.
Source code in src/gepa_adk/adapters/stoppers/regression.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
__init__ ¶
Initialize RegressionStopper with lookback window.
| PARAMETER | DESCRIPTION |
|---|---|
window | Number of iterations to look back for score comparison. Must be >= 1. Default is 3. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
ConfigurationError | If window < 1. |
Examples:
Notes
Score history is stored in a deque(maxlen=window+1) so memory usage is bounded to exactly window + 1 floats regardless of run length.
Source code in src/gepa_adk/adapters/stoppers/regression.py
setup ¶
Reset score history. Called by engine at start of each run.
Clears the internal score history by replacing the bounded deque with a fresh one, so the stopper can be safely reused across multiple evolve() calls with the same instance. Without this reset, history from one run would bleed into the next.
Examples:
Source code in src/gepa_adk/adapters/stoppers/regression.py
__call__ ¶
__call__(state: StopperState) -> bool
Check if evolution should stop due to score regression.
Appends the current best score to history, then compares the latest score against the score from window iterations ago. Returns False during the cold-start phase (fewer than window + 1 calls).
| PARAMETER | DESCRIPTION |
|---|---|
state | Current evolution state snapshot containing best_score. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bool | True if current best score is strictly lower than the score |
bool |
|
Examples:
stopper = RegressionStopper(window=3)
# Prime with 3 cold-start calls
for score in [0.5, 0.6, 0.7]:
stopper(
StopperState(
iteration=0,
best_score=score,
stagnation_counter=0,
total_evaluations=0,
candidates_count=1,
elapsed_seconds=0.0,
)
)
state = StopperState(
iteration=3,
best_score=0.4,
stagnation_counter=0,
total_evaluations=3,
candidates_count=1,
elapsed_seconds=3.0,
)
stopper(state) # True (0.4 < 0.5, the baseline from window=3 ago)