Package org.encog.neural.neat.training

Examples of org.encog.neural.neat.training.NEATLinkGene


                .setSplitX(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            neuronGene
                .setSplitY(CSVFormat.EG_FORMAT.parse(cols.get(7)));
            lastGenome.getNeurons().add(neuronGene);
          } else if (cols.get(0).equalsIgnoreCase("l")) {
            NEATLinkGene linkGene = new NEATLinkGene();
            linkGene.setId(Integer.parseInt(cols.get(1)));
            linkGene.setEnabled(Integer.parseInt(cols.get(2))>0);
            linkGene.setRecurrent(Integer.parseInt(cols.get(3))>0);
            linkGene.setFromNeuronID(Integer.parseInt(cols.get(4)));
            linkGene.setToNeuronID(Integer.parseInt(cols.get(5)));
            linkGene.setWeight(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            linkGene.setInnovationId(Integer.parseInt(cols.get(7)));
            lastGenome.getLinks().add(linkGene);
          }
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("CONFIG")) {
View Full Code Here


        out.addColumn(neatNeuronGene.getSplitX());
        out.addColumn(neatNeuronGene.getSplitY());
        out.writeLine();
      }
      for (Gene linkGene : neatGenome.getLinks().getGenes()) {
        NEATLinkGene neatLinkGene = (NEATLinkGene) linkGene;
        out.addColumn("l");
        out.addColumn(neatLinkGene.getId());
        out.addColumn(neatLinkGene.isEnabled());
        out.addColumn(neatLinkGene.isRecurrent());
        out.addColumn(neatLinkGene.getFromNeuronID());
        out.addColumn(neatLinkGene.getToNeuronID());
        out.addColumn(neatLinkGene.getWeight());
        out.addColumn(neatLinkGene.getInnovationId());
        out.writeLine();
      }
    }
    out.addSubSection("SPECIES");
    for (Species species : pop.getSpecies()) {
View Full Code Here

      lookup.put(neuronGene.getId(), i);
    }

    // loop over connections
    for (int i = 0; i < linksChromosome.size(); i++) {
      final NEATLinkGene linkGene = linksChromosome.get(i);
      if (linkGene.isEnabled()) {
        links.add(new NEATLink(lookup.get(linkGene.getFromNeuronID()),
            lookup.get(linkGene.getToNeuronID()), linkGene
                .getWeight()));
      }

    }
View Full Code Here

    int countTrysToFindOldLink = getOwner().getMaxTries();

    final NEATPopulation pop = ((NEATPopulation) target.getPopulation());

    // the link to split
    NEATLinkGene splitLink = null;

    final int sizeBias = ((NEATGenome)parents[0]).getInputCount()
        + ((NEATGenome)parents[0]).getOutputCount() + 10;

    // if there are not at least
    int upperLimit;
    if (target.getLinksChromosome().size() < sizeBias) {
      upperLimit = target.getNumGenes() - 1
          - (int) Math.sqrt(target.getNumGenes());
    } else {
      upperLimit = target.getNumGenes() - 1;
    }

    while ((countTrysToFindOldLink--) > 0) {
      // choose a link, use the square root to prefer the older links
      final int i = RangeRandomizer.randomInt(0, upperLimit);
      final NEATLinkGene link = target.getLinksChromosome().get(i);

      // get the from neuron
      final long fromNeuron = link.getFromNeuronID();

      if ((link.isEnabled())
          && (target.getNeuronsChromosome()
              .get(getElementPos(target, fromNeuron))
              .getNeuronType() != NEATNeuronType.Bias)) {
        splitLink = link;
        break;
View Full Code Here

      }
    }
   
    if( !mutated ) {
      int idx = rnd.nextInt(genome.getLinksChromosome().size());
      NEATLinkGene linkGene  = genome.getLinksChromosome().get(idx);
      result.add(linkGene)
    }
   
    return result;
  }
