Heuristic:ANative Lab EvoAgentX Convergence Detection
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Workflow_Optimization, Statistics |
| Last Updated | 2026-10-21 00:00 GMT |
Overview
Stops AFlow evolutionary optimization when top-k average scores stabilize across consecutive rounds, using a z-score-based confidence interval test.
Description
The ConvergenceUtils class detects when an AFlow optimization run has plateaued. For each round, it computes the average and standard deviation of benchmark scores. It then tracks the mean of the top-k highest-scoring rounds (Y value) and checks whether the change in Y between consecutive rounds falls within a confidence interval defined by `z * sigma_delta_y`. Convergence is declared when the Y change stays within the interval for `consecutive_rounds` consecutive rounds.
Usage
Use this heuristic when running AFlowOptimizer to avoid wasting compute on diminishing returns. The convergence check is called after each optimization round. If converged, the optimizer can stop early instead of running all `max_rounds`.
The Insight (Rule of Thumb)
- Action: Call `check_convergence(top_k=3, z=0, consecutive_rounds=5)` after each optimization round.
- Value: `top_k=3` (top 3 rounds), `z=0` (zero z-score = exact match threshold), `consecutive_rounds=5` (5 consecutive stable rounds).
- Trade-off: Stricter convergence (higher `z`, more `consecutive_rounds`) means fewer false stops but may waste compute. Looser settings risk stopping too early.
- Compatibility: Requires at least `top_k + 1` rounds before convergence can be evaluated.
Reasoning
Evolutionary optimization typically shows diminishing returns as the search space is explored. The top-k approach is more robust than tracking the single best score, because it captures the overall quality of the elite population rather than a single lucky sample. The standard error of the Y difference (`sigma_delta_y`) accounts for run-to-run variance in benchmark scores, so convergence is only declared when the improvement is statistically indistinguishable from noise.
With `z=0`, the test is `abs(delta_y) <= 0 * sigma_delta_y`, which means `delta_y` must be exactly zero (or extremely close). This is a very conservative test — it essentially requires the top-k mean to be identical across rounds. Increasing `z` widens the acceptance band.
Code Evidence
Convergence check from `evoagentx/utils/aflow_utils/convergence_utils.py:65-110`:
def check_convergence(self, top_k=3, z=0, consecutive_rounds=5):
self.avg_scores, self.stds = self.calculate_avg_and_std()
if len(self.avg_scores) < top_k + 1:
return False, None, None
convergence_count = 0
previous_y = None
sigma_y_previous = None
for i in range(len(self.avg_scores)):
top_k_indices = np.argsort(self.avg_scores[: i + 1])[::-1][:top_k]
top_k_scores = [self.avg_scores[j] for j in top_k_indices]
top_k_stds = [self.stds[j] for j in top_k_indices]
y_current = np.mean(top_k_scores)
sigma_y_current = np.sqrt(np.sum([s**2 for s in top_k_stds]) / (top_k**2))
if previous_y is not None:
delta_y = y_current - previous_y
sigma_delta_y = np.sqrt(sigma_y_current**2 + sigma_y_previous**2)
if abs(delta_y) <= z * sigma_delta_y:
convergence_count += 1
if convergence_count >= consecutive_rounds:
return True, i - consecutive_rounds + 1, i
else:
convergence_count = 0
previous_y = y_current
sigma_y_previous = sigma_y_current
return False, None, None