Interactive Evolutionary Computation in PythonHuman, simulated and AI evaluators. The easyiec toolbox

Chapter 5
Evaluators

The evaluator is the fitness function of IEC, and this chapter treats it as a component in its own right. It describes the simulated users that make benchmarks with a known ground truth possible, the AI judges that put language and vision–language models in the loop, panels of several evaluators, verbal steering that turns comments into search directions, the hybrid evaluator that escalates uncertain queries to a person under a risk-control rule, and the interfaces for people. Whether an evaluator can be trusted is the subject of chapter 6.

5.1 One interface

An evaluator has one method, evaluate(query), which returns an answer. Everything else is optional: an evaluator may expose a true_utility (simulated users), mark itself as human so that its answers count as human effort, attach to a session to see its log, or raise NeedsHuman to hand the query to a person waiting at a notebook gallery. Because people, simulated users, metrics, AI judges, panels and hybrids share this interface, an experiment can be prototyped with a simulated user, validated against an AI judge and run with people without changing anything else. Small adapters complete the set: MetricEvaluator answers from a computable score (a computational-aesthetics measure or a KPI), CallbackEvaluator wraps any function, RecordingEvaluator and ReplayEvaluator store and replay answers.

5.2 Simulated users

A simulated user (SimulatedUser) holds a hidden target and answers every protocol by perceiving noisy utilities. The target is a genome (the user wants a phenotype similar to it, eq. (2.2)), target values of named features, any utility function, or the problem’s own utility. At time t the user perceives the candidate in display position p of a gallery of n as

ũp=u(𝐱p)+σt𝜀p+β(1−p n−1),σt=σ(1+ϕ t Tϕ),(5.1)

where 𝜀p is standard normal (Thurstone) or a standardized Gumbel variable (Bradley–Terry–Luce), β is a position bias favouring the first candidates, and ϕ a fatigue that increases the noise with the number of queries answered. With probability λ the user lapses and answers at random; with limited attention only the first k positions are perceived with the nominal noise, the others with three times as much. The perceived utilities are then turned into an answer: the top third for a free selection, the order for a ranking, a possibly compressed rating, the larger perceived utility for a duel, with a tie below a threshold. The model can also drift (its target performs a random walk), satisfice (stop when good enough), edit the chosen candidate towards its target (Lamarckian edits), and comment on what should change, using the problem’s semantic axes (section 5.5).

The ground truth is what makes simulated users indispensable. With a known u, every shown candidate has a true utility, every session an anytime curve, and every algorithm, protocol or evaluator a measurable effect (chapter 10). The price is realism: a simulated user is a hypothesis about people, and conclusions that depend on its details should be checked with people or, as in chapter 11, with an AI judge whose behaviour is itself measured. Figure 5.1 shows how the noise level shapes the choice probabilities.

Figure 5.1

Figure 5.1. Probability that a simulated user prefers A to B against the true utility difference, estimated from 400 random pairs for four noise levels σ (Thurstonian model).

Open in ColabExample plot_01_simulated_users.py in the gallery

5.3 AI judges

LLMJudge turns a query into a request for a language or vision–language model and the model’s reply into an answer.

The request. A system prompt casts the model as a careful evaluator whose choices decide which candidates reproduce and asks it to ignore display order and label names. The user turn contains the candidates — a labelled grid image, one image per candidate, image pairs side by side for duels, or text descriptions from Problem.describe — followed by the goal, optional criteria and persona, and the task of the protocol, which asks for a short rationale before the verdict and for a strict JSON answer [4]. Where the provider supports it, a JSON schema enforces the format; otherwise the reply is parsed leniently and the request repeated if it fails.

Debiasing by several views. Language-model judges prefer certain positions [4, 5]. The judge can ask each query in several views: the original order and its reversal (debias="reverse"), or random permutations, and aggregate the answers — majority votes for selections, Borda counts for rankings, mean ratings, mean duel outcomes with a tie when the views disagree. The disagreement between the views is reported as the answer’s uncertainty: one minus the mean Jaccard overlap of selections, (1−τ)∕2 for rankings, the share of duels decided differently. Figure 5.2 shows what reversal buys: it cannot make a judge see better, but it removes the systematic preference for the first option and turns order-dependent verdicts into ties with high uncertainty — exactly the cases a hybrid evaluator should pass to a person.

