Note
Go to the end to download the full example code or to run this example in your browser via Binder.
A first interactive session: evolving a Julia set#
An interactive evolutionary algorithm shows a gallery of candidates, the evaluator picks the ones they like, and the algorithm breeds the next gallery from the picks. Here the evaluator is a simulated user who secretly prefers one particular Julia set; because its taste is known, we can measure how close each gallery came to it — the ground truth that a real person cannot give us.
Problem, strategy and evaluator#
A JuliaSet has ten genes: the complex constant
in polar form, zoom, centre, four colour genes and the interior shade. The interactive GA shows nine images per
generation and asks for the ones worth keeping (the select protocol).
import matplotlib.pyplot as plt
import easyiec as ei
from easyiec.problems import JuliaSet
from easyiec.strategies import InteractiveGA
problem = JuliaSet()
user = ei.SimulatedUser(problem, target="random", noise=0.05, seed=3)
result = ei.run(problem, InteractiveGA(pop_size=9), user, generations=12, seed=3)
print(result)
print(problem.describe(result.best.genome))
Result(problem=julia, strategy=InteractiveGA, evaluator=simulated-user, queries=12, items=108, human=0, usd=0.0, best_true=0.9190716458712059, stopped=max_generations, seed=3)
Parameters:
- radius = 0.7411 (range 0.62 .. 0.82)
- angle = 2.828 (range 0 .. 6.283)
- zoom = 1.293 (range 0.7 .. 2.5)
- center_x = 0.5901 (range -0.6 .. 0.6)
- center_y = 0.4171 (range -0.6 .. 0.6)
- hue = 0.9559 (range 0 .. 1)
- hue_cycles = 0.5047 (range 0.3 .. 3)
- saturation = 0.9906 (range 0.3 .. 1)
- gamma = 1.362 (range 0.3 .. 1.6)
- interior = 0.5469 (range 0 .. 1)
What the evaluator saw#
The film strip shows four galleries; the chosen images carry a frame. The population drifts towards the hidden target within a few generations.
ei.viz.plot_history(result.log, problem, steps=[0, 3, 7, 11], max_items=9, size=0.9)

<Figure size 810x380 with 36 Axes>
The anytime curve#
The true utility of the best individual is plotted against the number of images shown — the classical measure of evaluator effort in IEC.
ax = ei.viz.plot_anytime(result, label="interactive GA")
ax.set_title("best true utility vs. images shown")
plt.show()

Total running time of the script: (0 minutes 2.756 seconds)
