Metaheuristics

Cultural Algorithm (CA) in MATLAB

Get the code
Comments

Implement a Cultural Algorithm in MATLAB with shared situational and normative knowledge, Gaussian moves, and a bounded Sphere example.

Illustration for Cultural Algorithm (CA) in MATLAB
On this page

This package is a MATLAB implementation of the Cultural Algorithm (CA), a metaheuristic based on social evolution. In CA, a population of individuals evolves together with a shared body of knowledge called the culture. The Cultural Algorithm was introduced by Robert G. Reynolds in 1994.

How the Cultural Algorithm works

CA has two levels. The population space holds the individuals, which are candidate solutions. The belief space holds the culture, the knowledge that the population has gathered so far. The two levels talk to each other in every iteration:

  1. Acceptance. An acceptance function chooses which individuals may add to the culture. In this code, these are the best individuals of the population.
  2. Adjustment. The accepted individuals update the belief space.
  3. Influence. The culture guides how every individual changes in the next iteration.

So the culture works like a shared memory. Good experience from one generation is stored in it and passed on to the next.

The culture in this code

In this code, the culture has two parts: situational knowledge (the best solution found) and normative knowledge (an interval for each variable, built from the accepted individuals).

The normative interval of variable jj has a lower end ljl_j and an upper end uju_j, and each end remembers the cost of the individual that set it. An accepted individual moves an end when it lies outside the interval, or when its cost is lower than the stored cost of that end. The width of the interval is sj=uj−ljs_j = u_j - l_j.

The code has four ways to let the culture influence the population. Three of them are commented out. The active one uses both parts of the culture. Each variable of each individual takes a Gaussian step with a standard deviation of α sj\alpha\, s_j, and the direction of the step points toward the best solution:

xj←xj+∣α sj ε∣⋅sign⁡(bj−xj),ε∼N(0,1)x_j \leftarrow x_j + \left|\alpha\, s_j\, \varepsilon\right| \cdot \operatorname{sign}\left(b_j - x_j\right), \qquad \varepsilon \sim \mathcal{N}(0, 1)

where bjb_j is variable jj of the situational knowledge. If xjx_j already equals bjb_j, the code keeps the random sign of the step. As the accepted individuals gather in a smaller region, the intervals shrink, and the steps get smaller.

The example and its settings

The example minimizes the Sphere function with 10 variables in the range from −10-10 to 1010, using a population of 50 and 1000 iterations. The acceptance ratio pAccept is 0.35, so the best round(0.35*50), which is 18, individuals adjust the culture in each iteration. The step coefficient alpha is 0.3. The parameter beta (0.5) is used only by the fourth influence method, which is commented out.

What is in the download

  • main.m: starts the example by calling ca
  • ca.m: the main algorithm, with its settings
  • AdjustCulture.m: updates the culture from the accepted individuals
  • Sphere.m: the cost function
  • LICENSE and README.md

To try it, run main.m in MATLAB. The files are in the Cultural Algorithm folder of the download. The program prints the best cost of every iteration and then plots the best cost against the iteration number on a logarithmic scale.

The script creates the first population with unifrnd, a function of the Statistics and Machine Learning Toolbox, so it probably needs that toolbox.

To solve your own problem, write a cost function that takes a row vector and returns a number, and set CostFunction, nVar, VarMin and VarMax at the top of ca.m. To try another influence method, uncomment its block in the main loop of ca.m and comment out the active one.

Check the result

For the Sphere example, compare the best coordinates with the origin and the cost with the known minimum of 0. The normative intervals control the scale of new steps, so a narrow interval can reduce exploration. When experimenting with the commented influence methods, keep only the intended method active and record which one produced the result. Repeat runs before drawing conclusions about the acceptance ratio or step coefficient.

Downloads

How to cite

If you use this code or tutorial in your work, articles or publications, please cite it.

Plain text
Mostapha Kalami Heris, Cultural Algorithm (CA) in MATLAB (YPEA125), Yarpiz, 2015. https://yarpiz.com/cultural-algorithm-ypea125
BibTeX
@misc{yarpiz-ypea125,
  author = {{Mostapha Kalami Heris}},
  title = {{Cultural Algorithm (CA) in MATLAB}},
  howpublished = {Yarpiz},
  year = {2015},
  note = {Code YPEA125},
  url = {https://yarpiz.com/cultural-algorithm-ypea125}
}

Comments

Sign in or create a free account to join the discussion. No password needed.