2

I am working on a genetic algorithm. Here is how it works :

  • Input : a list of 2D points
  • Input : the degree of the curve
  • Output : the equation of the curve that passes through points the best way (try to minimize the sum of vertical distances from point's Ys to the curve)

The algorithm finds good equations for simple straight lines and for 2-degree equations.

But for 4 points and 3 degree equations and more, it gets more complicated. I cannot find the right combination of parameters : sometimes I have to wait 5 minutes and the curve found is still very bad. I tried modifying many parameters, from population size to number of parents selected...

Do famous combinations/theorems in GA programming can help me ?

Thank you ! :)

  • 1
    What do mean by the degree of the curve? Is it constant? – Amir H. Bagheri Apr 15 '17 at 20:15
  • 1
    I think she means the largest power of the polynomial interpolation. But you just have to solve some equations, I don't think GA should be used there. They are good in very complex problems where you have to make a tradeoff between solution quality and time invested. – maraca Apr 15 '17 at 20:33
  • You have to tell/show us what you are doing in order for us to help you. Also, you have to ask a specific question about programming. – RBarryYoung Apr 15 '17 at 20:58
  • Thanks for your answers. By degree I mean the largest power of the polynomial equation, as maraca said. I know there are more powerful things than GA to solve that but I try to train myself to this type of algorithms. – Anselme Clergeot Apr 16 '17 at 13:51

2 Answers2

2

Based on what is given, you would need a polynomial interpolation in which, the degree of the equation is number of points minus 1.

n = (Number of points) - 1

Now having said that, let's assume you have 5 points that need to be fitted and I am going to define them in a variable:

var points = [[0,0], [2,3], [4,-1], [5,7], [6,9]]

Please be noted the array of the points have been ordered by the x values which you need to do.

Then the equation would be:

f(x) = a1*x^4 + a2*x^3 + a3*x^2 + a4*x + a5

Now based on definition (https://en.wikipedia.org/wiki/Polynomial_interpolation#Constructing_the_interpolation_polynomial), the coefficients are computed like this:

enter image description here

Now you need to used the referenced page to come up with the coefficient.

Amir H. Bagheri
  • 1,416
  • 1
  • 9
  • 17
  • The problem you described is exactly what I am trying to do. But I am trying to solve that with a genetic algorithm. I will learn more about the link you showed me. Thank you ! – Anselme Clergeot Apr 16 '17 at 13:55
1

It is not that complicated, for the polynomial interpolation of degree n you get the following equation:

p(x) = c0 + c1 * x + c2 * x^2 + ... + cn * x^n = y

This means we need n + 1 genes for the coefficients c0 to cn.

The fitness function is the sum of all squared distances from the points to the curve, below is the formula for the squared distance. Like this a smaller value is obviously better, if you don't want that you can take the inverse (1 / sum of squared distances):

d_squared(xi, yi) = (yi - p(xi))^2

I think for faster conversion you could limit the mutation, e.g. when mutating choose a new value with 20% probability between min and max (e.g. -1000 and 1000) and with 80% probabilty a random factor between 0.8 and 1.2 with which you multiply the old value.

maraca
  • 8,468
  • 3
  • 23
  • 45