client = MockJudgeClient(scorer=taste, score_on="genome", noise=0.05, position_bias=0.05, seed=1) 
judge = LLMJudge(client, problem, goal="an intricate, glowing spiral in cool colours", debias="reverse", n_views=2, 
                 image_size=128) 
items = make_individuals(problem.random(np.random.default_rng(0), 6)) 
fb = judge.evaluate(ei.Query("select", items, n_select=2)) 
print(fb.summary()) 
print("rationale:", fb.rationale[:120]) 
print("uncertainty:", fb.uncertainty, " cost:", fb.cost)
   

Figure 5.2

Figure 5.2. A mock judge whose first-shown option receives a bonus of 0.1 on the utility scale, asked about 80 pairs once or in both orders: the share of decided duels won by the first option, the accuracy among decided duels, and the share of duels flagged as ties. Dashed: the true share of pairs in which the first option is better.

Open in ColabExample plot_02_llm_judge.py in the gallery

Critique and steering. With critique=True the judge also suggests how the best candidate could be improved (“brighter, fewer branches”); with auto_steer=True the suggestion is passed to verbal steering, so the AI not only selects but also points the search in a direction.

Clients, costs and caching. Clients for Claude (Anthropic Messages API), OpenAI-compatible servers, Gemini and local Ollama models send images as base64 PNG and report tokens, latency and an estimated cost. A CachedClient stores every reply on disk under a fingerprint of the request, so that a notebook can be rerun at no cost and with identical results. The offline MockJudgeClient reads the candidates from the request, scores them with a known function, adds controllable noise, position bias and malformed replies, and answers in the requested format; all examples of the book use it, which makes the judge’s behaviour reproducible and its errors measurable.

5.4 Panels

A Panel asks several evaluators and merges their answers with the rules of section 4.5; its uncertainty is the members’ disagreement, one minus Kendall’s coefficient of concordance W [52] for rankings and one minus the mean Jaccard overlap for selections. A PersonaPanel builds the members from one language model with different personas (a colour-blind reader, a print designer, a novice), a cheap way to probe whether a design works for different audiences. Panels of simulated users with related tastes (make_crowd) emulate a group: as the spread of the members’ targets grows, W falls (fig. 5.3), and a GA steered by the panel produces designs the whole group likes slightly better than a GA steered by one member alone.

Figure 5.3

Figure 5.3. Best mean utility over a seven-member group of simulated users for an interactive GA steered by the panel (Borda) and by one member alone; colour palettes, six crowds.

Open in ColabExample plot_03_panels.py in the gallery

5.5 Verbal steering

People comment while they choose: “much brighter, but slightly less contrast”. VerbalSteering turns such comments into a direction in the unit cube that the session passes to the strategy. Each problem names semantic axes — "brighter", "more contrast", "warmer", "lift the shadows" — as directions in its search space. Comments are split into clauses, the axes are found in each clause (for an axis “more X” also the bare “X”), and the hedges in front of them scale the step in the spirit of Zadeh’s interpretation of linguistic hedges as operators on fuzzy sets [53]: very and much concentrate (factor 2), slightly and a bit dilate (0.4 and 0.5), less and not negate; hedges multiply, so “slightly less contrast” gives −0.4. Hungarian hedges are included. When no axis matches, or always if preferred, a language model reads the comment together with the parameter names, units, ranges and current values and returns a signed change per parameter. With small galleries of four photographs, where each selection carries little information, the comments of a simulated user sped up photo enhancement noticeably (fig. 5.4).

for c in ["much brighter, but slightly less contrast", "a bit warmer and not so saturated", "lift the shadows a lot"]: 
    print(f"{c!r:45s} -> {parse_hedged_phrases(c, problem.semantic_axes)}") 
vs = VerbalSteering(problem, step=0.12) 
d = vs.direction("much brighter, but slightly less contrast") 
print({k: round(float(v), 3) for k, v in zip(problem.space.names, d) if v != 0})
   

Figure 5.4

Figure 5.4. Best ground-truth utility of photo enhancement with galleries of four, when the simulated user’s comments are turned into steering directions and when they are ignored; eight seeds.

Open in ColabExample plot_05_verbal_steering.py in the gallery

5.6 Hybrid evaluation with risk control

An AI judge is cheap and tireless but sometimes wrong; a person is reliable but tires. The EscalationEvaluator lets the AI answer every query and passes it to the person when the AI’s uncertainty u exceeds a threshold τ. Three policies set τ.