View Full Code Here

    final int cnt = Math.min(this.linkCount, genome.getLinksChromosome()
        .size());

    while (result.size() < cnt) {
      final int idx = rnd.nextInt(genome.getLinksChromosome().size());
      final NEATLinkGene link = genome.getLinksChromosome().get(idx);
      if (!result.contains(link)) {
        result.add(link);
      }
    }
    return result;
View Full Code Here

    final List<NEATLinkGene> selectedLinks = new ArrayList<NEATLinkGene>();
    final List<NEATNeuronGene> selectedNeurons = new ArrayList<NEATNeuronGene>();

    int curMom = 0; // current gene index from mom
    int curDad = 0; // current gene index from dad
    NEATLinkGene selectedGene = null;

    // add in the input and bias, they should always be here
    final int alwaysCount = ((NEATGenome)parents[0]).getInputCount()
        + ((NEATGenome)parents[0]).getOutputCount() + 1;
    for (int i = 0; i < alwaysCount; i++) {
      addNeuronID(i, selectedNeurons, best, notBest);
    }

    while ((curMom < mom.getNumGenes()) || (curDad < dad.getNumGenes())) {
      NEATLinkGene momGene = null; // the mom gene object
      NEATLinkGene dadGene = null; // the dad gene object
      long momInnovation = -1;
      long dadInnovation = -1;

      // grab the actual objects from mom and dad for the specified
      // indexes
      // if there are none, then null
      if (curMom < mom.getNumGenes()) {
        momGene = mom.getLinksChromosome().get(curMom);
        momInnovation = momGene.getInnovationId();
      }

      if (curDad < dad.getNumGenes()) {
        dadGene = dad.getLinksChromosome().get(curDad);
        dadInnovation = dadGene.getInnovationId();
      }

      // now select a gene for mom or dad. This gene is for the baby
      if ((momGene == null) && (dadGene != null)) {
        if (best == dad) {
View Full Code Here

    }

    // determine the target and remove
    final int index = RangeRandomizer.randomInt(0, target
        .getLinksChromosome().size() - 1);
    final NEATLinkGene targetGene = target.getLinksChromosome().get(index);
    target.getLinksChromosome().remove(index);

    // if this orphaned any nodes, then kill them too!
    if (!isNeuronNeeded(target, targetGene.getFromNeuronID())) {
      removeNeuron(target, targetGene.getFromNeuronID());
    }

    if (!isNeuronNeeded(target, targetGene.getToNeuronID())) {
      removeNeuron(target, targetGene.getToNeuronID());
    }
  }
View Full Code Here

            neuronGene
                .setInnovationId(Integer.parseInt(cols.get(4)));
            lastGenome.getNeuronsChromosome().add(neuronGene);
            nextGeneID = Math.max(geneID + 1, nextGeneID);
          } else if (cols.get(0).equalsIgnoreCase("l")) {
            final NEATLinkGene linkGene = new NEATLinkGene();
            linkGene.setId(Integer.parseInt(cols.get(1)));
            linkGene.setEnabled(Integer.parseInt(cols.get(2)) > 0);
            linkGene.setFromNeuronID(Integer.parseInt(cols.get(3)));
            linkGene.setToNeuronID(Integer.parseInt(cols.get(4)));
            linkGene.setWeight(CSVFormat.EG_FORMAT.parse(cols
                .get(5)));
            linkGene.setInnovationId(Integer.parseInt(cols.get(6)));
            lastGenome.getLinksChromosome().add(linkGene);
          }
        }

      } else if (section.getSectionName().equals("NEAT-POPULATION")
View Full Code Here

    final NEATInnovation innovation = ((NEATPopulation) target
        .getPopulation()).getInnovations().findInnovation(neuron1ID,
        neuron2ID);

    // now create this link
    final NEATLinkGene linkGene = new NEATLinkGene(neuron1ID, neuron2ID,
        true, innovation.getInnovationID(), weight);
    target.getLinksChromosome().add(linkGene);
  }
View Full Code Here

TOP

Related Classes of org.encog.neural.neat.training.NEATLinkGene

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.