Package org.encog.neural.neat.training

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


    return this.population.getGenomes().size();
  }

  public Object getValueAt(int rowIndex, int columnIndex) {
   
    NEATGenome genome = (NEATGenome)this.population.getGenomes().get(rowIndex);
   
    switch(columnIndex)
    {
      case 0:
        return Format.formatInteger((int)genome.getGenomeID());
      case 1:
        return Format.formatInteger(genome.getNeurons().size());
      case 2:
        return Format.formatInteger(genome.getLinks().size());
      case 3:
        return Format.formatDouble(genome.getAmountToSpawn(),2);
      case 4:
        return Format.formatDouble(genome.getScore(),4);
      default:
        return "";
    }
  }
View Full Code Here


          "Population must have more than zero genomes.");
    }

    // create the initial population
    for (int i = 0; i < populationSize; i++) {
      NEATGenome genome = new NEATGenome(assignGenomeID(), inputCount,
          outputCount);
      add(genome);
    }

    // create initial innovations
    NEATGenome genome = (NEATGenome) this.getGenomes().get(0);
    this.setInnovations(new NEATInnovationList(this, genome.getLinks(),
        genome.getNeurons()));

  }
View Full Code Here

          result.getSpecies().add(species);
          speciesMap.put((int) species.getSpeciesID(), species);
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("GENOMES")) {
        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)));
            lastGenome.setSpeciesID(Integer.parseInt(cols.get(2)));
            lastGenome.setAdjustedScore(CSVFormat.EG_FORMAT
                .parse(cols.get(3)));
            lastGenome.setAmountToSpawn(CSVFormat.EG_FORMAT
                .parse(cols.get(4)));
            lastGenome.setNetworkDepth(Integer.parseInt(cols.get(5)));
            lastGenome.setScore(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            result.add(lastGenome);
            genomeMap.put((int) lastGenome.getGenomeID(),
                lastGenome);
          } else if (cols.get(0).equalsIgnoreCase("n") ) {
            NEATNeuronGene neuronGene = new NEATNeuronGene();
            neuronGene.setId(Integer.parseInt(cols.get(1)));
            neuronGene.setNeuronType(PersistNEATPopulation
                .stringToNeuronType(cols.get(2)));
            neuronGene.setEnabled(Integer.parseInt(cols.get(3))>0);
            neuronGene.setInnovationId(Integer.parseInt(cols.get(4)));
            neuronGene.setActivationResponse(CSVFormat.EG_FORMAT
                .parse(cols.get(5)));
            neuronGene
                .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")) {
        Map<String, String> params = section.parseParams();
       
        result.setNeatActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_NEAT_ACTIVATION));
        result.setOutputActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_OUTPUT_ACTIVATION));
        result.setSnapshot(EncogFileSection.parseBoolean(params, PersistConst.SNAPSHOT));
        result.setInputCount(EncogFileSection.parseInt(params,
            PersistConst.INPUT_COUNT));
        result.setOutputCount(EncogFileSection.parseInt(params,
            PersistConst.OUTPUT_COUNT));
        result.setOldAgePenalty(EncogFileSection.parseDouble(params,
            NEATPopulation.PROPERTY_OLD_AGE_PENALTY));
        result.setOldAgeThreshold(EncogFileSection.parseInt(params,
            NEATPopulation.PROPERTY_OLD_AGE_THRESHOLD));
        result.setPopulationSize(EncogFileSection.parseInt(params,
            NEATPopulation.PROPERTY_POPULATION_SIZE));
        result.setSurvivalRate(EncogFileSection.parseDouble(params,
            NEATPopulation.PROPERTY_SURVIVAL_RATE));
        result.setYoungBonusAgeThreshhold(EncogFileSection.parseInt(
            params, NEATPopulation.PROPERTY_YOUNG_AGE_THRESHOLD));
        result.setYoungScoreBonus(EncogFileSection.parseDouble(params,
            NEATPopulation.PROPERTY_YOUNG_AGE_BONUS));
        result.getGenomeIDGenerate().setCurrentID(
            EncogFileSection.parseInt(params,
                NEATPopulation.PROPERTY_NEXT_GENOME_ID));
        result.getInnovationIDGenerate().setCurrentID(
            EncogFileSection.parseInt(params,
                NEATPopulation.PROPERTY_NEXT_INNOVATION_ID));
        result.getGeneIDGenerate().setCurrentID(
            EncogFileSection.parseInt(params,
                NEATPopulation.PROPERTY_NEXT_GENE_ID));
        result.getSpeciesIDGenerate().setCurrentID(
            EncogFileSection.parseInt(params,
                NEATPopulation.PROPERTY_NEXT_SPECIES_ID));
      }
    }

    // now link everything up

    // first put all the genomes into correct species
    for (Genome genome : result.getGenomes()) {
      NEATGenome neatGenome = (NEATGenome) genome;
      int speciesId = (int) neatGenome.getSpeciesID();
      Species species = speciesMap.get(speciesId);
      if (species != null) {
        species.getMembers().add(neatGenome);
      }
      neatGenome.setInputCount(result.getInputCount());
      neatGenome.setOutputCount(result.getOutputCount());
    }

    // set the species leader links
    for (Species species : leaderMap.keySet()) {
      int leaderID = leaderMap.get(species);
View Full Code Here

        out.writeLine();
      }
    }
    out.addSubSection("GENOMES");
    for (Genome genome : pop.getGenomes()) {
      NEATGenome neatGenome = (NEATGenome) genome;
      out.addColumn("g");
      out.addColumn(neatGenome.getGenomeID());
      out.addColumn(neatGenome.getSpeciesID());
      out.addColumn(neatGenome.getAdjustedScore());
      out.addColumn(neatGenome.getAmountToSpawn());
      out.addColumn(neatGenome.getNetworkDepth());
      out.addColumn(neatGenome.getScore());
      out.writeLine();

      for (Gene neuronGene : neatGenome.getNeurons().getGenes()) {
        NEATNeuronGene neatNeuronGene = (NEATNeuronGene) neuronGene;
        out.addColumn("n");
        out.addColumn(neatNeuronGene.getId());
        out.addColumn(PersistNEATPopulation
            .neuronTypeToString(neatNeuronGene.getNeuronType()));
        out.addColumn(neatNeuronGene.isEnabled());
        out.addColumn(neatNeuronGene.getInnovationId());
        out.addColumn(neatNeuronGene.getActivationResponse());
        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());
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public NEATGenome factor() {
    return new NEATGenome();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Genome factor(final Genome other) {
    return new NEATGenome((NEATGenome) other);
  }
View Full Code Here

   */
  @Override
  public NEATGenome factor(final List<NEATNeuronGene> neurons,
      final List<NEATLinkGene> links, final int inputCount,
      final int outputCount) {
    return new NEATGenome(neurons, links, inputCount, outputCount);
  }
View Full Code Here

   */
  @Override
  public NEATGenome factor(final Random rnd, final NEATPopulation pop,
      final int inputCount, final int outputCount,
      final double connectionDensity) {
    return new NEATGenome(rnd, pop, inputCount, outputCount,
        connectionDensity);
  }
View Full Code Here

    final BasicSpecies defaultSpecies = new BasicSpecies();
    defaultSpecies.setPopulation(this);

    // create the initial population
    for (int i = 0; i < getPopulationSize(); i++) {
      final NEATGenome genome = getGenomeFactory().factor(rnd, this,
          this.inputCount, this.outputCount,
          this.initialConnectionDensity);
      defaultSpecies.add(genome);
    }
    defaultSpecies.setLeader(defaultSpecies.getMembers().get(0));
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public MLMethod decode(final Genome genome) {
    final NEATGenome neatGenome = (NEATGenome) genome;
    final NEATPopulation pop = (NEATPopulation) neatGenome.getPopulation();
    final List<NEATNeuronGene> neuronsChromosome = neatGenome
        .getNeuronsChromosome();
    final List<NEATLinkGene> linksChromosome = neatGenome
        .getLinksChromosome();

    if (neuronsChromosome.get(0).getNeuronType() != NEATNeuronType.Bias) {
      throw new NeuralNetworkError(
          "The first neuron must be the bias neuron, this genome is invalid.");
    }

    final List<NEATLink> links = new ArrayList<NEATLink>();
    final ActivationFunction[] afs = new ActivationFunction[neuronsChromosome
        .size()];

    for (int i = 0; i < afs.length; i++) {
      afs[i] = neuronsChromosome.get(i).getActivationFunction();
    }

    final Map<Long, Integer> lookup = new HashMap<Long, Integer>();
    for (int i = 0; i < neuronsChromosome.size(); i++) {
      final NEATNeuronGene neuronGene = neuronsChromosome.get(i);
      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()));
      }

    }

    Collections.sort(links);

    final NEATNetwork network = new NEATNetwork(neatGenome.getInputCount(),
        neatGenome.getOutputCount(), links, afs);

    network.setActivationCycles(pop.getActivationCycles());
    return network;
  }
View Full Code Here

TOP

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

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.