Re: Question about Mutation Operator

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about Mutation Operator

Giuseppe Quartarone
Hi,
no one know if this is a bug or not?
....
So I read the MutationOperator.class code present in the package that I
downloaded and I found the following piece of code at line 220.

// Process all atomic elements in the gene. For a StringGene this
>
>          // would be as many elements as the string is long , for an
>
>          // IntegerGene, it is always one element.
>
>          // --------------------------------------------------------------
>
>          if (genes[j] instanceof ICompositeGene) {
>
>            ICompositeGene compositeGene = (ICompositeGene) genes[j];
>
>            if (m_monitorActive) {
>
>
> compositeGene.setUniqueIDTemplate(chrom.getGene(j).getUniqueID(), 1);
>
>            }
>
>            for (int k = 0; k < compositeGene.size(); k++) {
>
>              mutateGene(compositeGene.geneAt(k), generator);
>
>              if (m_monitorActive) {
>
>                compositeGene.geneAt(k).setUniqueIDTemplate(
>
>                    ( (ICompositeGene)
> chrom.getGene(j)).geneAt(k).getUniqueID(),
>
>                    1);
>
>              }
>
>            }
>
>          }
>
>          else {
>
>            mutateGene(genes[j], generator);
>
>            if (m_monitorActive) {
>
>              genes[j].setUniqueIDTemplate(chrom.getGene(j).getUniqueID(),
> 1);
>
>            }
>
>          }
>

As you can see the "mutateGene" method is called either by the true branch
and the else branch. Below the "mutateGene" implementation:

/**
>
>   * Helper: mutate all atomic elements of a gene.
>
>   *
>
>   * @param a_gene the gene to be mutated
>
>   * @param a_generator the generator delivering the amount of mutation
>
>   *
>
>   * @author Klaus Meffert
>
>   * @since 1.1
>
>   */
>
>  private void mutateGene(final Gene a_gene, final RandomGenerator
> a_generator) {
>
>     for (int k = 0; k < a_gene.size(); k++) {
>
>      // Retrieve value between 0 and 1 (not included) from generator.
>
>      // Then map this value to range -1 and 1 (-1 included, 1 not).
>
>      // -------------------------------------------------------------
>
>      double percentage = -1 + a_generator.nextDouble() * 2;
>
>      // Mutate atomic element by calculated percentage.
>
>      // -----------------------------------------------
>
>      a_gene.applyMutation(k, percentage);
>
>     }
>
>  }
>

Thus, when the "mutateGene" is called and the gene is not an instance of
"ICompoisteGene" his size is zero and the mutation never take place.
However, this issue doesn’t occur if I call the "applyMutation" in the else
branch, so I'm wondering whether this is the main cause or I wrongly set up
the framework configuration.

Thanks in advance for your time

Best regards
Giuseppe


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about Mutation Operator

Klaus Meffert-5
Giuseppe,
 
there does not seem to be a bug.
The below logic should work as intended.
Please see the class org.jgap.BaseGene, where size() is defined as:
  public int size() {
    return 1;
  }
 
 
So all genes other than CompositeGene, like IntegerGene, return size = 1 per default.
 
Best
 


From: Giuseppe Quartarone [mailto:[hidden email]]
Sent: Wednesday, June 05, 2013 3:41 PM
To: [hidden email]
Subject: Re: [jgap-users] Question about Mutation Operator

Hi,
no one know if this is a bug or not?
....
So I read the MutationOperator.class code present in the package that I
downloaded and I found the following piece of code at line 220.

// Process all atomic elements in the gene. For a StringGene this
>
>          // would be as many elements as the string is long , for an
>
>          // IntegerGene, it is always one element.
>
>          // --------------------------------------------------------------
>
>          if (genes[j] instanceof ICompositeGene) {
>
>            ICompositeGene compositeGene = (ICompositeGene) genes[j];
>
>            if (m_monitorActive) {
>
>
> compositeGene.setUniqueIDTemplate(chrom.getGene(j).getUniqueID(), 1);
>
>            }
>
>            for (int k = 0; k < compositeGene.size(); k++) {
>
>              mutateGene(compositeGene.geneAt(k), generator);
>
>              if (m_monitorActive) {
>
>                compositeGene.geneAt(k).setUniqueIDTemplate(
>
>                    ( (ICompositeGene)
> chrom.getGene(j)).geneAt(k).getUniqueID(),
>
>                    1);
>
>              }
>
>            }
>
>          }
>
>          else {
>
>            mutateGene(genes[j], generator);
>
>            if (m_monitorActive) {
>
>              genes[j].setUniqueIDTemplate(chrom.getGene(j).getUniqueID(),
> 1);
>
>            }
>
>          }
>

As you can see the "mutateGene" method is called either by the true branch
and the else branch. Below the "mutateGene" implementation:

/**
>
>   * Helper: mutate all atomic elements of a gene.
>
>   *
>
>   * @param a_gene the gene to be mutated
>
>   * @param a_generator the generator delivering the amount of mutation
>
>   *
>
>   * @author Klaus Meffert
>
>   * @since 1.1
>
>   */
>
>  private void mutateGene(final Gene a_gene, final RandomGenerator
> a_generator) {
>
>     for (int k = 0; k < a_gene.size(); k++) {
>
>      // Retrieve value between 0 and 1 (not included) from generator.
>
>      // Then map this value to range -1 and 1 (-1 included, 1 not).
>
>      // -------------------------------------------------------------
>
>      double percentage = -1 + a_generator.nextDouble() * 2;
>
>      // Mutate atomic element by calculated percentage.
>
>      // -----------------------------------------------
>
>      a_gene.applyMutation(k, percentage);
>
>     }
>
>  }
>

Thus, when the "mutateGene" is called and the gene is not an instance of
"ICompoisteGene" his size is zero and the mutation never take place.
However, this issue doesn’t occur if I call the "applyMutation" in the else
branch, so I'm wondering whether this is the main cause or I wrongly set up
the framework configuration.

Thanks in advance for your time

Best regards
Giuseppe


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Loading...