## 1. Introduction

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.

## 2. Sine-Cosine Algorithm

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:

- conditions the shift in updating a solution, towards the best solution () or outwards it (). decreases linearly from a certain constant value to zero:

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.

- has values in the range and determines how big the movement of a solution is towards or outwards of the destination.
- has values in the range and is used to assign a weight to the destination, reinforcing or inhibiting the impact of the destination point on the updating process of the other solutions.
- , with values in the range , is a switch between the sine and cosine functions.

## 3. SCA in Practice

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:

### 3.1. An Example: Features Selection

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:

- represents the relative importance of the error rate with respect to the number of features;
- is the error in the classification;
- is the number of features of the current solution for dimension ;
- is the total number of features.

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.

### 3.2. A Numerical Calculation

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:

## 4. Exploration vs. Exploitation

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:

- For values of the sine and cosine functions in the intervals, and we have a predominance of the exploratory process since the SCA tests many different points in the problem space.
- For values of the sine and cosine functions in the range , there is a predominance of the exploiting phase.

## 5. Why Does SCA Work?

The reasons for the efficiency of the SCA algorithm are different, some common to other metaheuristic techniques:

- SCA works with a population of solutions, which benefit from parallel exploration phenomena
- It investigates several regions of the solution space simultaneously for values ??of the sine and cosine functions outside the range
- During the exploiting process, with sine and cosine values ??in the range , SCA investigates several promising solutions simultaneously
- The adaptive values ??of the parameters allow transferring the promising strategies and regions between the exploratory and exploitative processes
- The best solution at a certain point in the calculation is saved in a variable and becomes the target of the problem, and therefore is never lost during the optimization phase
- The optimization process is convergent

## 6. Conclusion

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.