Metaheuristics

Teaching-Learning-based Optimization in MATLAB

Get the code
Comments

Implement teaching-learning-based optimization in MATLAB with teacher and learner phases, bound handling, and a Sphere test problem.

Illustration for Teaching-Learning-based Optimization in MATLAB
On this page

Teaching-Learning-based Optimization (TLBO) is a metaheuristic inspired by the process of teaching and learning. It uses a simplified mathematical model of how students in a class improve their knowledge. The algorithm was proposed by Rao, Savsani and Vakharia in 2011 in this paper (opens in a new tab), where they used it for constrained mechanical design problems.

In TLBO, the population is a class of learners. Each learner is a candidate solution, and its cost is its result in an exam. The best learner acts as the teacher. The class improves in two phases: first the teacher raises the mean level of the class, then the learners improve by learning from each other.

How TLBO works

Let xix_i be the position of learner ii, MM the mean position of the class, and xteacherx_{\text{teacher}} the best learner in the current iteration.

Teacher phase

Each learner moves toward the teacher and away from the class mean:

xinew=xi+r⊙(xteacher−TF M)x_i^{\text{new}} = x_i + r \odot \left(x_{\text{teacher}} - T_F\, M\right)

Here rr is a vector of uniform random numbers in [0,1][0, 1], and TFT_F is the teaching factor, chosen at random as 1 or 2. The new position replaces the old one only if its cost is lower.

Learner phase

Each learner ii picks another learner jj at random. If jj is better, learner ii moves toward it. Otherwise, it moves away from it:

xinew={xi+r⊙(xj−xi)if f(xj)<f(xi)xi+r⊙(xi−xj)otherwisex_i^{\text{new}} = \begin{cases} x_i + r \odot (x_j - x_i) & \text{if } f(x_j) < f(x_i) \\ x_i + r \odot (x_i - x_j) & \text{otherwise} \end{cases}

Again, the new position is kept only if it improves the cost. This greedy acceptance in both phases means that a learner never gets worse.

No algorithm specific parameters

Most metaheuristics have control parameters of their own, such as the inertia weight of PSO or the mutation rate of a genetic algorithm. The basic TLBO update uses no additional user-selected coefficients. Population size, iteration budget, variable scaling, bounds, and the problem formulation still affect the result.

Implementation in MATLAB

This post shares an open-source MATLAB implementation of TLBO. The code is structured, so if you know MATLAB, you should find it easy to use in your research projects.

What is in the download

The TLBO folder holds three files:

  • tlbo.m: the TLBO script, with the problem definition, the parameters, the main loop and the results.
  • Sphere.m: the sample cost function, f(x)=∑i=1nxi2f(x) = \sum_{i=1}^{n} x_i^2.
  • main.m: a one line entry point that runs tlbo.m.

To run the code, open the TLBO folder in MATLAB and run main.m. 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.

Parameters in the code

Parameter Meaning Value
nVar Number of decision variables 10
VarMin, VarMax Lower and upper bounds of the variables −10-10, 1010
MaxIt Maximum number of iterations 1000
nPop Population size (number of learners) 50

In every iteration, the code computes the class mean and selects the teacher once, before the teacher phase. After each move, any variable outside the bounds is set back to the nearest bound.

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 in the problem definition section of tlbo.m.

Check the result

The Sphere example has a known minimum of 0 at the origin. Check the best cost and coordinates, then repeat the run before comparing population sizes. One iteration contains both a teacher phase and a learner phase, so iteration counts alone do not give an equal evaluation budget against an algorithm with one update per member. A lack of extra update coefficients does not remove the need to validate the objective and constraints.

  • YPEA is a MATLAB toolbox that includes TLBO and 14 other algorithms that share one problem definition.
  • Particle Swarm Optimization in MATLAB is another population based method with the same code structure.

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, Teaching-Learning-based Optimization in MATLAB (YPEA111), Yarpiz, 2015. https://yarpiz.com/teaching-learning-based-optimization-ypea111
BibTeX
@misc{yarpiz-ypea111,
  author = {{Mostapha Kalami Heris}},
  title = {{Teaching-Learning-based Optimization in MATLAB}},
  howpublished = {Yarpiz},
  year = {2015},
  note = {Code YPEA111},
  url = {https://yarpiz.com/teaching-learning-based-optimization-ypea111}
}

Comments

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