Results 1 to 11 of 11
  1. #1
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default 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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  3. #3
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    Here is some of the related code:

    Java Code:
    public double evaluate(IChromosome subject) {
            double[] x = convertGeneToDouble(subject);
            double f = objFun.functionAtX(x);
            f += addPenalty(subject);        
            System.out.println("f: " + f);
            double fitness = 1.0+1.0/Math.abs(f);
            System.out.println("Fitness: " + fitness);
            return fitness;
        }
    Java 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.

  4. #4
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    Eranga, can you post and example java code for GAPlayground?

    Thanks.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  6. #6
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    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

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  8. #8
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    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.

    Thanks for your comments.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  10. #10
    Iskatel is offline Member
    Join Date
    Mar 2010
    Posts
    27
    Rep Power
    0

    Default

    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. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Q about Genetic programming
    By m00nchile in forum New To Java
    Replies: 8
    Last Post: 05-12-2010, 11:23 AM
  2. genetic algorithms
    By nurfadhillah in forum Advanced Java
    Replies: 1
    Last Post: 10-19-2008, 04:13 PM
  3. Algorithms in Java: where to find sources?
    By javalover in forum New To Java
    Replies: 0
    Last Post: 09-21-2008, 07:33 AM
  4. Jgap 3.3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-12-2007, 06:03 PM
  5. Jgap 3.2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 06-24-2007, 08:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •