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

Chapter 2
Foundations

This chapter fixes the notation and the building blocks used in the rest of the book: the two spaces of IEC, the search space and its normalization, the seven feedback protocols and their conversion into pairwise preferences, the information and effort an answer carries, the problem interface and the session that binds a problem, a strategy and an evaluator. Readers who want to run the examples first can skim it and come back to the definitions when needed.

2.1 Two spaces

Takagi [1] described IEC as a search in a parameter space guided by an evaluation in a psychological space. A candidate is a genome 𝐱 in a search space 𝒳; the evaluator does not see 𝐱 but its phenotype — an image, a step response, a temperature profile, a melody — and judges the phenotype by features 𝐟(𝐱) that are partly computable (brightness, overshoot, batch time) and partly not (beauty, “looks natural”). The evaluator’s preference is a latent utility u:𝒳→[0,1] that nobody can write down, and that the evaluator reveals only through answers to queries. Two consequences follow. First, everything the algorithm learns about u comes through answers, so the questions asked matter as much as the algorithm that asks them (section 2.3). Second, the mapping from genome to phenotype shapes the search: a small change of a gene should produce a visible but not overwhelming change of the phenotype, otherwise the evaluator sees either nothing new or chaos.

Table 2.1. Notation.
𝒳, 𝐱

search space and a genome in natural units

𝐳∈[0,1]d

the genome normalized to the unit cube; strategies work with 𝐳

𝐟(𝐱)

phenotype features (image features, key performance indicators)

u(𝐱)∈[0,1]

latent utility of the evaluator; known only for simulated users

𝒬=(k,{𝐱1,…,𝐱n})

a query of kind k about n candidates

𝒜

the evaluator’s answer (choices, ranking, ratings, duels, comments, edits)

𝒞={(a,b,w)}

weighted pairwise preferences a≻b with weight w

σ

perceptual noise of a simulated user; σt at time t

τ

escalation threshold of a hybrid evaluator

2.2 Search spaces

The search space of most problems is a box 𝒳=[𝐥,𝐮]⊂ℝd of typed, named genes (easyiec.Box). A gene is real, integer or categorical, and may be log-scaled. Strategies never see the natural units: they work in the unit cube, and the box maps between the two,

