Package org.encog.ml.genetic.species

Examples of org.encog.ml.genetic.species.BasicSpecies


      // if this genome did not fall into any existing species, create a
      // new species
      if (!added) {
        getPopulation().getSpecies().add(
            new BasicSpecies(getPopulation(), genome,
                getPopulation().assignSpeciesID()));
      }
    }

    adjustSpeciesScore();
View Full Code Here


        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("SPECIES")) {
        for (String line : section.getLines()) {
          String[] cols = line.split(",");
          BasicSpecies species = new BasicSpecies();

          species.setSpeciesID(Integer.parseInt(cols[0]));
          species.setAge(Integer.parseInt(cols[1]));
          species.setBestScore(CSVFormat.EG_FORMAT.parse(cols[2]));
          species.setGensNoImprovement(Integer.parseInt(cols[3]));
          species.setSpawnsRequired(CSVFormat.EG_FORMAT
              .parse(cols[4]));
          species.setSpawnsRequired(CSVFormat.EG_FORMAT
              .parse(cols[5]));
          leaderMap.put(species, Integer.parseInt(cols[6]));
          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);
      Genome leader = genomeMap.get(leaderID);
      species.setLeader(leader);
      ((BasicSpecies)species).setPopulation(result);
    }

    return result;
  }
View Full Code Here

TOP

Related Classes of org.encog.ml.genetic.species.BasicSpecies

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.