Message Boards Message Boards

Implementing Jaya in Wolfram Language

Posted 3 years ago

Hi all, I am trying to implement the Jaya optimization algorithm (Jaya). This is a flowchart from the Author 's webpage showing the details of the Algorithm. enter image description here Note that there is a typo in the equation in the above figure. It should be:

X'j,k,i = Xj,k,i + r1,j,i (Xj,best,i - │Xj,k,i│) - r2,j,i (Xj,worst,i - │Xj,k,i│)

I have implemented it in the Wolfram Language (WL) as follows:

Setting the parameters

lb = -10; ub = 10; n (*pop size*)= 4; d (*dimension*)= 2; fn (* function number*)= 1;

Initializing the population

x = RandomReal[{lb, ub}, {n, d + 1}];

Calculating the objective function for each individual

Table[x[[i, -1]] = f[x[[i, 1 ;; -2]], fn], {i, 1, n}]; (* f is the objective function. I am using the last element of each solution to store its objective function *)

The Jaya update equation

update[y_] := Module[{z},

   z = y + RandomReal[{0, 1}, d] (x[[minIndex, 1 ;; -2]] - Abs[y]) -  RandomReal[{0, 1}, d] (x[[maxIndex, 1 ;; -2]] - Abs[y]);

   Map[If[# < lb, lb, If[# > ub, ub, #]] &, z]];

One iteration of Jaya

jaya[x_] := Module[{y, fy},

  minIndex = First[Ordering[x[[All, -1]], 1]];

  maxIndex = First[Ordering[x[[All, -1]], -1]];

  y = Map[update, x[[All, 1 ;; -2]]];

  fy = Table[f[y[[i, All]], fn], {i, 1, n}];

  y = MapThread[Append, {y, fy}];

  MapThread[(If[#1[[-1]] <= #2[[-1]], #1, #2]) &, {x, y}]

  ]

Repeating the update

Timing[Min[Nest[jaya, x, 1000] [[All, -1]]]]

The results when applied to the Sphere function (shown below) are not close to the Matlab implementation of the same Algorithm for the same setting and on the same function.

f[x_, 1] := Total[x^2] (* The Sphere function *)

In addition, the WL implementation is much slower than Matlab even after using Parallelize, ParallelTable, etc.

Please advice. Thanks!

POSTED BY: Mahamed Omran
Posted 3 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract