Package com.heatonresearch.aifh.evolutionary.species

Examples of com.heatonresearch.aifh.evolutionary.species.Species


    /**
     * {@inheritDoc}
     */
    @Override
    public Species createSpecies() {
        final Species species = new BasicSpecies();
        species.setPopulation(this);
        getSpecies().add(species);
        return species;
    }
View Full Code Here


     */
    public void purgeInvalidGenomes() {
        // remove any invalid genomes
        int speciesNum = 0;
        while (speciesNum < getSpecies().size()) {
            Species species = getSpecies().get(speciesNum);

            int genomeNum = 0;
            while (genomeNum < species.getMembers().size()) {
                Genome genome = species.getMembers().get(genomeNum);
                if (Double.isInfinite(genome.getScore())
                        || Double.isInfinite(genome.getAdjustedScore())
                        || Double.isNaN(genome.getScore())
                        || Double.isNaN(genome.getAdjustedScore())) {
                    species.getMembers().remove(genome);
                } else {
                    genomeNum++;
                }
            }

            // is the species now empty?
            if (species.getMembers().size() == 0) {
                getSpecies().remove(species);
            } else {
                // new leader needed?
                if (!species.getMembers().contains(species.getLeader())) {
                    species.setLeader(species.getMembers().get(0));
                    species.setBestScore(species.getLeader().getScore());
                }

                // onto the next one!
                speciesNum++;
            }
View Full Code Here

public class TournamentCompareExample {
    public static void main(String[] args) {

        // Create a new population.
        Population pop = new BasicPopulation();
        Species species = pop.createSpecies();

        // Create 1000 genomes, assign the score to be the index number.
        for (int i = 0; i < 1000; i++) {
            Genome genome = new IntegerArrayGenome(1);
            genome.setScore(i);
            genome.setAdjustedScore(i);
            pop.getSpecies().get(0).add(genome);
        }

        GenerateRandom rnd = new MersenneTwisterGenerateRandom();

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        // We only care that we are maximizing.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }

            @Override
            public boolean shouldMinimize() {
                return false;
            }
        });

        // Perform the test for round counts between 1 and 10.
        for (int roundCount = 1; roundCount <= 10; roundCount++) {
            TournamentSelection selection = new TournamentSelection(train, roundCount);
            int sum = 0;
            int count = 0;
            for (int i = 0; i < 100000; i++) {
                int genomeID = selection.performSelection(rnd, species);
                Genome genome = species.getMembers().get(genomeID);
                sum += genome.getAdjustedScore();
                count++;
            }
            sum /= count;
            System.out.println("Rounds: " + roundCount + ", Avg Score: " + sum);
View Full Code Here

TOP

Related Classes of com.heatonresearch.aifh.evolutionary.species.Species

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.