How can I use differential evolution to find the maximum values of the function function f(x) = -x(x+1) from -500 to 500? I need this for a chess program I am making, I have begun researching on Differential Evolution and am still finding it quite difficult to understand, let alone use for a program. Can anyone please help me by introducing me to the algorithm in a simple way and possibly giving some example pseudo-code for such a program?
Share
First, of all, sorry for the late reply.
I bet that you won’t know the derivatives of the function that you’ll be trying to max, that’s why you want to use the Differential Evolution algorithm and not something like the Newton-Raphson method.
I found a great link that explains Differential Evolution in a straightforward manner: http://web.as.uky.edu/statistics/users/viele/sta705s06/diffev.pdf.
On the first page, there is a section with an explanation of the algorithm:
Initialize an array with size
j. Add a numberjof distinct random x values from-500 to 500, the interval you are considering right now. Ideally, you would know around where the maximum value would be, and you would make it more probable for yourxvalues to be there.Hmmm… This is a bit more complicated. Iterate through the array you made in the last step. For each
xvalue, pick two random indexes (yj1andyj2). Construct a candidatexvalue withcx = α(yj1 − yj2), where you choose yourα. You can try experimenting with different values of alpha.Check to see which one is larger, the candidate value or the x value at
j. If the candidate value is larger, replace it for thexvalue atj.Do this all until all of the values in the array are more or less similar.
Tahdah, any of the values of the array will be the maximum value. Just to reduce randomness (or maybe this is not important….), average them all together.
The more stringent you make the
aboutmethod, the better approximations you will get, but the more time it will take.For example, instead of
Math.abs(a - b) <= alpha /10, I would doMath.abs(a - b) <= alpha /10000to get a better approximation.You will get a good approximation of the value that you want.
Happy coding!
Code I wrote for this response:
}
If you have any questions after reading this, feel free to ask them in the comments. I’ll do my best to help.