Gray Wolf Optimization in Java

Todays Metaheuristic Optimization Algorithms are used widely from engineering problems to economic estimates. Most distinguish side between Optimization Algorithms and classic Machine Learning algorithms is ML has an ability to generalize, we design architecture, train/test model(weights) for using it later in order to estimate. But for Metaheuristic Optimization things change a little bit. Optimization is a pure algorithm to find some specific point/value for each dataset. Below you can see taxonomy of Swarm-based algorithms.

Hypothesis Function

In this blog we are talking about GWO(Gray Wolf Optimizer) that mimics wolf swarms to explore and exploit prey(in our case prey is point/value).


We are going to review GWO from programming point by steps below:
• Hunting
• Exploring
• Exploiting

Hunting(Initialization)

We initialize the number of population and define alpha, beta, delta(trio) and omega(others) wolves in swarm. More details in the code snippet below.

//Initialization Starts Here
System.out.println("Gray Wolf Initialization Starts...");
double a;
double r1, r2;
double A1, A2, A3;
double C1, C2, C3;
double Dalpha, Dbeta, Ddelta;
double Xalpha, Xbeta, Xdelta;
double X, X1, X2, X3;
int population = 30, dimension = 100;
double min = -100.0, max = 100.0;
int iteration = 500;

//Create Random population * dimension Optimization Matrix
CreateOptimizationMatrix(population, dimension, min, max);
//Find Fitness values of population by Sphere Benchmark function
FindFitnessValues(optimizationMatrix);
//Find 3 best solutions/trio(alpha, beta and delta wolves)
FindTrio(fitnessValues);

Exploring and Exploiting

(Iteration)

In this part of code our wolves explore and when they find prey by iterating. In each iteration we define alpha, beta and delta wolves of swarm by Sphere Benchmark function. At the end of each iteration we change position of other wolves(omega) due to trio.

//Iteration Starts Here
System.out.println("Gray Wolf Iteration Starts...");
for (int stCounter = 0; stCounter < iteration; stCounter=stCounter + 1) {
  for (int ndCounter = 0; ndCounter < optimizationMatrix.size(); ndCounter=ndCounter + 1) {
    for (int rdCounter = 0; rdCounter < optimizationMatrix.get(ndCounter).size(); rdCounter=rdCounter + 1) {
      //Update the position of each wolf in dimension
    }
  }
//Find Fitness values of population by Sphere Benchmark function
FindFitnessValues(optimizationMatrix);
//Find 3 best solutions/trio(alpha, beta and delta wolves)
FindTrio(fitnessValues);
}

Result

At the end of iterations we find the best positions of wolf population. But alpha wolf's position is where our wolves exploited prey. In the classic GWO our results after 500 iteration should be like for 30 population and 10 dimensions:

Alpha's Fitness Value at the End:
5.0912633467929775E-15
Alpha's Values at the End:
[8.133101711319844E-9, 6.235615799574227E-9, 7.839096104261306E-9, 8.504619117130029E-9, 6.425843414789091E-9, -6.768752804656183E-9, -5.520651393403654E-9, -8.312186750183637E-9, -5.951657081578676E-9, -6.0293785776069615E-9]

Appendices

• Source code

Please rotate your device!