Cultural Algorithm (CA)¶
An evolutionary method for continuous problems.
CA ¶
CA(*, accept_rate=0.2, influence_type=4, alpha=0.9, beta=0.2, survival='best', **kwargs)
Cultural Algorithm (Reynolds, 1994).
A population space and a belief space (the culture) evolve together. In every
iteration, the best accept_rate share of the population updates the culture,
and the culture then moves every individual.
The belief space has two parts:
- situational knowledge: the best accepted solution found so far,
- normative knowledge: for every component j, an interval [xmin_j, xmax_j] with the scores L_j and U_j of the solutions that set its ends. An accepted solution moves the lower end when its component is below xmin_j or when it is better than L_j (and the same for the upper end). Scores are compared with the problem's comparator, so maximization and constraints work.
Parameters
accept_rate: share of the population (sorted from best) that updates the culture. At least two solutions are accepted (one would give zero width intervals).-
influence_type: how the culture moves an individual (component j, N is a standard normal number, size_j = xmax_j - xmin_j, s is the situational solution):- normative size only: x_j += alpha * size_j * N
- situational direction only: x_j moves toward s_j by abs(0.1 * alpha * N)
- both: x_j moves toward s_j by abs(alpha * size_j * N)
- (default) normative size and direction: x_j moves up by abs(alpha * size_j * N) when it is below xmin_j, down when it is above xmax_j, and by beta * alpha * size_j * N inside the interval
When x_j equals s_j (types 2 and 3) the step keeps its random sign.
The four types are CAEP(Ns), CAEP(Sd), CAEP(Ns+Sd) and CAEP(Nsd) of Chung and Reynolds (1998), Section 3.7, with every step multiplied by
alpha. Withalpha=1, types 1 and 3, and type 4 withbeta=0.2, are the paper's operators. Type 2 uses the constant step 0.1 * alpha (the paper allows a constant or a self-adapted step). -
alpha: scale of every influence step (default 0.9) beta: scaling factor of the step inside the normative interval (type 4, default 0.2, the paper's value). Type 4 was chosen on benchmark tests. With very small populations (about 5) it can stall as the intervals shrink, and type 3 keeps moving toward the best solution.survival: "best" (default) keeps the bestpop_sizeof parents and offspring. "offspring" replaces every individual by its offspring.
Every individual makes one offspring per iteration (pop_size evaluations), and
the culture is then updated from the survivors.
Reference: R. G. Reynolds, "An introduction to cultural algorithms", Proceedings of the Third Annual Conference on Evolutionary Programming, 1994, pp. 131 to 139. C.-J. Chung and R. G. Reynolds, "CAEP: an evolution-based tool for real-valued function optimization using cultural algorithms", International Journal on Artificial Intelligence Tools, 7(3), 1998, pp. 239 to 291. R. G. Reynolds and C.-J. Chung, "Knowledge-based self-adaptation in evolutionary programming using cultural algorithms", Proceedings of the IEEE International Conference on Evolutionary Computation, 1997 (the source of the influence types).
Example¶
import ypea
problem = ypea.Problem(
ypea.Real("x", shape=20, lb=-10, ub=10),
lambda sol: ypea.benchmarks.sphere(sol.x),
vectorized=True,
name="sphere",
)
alg = ypea.CA(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
CA on sphere
best objective value: 4.11972e-10
feasible: True (violation 0)
evaluations: 20000, iterations: 199, time: 0.134 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.
problem = ypea.Problem( ...
vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
vectorized=true, ...
name="sphere");
alg = ypea.CA(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
CA on sphere
best objective value: 6.0077e-10
feasible: true (violation 0)
evaluations: 20000, iterations: 199, time: 0.212 s, stopped by: max_nfe
Search on Rastrigin¶