Package com.heatonresearch.aifh.genetic.genome

Examples of com.heatonresearch.aifh.genetic.genome.DoubleArrayGenome


            parents[0].getData()[i - 1] = i;
        }

        // Create an array to hold the offspring.
        DoubleArrayGenome[] offspring = new DoubleArrayGenome[1];
        offspring[0] = new DoubleArrayGenome(5);

        // Perform the operation
        opp.performOperation(rnd, parents, 0, offspring, 0);

        // Display the results
View Full Code Here


        defaultSpecies.setPopulation(result);
        result.getSpecies().add(defaultSpecies);

        // Create a new population of random networks.
        for (int i = 0; i < POPULATION_SIZE; i++) {
            final DoubleArrayGenome genome = new DoubleArrayGenome(size);
            network.reset(rnd);
            System.arraycopy(network.getLongTermMemory(), 0, genome.getData(), 0, size);
            defaultSpecies.add(genome);
        }

        // Set the genome factory to use the double array genome.
        result.setGenomeFactory(new DoubleArrayGenomeFactory(size));
View Full Code Here

        defaultSpecies.setPopulation(result);
        result.getSpecies().add(defaultSpecies);

        // Create a new population of random networks.
        for (int i = 0; i < POPULATION_SIZE; i++) {
            final DoubleArrayGenome genome = new DoubleArrayGenome(size);
            network.reset(rnd);
            System.arraycopy(network.getLongTermMemory(), 0, genome.getData(), 0, size);
            defaultSpecies.add(genome);
        }

        // Set the genome factory to use the double array genome.
        result.setGenomeFactory(new DoubleArrayGenomeFactory(size));
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void performOperation(GenerateRandom rnd, Genome[] parents, int parentIndex,
                                 Genome[] offspring, int offspringIndex) {
        DoubleArrayGenome parent = (DoubleArrayGenome) parents[parentIndex];
        offspring[offspringIndex] = parent.getPopulation().getGenomeFactory().factor();
        DoubleArrayGenome child = (DoubleArrayGenome) offspring[offspringIndex];

        for (int i = 0; i < parent.size(); i++) {
            double value = parent.getData()[i];
            value += value * (perturbAmount - (rnd.nextDouble() * perturbAmount * 2));
            child.getData()[i] = value;
        }
    }
View Full Code Here

        }
        return Math.sqrt(sum);
    }

    private double scoreDouble(final Genome genome1, final Genome genome2) {
        DoubleArrayGenome doubleGenome1 = (DoubleArrayGenome) genome1;
        DoubleArrayGenome doubleGenome2 = (DoubleArrayGenome) genome2;
        double sum = 0;
        for (int i = 0; i < doubleGenome1.size(); i++) {
            double diff = doubleGenome1.getData()[i] - doubleGenome2.getData()[i];
            sum += diff * diff;
        }
        return Math.sqrt(sum);
    }
View Full Code Here

    /**
     * @return A random genome.
     */
    private DoubleArrayGenome randomGenome() {
        DoubleArrayGenome genome = new DoubleArrayGenome(PlantUniverse.GENOME_SIZE);

        for (int i = 0; i < genome.size(); i++) {
            genome.getData()[i] = rnd.nextDouble(0, 1);
        }
        return genome;
    }
View Full Code Here

        Population result = new BasicPopulation(PlantUniverse.POPULATION_SIZE, null);

        BasicSpecies defaultSpecies = new BasicSpecies();
        defaultSpecies.setPopulation(result);
        for (int i = 0; i < PlantUniverse.POPULATION_SIZE; i++) {
            final DoubleArrayGenome genome = randomGenome();
            defaultSpecies.add(genome);
        }
        result.setGenomeFactory(new DoubleArrayGenomeFactory(PlantUniverse.GENOME_SIZE));
        result.getSpecies().add(defaultSpecies);
View Full Code Here

        this.universe = new PlantUniverse();
        this.universe.reset();


        DoubleArrayGenome bestGenome = (DoubleArrayGenome) genetic.getBestGenome();
        PlantPhysics physics = new PlantPhysics();
        PlantGrowth growth = new PlantGrowth();

        for (int i = 0; i < 100; i++) {
            physics.runPhysics(universe);
            growth.runGrowth(universe, bestGenome.getData());
        }

        this.display = new DisplayPlant();
        this.display.setUniverse(this.universe);
        this.getContentPane().add(this.display);
View Full Code Here

            generation++;
            this.genetic.iteration();

            this.universe.reset();

            DoubleArrayGenome bestGenome = (DoubleArrayGenome) this.genetic.getBestGenome();
            PlantGrowth growth = new PlantGrowth();
            PlantPhysics physics = new PlantPhysics();

            for (int i = 0; i < PlantUniverse.EVALUATION_CYCLES; i++) {
                physics.runPhysics(universe);
                growth.runGrowth(universe, bestGenome.getData());
            }

            this.display.setGeneration(generation);
            this.display.setBestScore(this.genetic.getBestGenome().getScore());
            this.display.repaint();

            System.out.println(Arrays.toString(bestGenome.getLongTermMemory()));

        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public double calculateScore(final MLMethod algo) {
        DoubleArrayGenome genome = (DoubleArrayGenome) algo;
        PlantUniverse universe = new PlantUniverse();
        universe.reset();
        PlantPhysics physics = new PlantPhysics();
        PlantGrowth growth = new PlantGrowth();

        // Run the generations.
        for (int i = 0; i < PlantUniverse.EVALUATION_CYCLES; i++) {
            physics.runPhysics(universe);
            growth.runGrowth(universe, genome.getData());
        }

        // Count the amount of green.
        int count = 0;
        double sum = 0;
View Full Code Here

TOP

Related Classes of com.heatonresearch.aifh.genetic.genome.DoubleArrayGenome

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.