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

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 be the position of learner , the mean position of the class, and the best learner in the current iteration.
Teacher phase
Each learner moves toward the teacher and away from the class mean:
Here is a vector of uniform random numbers in , and 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 picks another learner at random. If is better, learner moves toward it. Otherwise, it moves away from it:
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, .main.m: a one line entry point that runstlbo.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 | , |
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.
Related posts
- 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.
Mostapha Kalami Heris, Teaching-Learning-based Optimization in MATLAB (YPEA111), Yarpiz, 2015. https://yarpiz.com/teaching-learning-based-optimization-ypea111@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}
}Published Updated
Comments