Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
In this tutorial, we take a look at a very recent algorithm: the sine-cosine algorithm or SCA.
It is an optimization procedure that belongs to the family of population-based metaheuristic techniques. Within these, it belongs to the math-based algorithms.
The SCA algorithm was proposed by Seyedali Mirjalili in 2016. It is a population-based metaheuristic algorithm applied to optimization problems.
As is common to algorithms belonging to the same family, the optimization process consists of the movement of the individuals of the population within the search space, which represent approximations to the problem.
For this purpose, SCA uses trigonometric sine and cosine functions. At each step of the calculation, it updates the solutions according to the following equations:
Generally, the above equations are combined as follows:
where represents the current individual
at iteration
,
shows the best individual’s position at iteration
, and
are random parameters.
SCA uses the latter parameters to avoid entrapment in suboptimal solutions and to balance the exploration and exploitation processes:
where is a constant,
is the current iteration, and
represents the maximum iterations allowed. The above equation allows for the balance between exploration and exploitation.
SCA begins the optimization procedures with a set of initial random solutions. The best solution achieved becomes the destination point (target), which is used to update the other solutions. SCA refreshes the ranges of sine and cosine functions to maintain the exploitation of the search space as the iteration number increments. The SCA stops the optimization procedures when the iteration number reaches the maximum number of iterations.
The following figure illustrates the entire process:
Belazzoug et al. used SCA to select features for text categorization.
The goal of the problem is to find the optimal subset of features. Each solution consists of a fixed size vector where each dimension encodes a value for each feature in the range . A feature with a value greater than or equal to 0.5 implies its selection.
The evaluation of each solution (features subset) takes into account both the accuracy of the classification and the size of the selected subset. This is an example of multi-objective optimization, where the objectives are the minimization of the classification error and the subset size:
where:
This objective function allows the evaluation of each individual in the general procedure we have given in the figure above.
Of course, we have to calculate a value for the classification error. In the context of Belazzoug’s work, this value is obtained through the Information Gain (Mutual Information), which measures the number of bits of information obtained for category prediction by knowing the presence or the absence of a term in a document.
In this section, we’ll make a numerical example of optimization with SCA. Let’s try to find the minimum of a real two-variable function, the Six-Hump Camel Function, often used as a test:
The function has a minimum for:
Using Dr. Pereira’s code, the optimization process, starting from a random population, is as follows:
| 0 | 0.14352534 | -0.54935549 | -0.84019004 |
| 100 | -0.08822356 | 0.70538939 | -1.0312019 |
| 200 | -0.08822356 | 0.70538939 | -1.0312019 |
| 300 | -0.0996268 | 0.71069016 | -1.0312051 |
| 400 | -0.09105287 | 0.7089342 | -1.03150536 |
| 500 | -0.09105287 | 0.7089342 | -1.03150536 |
| 600 | -0.08818936 | 0.71163966 | -1.03161103 |
| 700 | -0.08818936 | 0.71163966 | -1.03161103 |
| 800 | -0.08818936 | 0.71163966 | -1.03161103 |
| 900 | -0.09038102 | 0.71235722 | -1.03162643 |
| 1000 | -0.09038102 | 0.71235722 | -1.03162643 |
As happens to all optimization algorithms in general, and to metaheuristic algorithms in particular, the goodness of the SCA solutions depends on an optimal balance between exploration and exploitation. To explain how this balancing, we will start from the following figure, which represents two functions dependent on sine and cosine in the interval for the independent variable, with values of the functions within the range
:
The variable represents the set of independent variables that define the search space.
As we can see, the range of variability in the domain is much greater for the values of the functions located in the upper and lower part of the curves, compared to the central section. This fact allows us to state the following heuristic rule:
The reasons for the efficiency of the SCA algorithm are different, some common to other metaheuristic techniques:
In this tutorial, we have briefly analyzed the sine-cosine algorithm. This is an optimization procedure that has original characteristics with respect to other conventional algorithms belonging to the family of metaheuristic techniques.
We have left out many interesting features, including the variants of the algorithm that arose from the original proposal by Seyedali Mirjalili. The analysis of these variants is outside the scope of this tutorial, but we invite the reader to explore them.