Package org.encog.ml.genetic.genome

Examples of org.encog.ml.genetic.genome.Chromosome


   */
  public NeuralGenome(
      final BasicNetwork network) {
    setOrganism(network);

    this.networkChromosome = new Chromosome();

    // create an array of "double genes"
    final int size = network.getStructure().calculateSize();
    for (int i = 0; i < size; i++) {
      final Gene gene = new DoubleGene();
View Full Code Here


      else {
        best = NEATParent.Dad;
      }
    }

    final Chromosome babyNeurons = new Chromosome();
    final Chromosome babyGenes = new Chromosome();

    final List<Long> vecNeurons = new ArrayList<Long>();

    int curMom = 0;
    int curDad = 0;

    NEATLinkGene momGene;
    NEATLinkGene dadGene;

    NEATLinkGene selectedGene = null;

    while ((curMom < mom.getNumGenes()) || (curDad < dad.getNumGenes())) {

      if (curMom < mom.getNumGenes()) {
        momGene = (NEATLinkGene) mom.getLinks().get(curMom);
      } else {
        momGene = null;
      }

      if (curDad < dad.getNumGenes()) {
        dadGene = (NEATLinkGene) dad.getLinks().get(curDad);
      } else {
        dadGene = null;
      }

      if ((momGene == null) && (dadGene != null)) {
        if (best == NEATParent.Dad) {
          selectedGene = dadGene;
        }
        curDad++;
      } else if ((dadGene == null) && (momGene != null)) {
        if (best == NEATParent.Mom) {
          selectedGene = momGene;
        }
        curMom++;
      } else if (momGene.getInnovationId() < dadGene.getInnovationId()) {
        if (best == NEATParent.Mom) {
          selectedGene = momGene;
        }
        curMom++;
      } else if (dadGene.getInnovationId() < momGene.getInnovationId()) {
        if (best == NEATParent.Dad) {
          selectedGene = dadGene;
        }
        curDad++;
      } else if (dadGene.getInnovationId() == momGene.getInnovationId()) {
        if (Math.random() < 0.5f) {
          selectedGene = momGene;
        }

        else {
          selectedGene = dadGene;
        }
        curMom++;
        curDad++;

      }

      if (babyGenes.size() == 0) {
        babyGenes.add(selectedGene);
      }

      else {
        if (((NEATLinkGene) babyGenes.get(babyGenes.size() - 1))
            .getInnovationId() != selectedGene.getInnovationId()) {
          babyGenes.add(selectedGene);
        }
      }

      // Check if we already have the nodes referred to in SelectedGene.
      // If not, they need to be added.
View Full Code Here

        NEATGenome lastGenome = null;
        for (String line : section.getLines()) {
          List<String> cols = EncogFileSection.splitColumns(line);
          if (cols.get(0).equalsIgnoreCase("g") ) {
            lastGenome = new NEATGenome();
            lastGenome.setNeuronsChromosome(new Chromosome());
            lastGenome.setLinksChromosome(new Chromosome());
            lastGenome.getChromosomes().add(
                lastGenome.getNeuronsChromosome());
            lastGenome.getChromosomes().add(
                lastGenome.getLinksChromosome());
            lastGenome.setGenomeID(Integer.parseInt(cols.get(1)));
View Full Code Here

   *
   * @param other
   *            The other genome.
   */
  public NEATGenome(final NEATGenome other) {
    this.neuronsChromosome = new Chromosome();
    this.linksChromosome = new Chromosome();
    this.setGeneticAlgorithm(other.getGeneticAlgorithm());

    getChromosomes().add(this.neuronsChromosome);
    getChromosomes().add(this.linksChromosome);

View Full Code Here

    this.outputCount = outputCount;
    setAmountToSpawn(0);
    this.speciesID = 0;

    final double inputRowSlice = 0.8 / (inputCount);
    this.neuronsChromosome = new Chromosome();
    this.linksChromosome = new Chromosome();

    getChromosomes().add(this.neuronsChromosome);
    getChromosomes().add(this.linksChromosome);

    for (int i = 0; i < inputCount; i++) {
View Full Code Here

        }
        organism[i + 1] = icandidate;
      }
    }
   
    this.pathChromosome = new Chromosome();
    this.getChromosomes().add(this.pathChromosome);
   
    for(int i=0;i<organism.length;i++)
    {
      IntegerGene gene = new IntegerGene();
View Full Code Here

  }

  @Override
  public void decode() {
    Chromosome chromosome = this.getChromosomes().get(0);
    int[] organism = new int[chromosome.size()];
   
    for(int i=0;i<chromosome.size();i++)
    {
      IntegerGene gene = (IntegerGene)chromosome.get(i);
      organism[i] = gene.getValue();
    }
   
    setOrganism(organism);
  }
View Full Code Here

    setOrganism(organism);
  }

  @Override
  public void encode() {
    Chromosome chromosome = this.getChromosomes().get(0);
   
    int[] organism = (int[])getOrganism();

    for(int i=0;i<chromosome.size();i++)
    {
      IntegerGene gene = (IntegerGene)chromosome.get(i);
      gene.setValue(organism[i]);
    }
  }
View Full Code Here

  private Chromosome chromosome;
  private int length;
 
  public PlayerGenome(GeneticAlgorithm geneticAlgorithm, Player player) {   
    this.player = player;
    this.chromosome = new Chromosome();
    setOrganism(this.player);
   
    this.length = player.getRules().length;
   
    for(int i=0;i<length;i++)
View Full Code Here

TOP

Related Classes of org.encog.ml.genetic.genome.Chromosome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.