The risk policy needs labels: pairs of an AI answer and a person’s answer to the same query, with the AI’s uncertainty uj and their protocol-aware disagreement dj∈[0,1] (the share of duels decided differently, one minus the Jaccard overlap of selections, and so on). Escalated queries provide such labels automatically; to avoid a biased picture of the confident queries, a random fraction a of them is audited as well, and each label carries the inverse-probability weight wj=1∕a for audits and wj=1 for escalations. For a candidate threshold t the weighted disagreement of the labels with uj≤t and its Hoeffding bound [55] are

R^(t)=∑uj≤twjkjdj ∑uj≤twjkj,UCB(t)=R^(t)+ ln⁡ (1∕δ) 2neff(t), neff(t)=(∑uj≤twjkj)2 ∑uj≤twj2kj, (5.2)

with Kish’s effective sample size [56], and τ=max{t:UCB(t)≤𝜀}; when no threshold satisfies the bound, every query goes to the person, including those on which the AI’s views agree completely. Here kj=1 counts queries (the conservative choice) or kj is the number of elementary decisions of the query — the eight duels of a pairwise query — when these are close to independent (granularity="decision").

Two lessons from building this rule are worth stating. First, a bound on a few dozen labels is loose: certifying a 25 % disagreement with δ=0.1 and Hoeffding’s inequality needs on the order of a hundred labels at the query level, so a risk-controlled session that starts from nothing escalates almost everything for a long time. The package therefore accepts calibration labels from an earlier session or a judge-substitution study, as split conformal methods start from a calibration set [8]. Second, the tolerance must be set relative to the natural disagreement between careful evaluators: when two candidates are nearly equal, any two evaluators — two people included — decide their duel differently half of the time, and no AI can do better. The guarantee assumes exchangeable queries, while interactive search is non-stationary; the bound is an operational safeguard, monitored online, not a theorem.

Algorithm\special {t4ht^+}

Figure 5.5 compares the three policies for three mock AI judges of different quality on segmentation tuning with duels. A fixed threshold escalates according to the AI’s uncertainty, whatever its real reliability; the rate rule holds its share regardless of quality and lets the weakest AI’s errors through. The calibrated risk rule asks the person rarely when the AI is good (13 % of the queries) and almost always when it is not (93 %), and keeps the disagreement of the AI-only answers well below the tolerance of 0.3 in all three cases.

        hybrid = EscalationEvaluator(ai, person, policy=policy, threshold=0.3, target_rate=0.25, 
                                     epsilon=0.3, delta=0.1, audit=0.1, calibration=calib.labels, 
                                     granularity="decision", seed=3) 
        res = ei.run(problem, InteractiveDE(pop_size=8), hybrid, generations=30, seed=4, oracle=person.true_utility) 
        
   

Figure 5.5

Figure 5.5. Hybrid evaluation of segmentation tuning with eight duels per query. Left: share of queries answered by the person; right: disagreement of the AI-only answers with an independent careful answer (dashed: the tolerance 𝜀=0.3 of the risk policy). AI noise 0.05, 0.1 and 0.2 on the utility scale.

Open in ColabExample plot_04_escalation.py in the gallery

5.7 People

JupyterGallery runs in Jupyter, JupyterLab, VS Code and Colab: images in a grid with buttons, one click for a parent, two for a kept candidate, a ranking or rating mode, a gene editor for direct manipulation, a comment box for verbal steering, and an Ask AI button that pre-selects the answer of an assistant judge. With a hybrid evaluator the gallery advances by itself while the AI is confident and stops with the AI’s suggestion pre-selected when it is not; technically, the person is represented by a HumanProxy that raises NeedsHuman, and the gallery completes the query when the person clicks Next. MatplotlibGallery is the desktop counterpart in the style of the MATLAB toolbox, with draggable knots for editable problems, and ConsoleEvaluator works in a terminal.

In a nutshell: Evaluators

  • Every evaluator answers queries through one interface; experiments move unchanged from simulated users to AI judges to people.
  • Simulated users perceive noisy utilities with fatigue, lapses, position bias, limited attention and drift, and provide the ground truth of benchmarks.
  • AI judges ask several views, aggregate them and report the views’ disagreement as uncertainty; clients cache, count tokens and estimate costs.
  • Panels merge members and report their disagreement; verbal steering turns hedged comments into search directions.
  • The hybrid evaluator escalates uncertain queries; the calibrated risk policy adapts the human share to the AI’s measured reliability.