zi= { xi−li ui−li linear gene, ln⁡xi−ln⁡li ln⁡ui−ln⁡lilog-scaled gene, (2.1)

and xi follows from the inverse map, rounded for integer genes and floored for categorical ones. Log scaling matters for gains, time constants and rates, whose meaningful values span orders of magnitude; a categorical gene with m categories is decoded by flooring a real number in [0,m). Working in the unit cube lets every strategy use the same step sizes for every problem, and lets distances between genomes be compared across problems.

space = ei.Box( 
    lower=[0.1, 1.0, 0, 0], 
    upper=[10.0, 100.0, 5, 3], 
    names=["gain", "time_constant", "filter_order", "mode"], 
    kinds=["real", "real", "int", "cat"], 
    log=[True, True, False, False], 
    categories={3: ["P", "PI", "PID"]}, 
    units=["", "s", "", ""], 
) 
x = space.denormalize(np.array([0.5, 0.5, 0.5, 0.9])) 
print(space.describe(x))        # gain and time constant at the geometric mean
   

2.3 Seven ways to answer

The literature asks the evaluator very different questions, and the package supports seven of them (table 2.2). The select protocol of EASY-IEC asks for the candidates worth keeping, with a free or a fixed number of choices; EASY-IEC also distinguishes candidates that become parents from candidates that are copied unchanged (keep) [2]. A ranking orders the gallery; a rating scores each candidate on a scale. Preferential Bayesian optimization asks for pairwise comparisons [14, 15]. Best–worst scaling asks for the best and the worst of a set, an efficient design popular in sensory and marketing science [26]. Sequential line search asks for the best point on a slider through the current best [16]. Finally, a person may edit a candidate directly, for example drag a knot of a temperature profile; the edited candidate enters the population as a new individual, a Lamarckian step that EASY-IEC introduced for profile design [2]. Every answer may carry a comment in natural language, a stated confidence and, for AI judges, a rationale.

Table 2.2. The seven feedback protocols, the pairwise preferences they imply and the upper bound of the information an answer can carry (n candidates).
protocol answer

implied preferences 𝒞

information bound (bits)
select chosen set S

a≻b for a∈S, b∉S

n (free), log⁡2(n k)
rank ordering

every ordered pair

log⁡2n!
rate scores ri on m levels

a≻b with w=(ra−rb)∕(rmax−rmin)

n log⁡ 2 m
pairs winner or tie per duel

winner ≻ loser; a tie both ways, w=12

log⁡23 per duel
best–worst best b, worst w

b≻ others ≻w

log⁡2n(n−1)
slider index of the best sample

chosen ≻ the other samples

log⁡2n
edit a modified genome

edited ≻ original

—

One currency. Every answer is converted into weighted pairwise preferences 𝒞={(a,b,w)} by Feedback.to_pairs (table 2.2) and into a utility in [0,1] for every candidate by Feedback.utilities: 1 and 0 for chosen and unchosen candidates, a normalized Borda score for a ranking, the normalized rating, the Copeland score (wins plus half the ties over comparisons) for duels, 1, 12 and 0 for best, others and worst, and the closeness in slider position for a line answer. Strategies that need an order use the utilities; preference models (chapter 4) use the pairs. As a result every strategy runs with every protocol it can make sense of, and a session can switch protocols between queries.

Information and effort. Protocols differ in what an answer is worth and in what it costs. information_bits bounds the information one answer can carry (table 2.2); Query.n_decisions counts the elementary judgements a careful evaluator makes: one per candidate looked at in a gallery, n−1 plus about n(n−1)∕4 comparisons for a ranking, one per duel, two for best–worst, one for a slider. Figure 2.1 compares the protocols on one gallery of six harmonographs: a ranking carries the most information but costs the most decisions; best–worst scaling costs two decisions and still implies nine pairwise preferences.

queries = { 
    "select": ei.Query("select", items), 
    "select k=2": ei.Query("select", items, n_select=2), 
    "rank": ei.Query("rank", items), 
    "rate 1-10": ei.Query("rate", items, scale=(1, 10)), 
    "pairs": ei.Query("pairs", items, pairs=[(0, 1), (2, 3), (4, 5), (0, 5)]), 
    "best-worst": ei.Query("best_worst", items), 
} 
rows = [] 
for name, q in queries.items(): 
    fb = user.evaluate(q) 
    pairs = fb.to_pairs(q) 
    rows.append((name, information_bits(q), q.n_decisions(), len(pairs))) 
    print(f"{name:11s} {fb.summary():45s} -> {len(pairs):2d} pairs")
   

Figure 2.1

Figure 2.1. What one answer is worth: the information bound, the number of elementary decisions and the number of implied pairwise preferences of six protocols for one gallery of six harmonographs.

Open in ColabExample plot_02_protocols.py in the gallery

2.4 Problems

A problem (easyiec.Problem) connects the search space with the evaluator. It has a search space, a phenotype — render draws on a Matplotlib axis, to_image returns an RGB array for galleries and vision–language models, describe returns a text for language models — and optional descriptors: features returns phenotype features (twelve image features by default: brightness, contrast, colourfulness after Hasler and Süsstrunk [27], saturation, hue, entropy, edge density, two symmetries, coverage and a compression-based complexity), objectives returns key performance indicators of engineering problems, and utility returns a ground-truth utility used by simulated users and benchmarks. With a target genome 𝐱∗ the default utility is a Gaussian similarity of standardized features,

u(𝐱∣𝐱∗)=exp⁡(−1 2w21 p∑j=1p(fj(𝐱)−fj(𝐱∗))2),(2.2)

with width w=0.15; engineering problems define a target-free utility from their objectives instead (chapter 8). Problems may also be editable (handles that a person can drag) and may name semantic axes for verbal steering (section 5.5). The package ships twenty-five problems (fig. 2.2).

Figure 2.2

Figure 2.2. The twenty-five problems of the package, each drawn from its default or a random genome: synthetic landscapes and curve matching, PID and CSTR control, beer fermentation, fuzzy partitions, robot paths, photo enhancement and segmentation, fractals, CPPN images, harmonographs, biomorphs, L-systems, cellular automata, superformula logos, palettes, chart styles, Chernoff faces, network drawings, melodies and slogans.

Open in ColabExample plot_03_problem_zoo.py in the gallery

2.5 Sessions, budgets and logs

A Session binds a problem, a strategy and an evaluator. Strategies follow the ask–tell pattern: ask returns a query, tell receives the answer. The session registers every individual a strategy creates, converts edits into new individuals, passes comments to verbal steering, records the cost of each answer (elementary decisions, human answers, tokens, US dollars, seconds) and stops when a budget is exhausted: a number of generations, queries, shown items, human answers, dollars or seconds, or a target utility. If an oracle is available — a simulated user’s true utility or any function passed as oracle — the session stores the true utility of every individual, which makes anytime curves and every benchmark of the book possible.

The log (SessionLog) is the raw material of all analyses. It keeps every individual ever created, shown or not, with its parents and origin, every query and answer with cumulative counters, and free events such as escalations and steering moves; it can be turned into data frames and saved to and restored from JSON.

session = ei.Session(problem, EasyIEC(pop_size=9), user, seed=11) 
result = session.run(15) 
log = result.log 
print(len(log.individuals), "individuals created,", len(log.shown_ids()), "shown") 
print(log.to_frame()[["step", "n_items_cum", "n_decisions_cum", "best_true"]].tail(4)) 
session.save("supershape_session.json") 
again = ei.core.log.SessionLog.load("supershape_session.json") 
print(len(again.records), "records restored")
   

In a nutshell: Foundations

  • Strategies work in the unit cube; the box maps to natural units with log, integer and categorical genes.
  • Seven protocols — select, rank, rate, pairs, best–worst, slider, edit — reduce to weighted pairwise preferences and to utilities in [0,1].
  • Answers differ in information and effort; both are measured, so protocols can be compared fairly.
  • A session binds problem, strategy and evaluator, enforces budgets, and logs everything, including ground-truth utilities when an oracle exists.