3
$\begingroup$

I'm trying to apply a polynomial approximation for a given function (via Genetic Algorithms), and so far the results are not so good:

 # or any other GA package
  require(gaoptim)

  # for polyval
  require(pracma)

  # polynomial of degree 10
  ndeg = 10  
  ndim = ndeg + 1

  # search limits
  search.low = rep(-1, ndim)
  search.up = rep(1, ndim)

  # no. of data points
  m = 101 
  xi = seq(-1, 1, length = m)
  yi = 1 / (1 + (5*xi)^2)

  # fitness function
  pfn = function(p) max(abs(polyval(c(p), xi) - yi))

  # gaoptim perform maximization, so transform the fitness function
  pfninv = function(p){ 1/(pfn(p) + 1) }

  ## set up the ga
  ga = GAReal(pfninv, search.low, search.up, popSize = 500)
  ga$evolve(100)
  y2 = polyval(ga$bestIndividual(), xi)

  plot(xi, yi, ylim = range(c(yi, y2)), type = 'l', main = 'Runge function')
  lines(xi, y2, col = 'red')

enter image description here

Is there any strategy i can apply here, or this is a No-no approach? Maybe a better fitness function, or expand the search limits? Higher values of popSize doesn't seem to help too much.

Thanks for any insight!

$\endgroup$

1 Answer 1

2
$\begingroup$

1) Your target function is yi = 1 /(1 + (5*xi)^2), which is not a polynomial, so it's going to be hard to approximate with a polynomial:

enter image description here

2) If you invert the target function, yi = 1 + (5*xi)^2, increase your bounds, e.g. search.low = rep(-50, ndim); search.up= rep(50, ndim)

enter image description here

3) It's more common to take the root-mean-square error (RMSE) as the fitness function instead of max(abs(polyval(c(p), xi) - yi)).

$\endgroup$
4
  • $\begingroup$ Sorry for the mistake, i edited the question. $\endgroup$
    – Fernando
    Oct 15, 2013 at 17:56
  • $\begingroup$ The issue is that the search space of your GA, viz. the polynomials of degree 10, is too far away from your target function f(x) = 1 /(1 + (5*x)^2), hence the poor fitness value. $\endgroup$ Oct 15, 2013 at 18:22
  • $\begingroup$ So theoretically, if i increase this search i should get better fits? $\endgroup$
    – Fernando
    Oct 15, 2013 at 18:23
  • $\begingroup$ Yes but since your target function cannot be approximated by a polynomial, increasing the degree is useless. In evolutionary computation such task is called symbolic regression and we use genetic programming to optimize, not GA (GA typically requires to have a pretty good knowledge on the structure of your target function). $\endgroup$ Oct 15, 2013 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.