# JGAP genetic algorithms for Java

• 10-14-2010, 12:27 PM
Iskatel
JGAP genetic algorithms for Java
Hi all,

I am stuck with JGAP, I am trying to test the code by finding Maximum Likelihood Estimates, I seem to have a problem with the fitness function. First, JGAP requires the fitness function to be positive valued. I have tried the usual transform: fitness = Math.exp(f(x)), but this doesn't work, JGAP can't find the optimum values of x. In most cases fitness stays at 0.0 due to f(x) being very low. Any suggestions on scaling the f(x)? Or is there other more popular packages for GA?

Regards,
Iskatel
• 10-14-2010, 01:12 PM
Eranga
Could you provide more details, like posting some code segment related to your work and so on. It's easy comment on your question.

I'm using GA Playground toolkit, in all my studies, which is more capable of customization accordingly.
• 10-14-2010, 01:55 PM
Iskatel
Here is some of the related code:

Code:

public double evaluate(IChromosome subject) {
double[] x = convertGeneToDouble(subject);
double f = objFun.functionAtX(x);
System.out.println("f: " + f);
double fitness = 1.0+1.0/Math.abs(f);
System.out.println("Fitness: " + fitness);
return fitness;
}

Code:

public double functionAtX(double[] param){
int numX = this.X[0].length;
double b = param[param.length - 2];
double var = param[param.length - 1];
double sum = 0;
for (int i = 0; i < 30; i++) {
double mean = 0;
for (int j = 0; j < numX; j++) {
mean = param[j] * this.X[i][j] + b; // A*X+B
}
double logL = -Math.log(2 * Math.PI * var) / 2 - Math.pow((Y[i] - mean), 2) / (2 * var);
sum += logL;
}
return sum;
}

I am just learning to use JGAP, I am trying to fit simple linear regression for a normally distributed data: Y = a + b*x.

I guess I need to make transformations of parameters and restrict them to say [0,1] and reward more those chromosomes that come up with lower variance than others.
• 10-14-2010, 03:47 PM
Iskatel
Eranga, can you post and example java code for GAPlayground?

Thanks.
• 10-15-2010, 08:07 AM
Eranga
I'll try to find some of the stuff that I've done on my assignments, and send it to you later. I've to search them. :)

But I've found the following URL from my bookmarks.

GA Playground - Java Genetic Algorithms Toolkit

Scroll to bottom of the page, you can see several demos related with different fitness functions.
• 10-15-2010, 02:17 PM
Iskatel
Thanks Eranga; I don't really get the GA Playground; the example on the link you've posted is an applet, I wonder whether GA Playground can be used as library for my Java programs that involve other stuff. For such libraries there are usually example codes on their websites, but not for the GA Playground.

With kind regards,
Iskatel
• 10-18-2010, 10:51 AM
Eranga
If you search on the that, you can find the complete free download package. If not let me know.

I'll try to send you an example today from my stuff.
• 10-25-2010, 04:08 PM
Iskatel
Sorry for late reply Eranga. I got the JGAP working, I guess it just wasn't good for some stuff, I read that GA in general can home in to a local maximum and stay there. Now, it is working OK within reason I guess. I will probably have a look at the GA Playground later again.

• 10-25-2010, 06:12 PM
Eranga
When we start learning GA and looking into different tools, I remember that my professor said that most of the tools are not capable of training data set properly with complex training equations. It's not an easy task to implement those equations, and I don't know JGAP in that too.

GA Playground is more advanced than other tools I've used. More importantly, it could customize easily.
• 11-04-2010, 01:44 PM
Iskatel
I have downloaded the GA zip package. I can't find any examples of using GA within a program, or using it as a library.
• 11-04-2010, 05:26 PM
Eranga
Quote:

Originally Posted by Iskatel
I have downloaded the GA zip package. I can't find any examples of using GA within a program, or using it as a library.

Have you look at the following?

GA Playground - Java Genetic Algorithms Toolkit