Examples of AIFHError


Examples of com.heatonresearch.aifh.AIFHError

    private void levelOff() {
        int total = 0;
        final List<Species> list = this.population.getSpecies();

        if (list.size() == 0) {
            throw new AIFHError(
                    "Can't speciate, next generation contains no species.");
        }

        Collections.sort(list, new SpeciesComparator(this.owner));
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

            // a species
            result.remove(s.getLeader());
        }

        if (this.population.getSpecies().size() == 0) {
            throw new AIFHError("Can't speciate, the population is empty.");
        }

        return result;
    }
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

     */
    private void speciateAndCalculateSpawnLevels(final List<Genome> genomes) {
        double maxScore = 0;

        if (genomes.size() == 0) {
            throw new AIFHError("Can't speciate, the population is empty.");
        }

        final List<Species> speciesCollection = this.population.getSpecies();

        if (speciesCollection.size() == 0) {
            throw new AIFHError("Can't speciate, there are no species.1");
        }

        // calculate compatibility between genomes and species
        adjustCompatibilityThreshold();

        // assign genomes to species (if any exist)
        for (final Genome genome : genomes) {
            Species currentSpecies = null;

            if (!Double.isNaN(genome.getAdjustedScore())
                    && !Double.isInfinite(genome.getAdjustedScore())) {
                maxScore = Math.max(genome.getAdjustedScore(), maxScore);
            }

            for (final Species s : speciesCollection) {
                final double compatibility = getCompatibilityScore(genome,
                        s.getLeader());

                if (compatibility <= this.compatibilityThreshold) {
                    currentSpecies = s;
                    addSpeciesMember(s, genome);
                    genome.setSpecies(s);
                    break;
                }
            }

            // if this genome did not fall into any existing species, create a
            // new species
            if (currentSpecies == null) {
                currentSpecies = new BasicSpecies(this.population, genome);
                this.population.getSpecies().add(currentSpecies);
            }
        }

        //
        double totalSpeciesScore = 0;
        for (final Species species : speciesCollection) {
            totalSpeciesScore += species.calculateShare(this.owner
                    .getScoreFunction().shouldMinimize(), maxScore);
        }

        if (speciesCollection.size() == 0) {
            throw new AIFHError("Can't speciate, there are no species.2");
        }
        if (totalSpeciesScore < AIFH.DEFAULT_PRECISION) {
            // This should not happen much, or if it does, only in the
            // beginning.
            // All species scored zero. So they are all equally bad. Just divide
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

                // don't readd the old best genome, it was already added
                if (genome != this.oldBestGenome) {

                    if (isValidationMode()) {
                        if (this.newPopulation.contains(genome)) {
                            throw new AIFHError(
                                    "Genome already added to population: "
                                            + genome.toString());
                        }
                    }
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

            this.taskExecutor.shutdown();
            try {
                this.taskExecutor.awaitTermination(Long.MAX_VALUE,
                        TimeUnit.MINUTES);
            } catch (final InterruptedException e) {
                throw new AIFHError(e);
            } finally {
                this.taskExecutor = null;
            }
        }
    }
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

        if (this.actualThreadCount == -1) {
            preIteration();
        }

        if (getPopulation().getSpecies().size() == 0) {
            throw new AIFHError("Population is empty, there are no species.");
        }

        this.iteration++;

        // Clear new population to just best genome.
        this.newPopulation.clear();
        this.newPopulation.add(this.bestGenome);
        this.oldBestGenome = this.bestGenome;

        // execute species in parallel
        this.threadList.clear();
        for (final Species species : getPopulation().getSpecies()) {
            int numToSpawn = species.getOffspringCount();

            // Add elite genomes directly
            if (species.getMembers().size() > 5) {
                final int idealEliteCount = (int) (species.getMembers().size() * getEliteRate());
                final int eliteCount = Math.min(numToSpawn, idealEliteCount);
                for (int i = 0; i < eliteCount; i++) {
                    final Genome eliteGenome = species.getMembers().get(i);
                    if (getOldBestGenome() != eliteGenome) {
                        numToSpawn--;
                        if (!addChild(eliteGenome)) {
                            break;
                        }
                    }
                }
            }

            // now add one task for each offspring that each species is allowed
            while (numToSpawn-- > 0) {
                final EAWorker worker = new EAWorker(this, species);
                this.threadList.add(worker);
            }
        }

        // run all threads and wait for them to finish
        try {
            this.taskExecutor.invokeAll(this.threadList);
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }

        // handle any errors that might have happened in the threads
        if (this.reportedError != null && !getShouldIgnoreExceptions()) {
            throw new AIFHError(this.reportedError);
        }

        // validate, if requested
        if (isValidationMode()) {
            if (this.oldBestGenome != null
                    && !this.newPopulation.contains(this.oldBestGenome)) {
                throw new AIFHError(
                        "The top genome died, this should never happen!!");
            }

            if (this.bestGenome != null
                    && this.oldBestGenome != null
                    && getBestComparator().isBetterThan(this.oldBestGenome,
                    this.bestGenome)) {
                throw new AIFHError(
                        "The best genome's score got worse, this should never happen!! Went from "
                                + this.oldBestGenome.getScore() + " to "
                                + this.bestGenome.getScore());
            }
        }
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

     * Update the species share of the next population.
     */
    private void updateShare() {
        final int speciesCount = this.owner.getPopulation().getSpecies().size();
        if (speciesCount != 1) {
            throw new AIFHError(
                    "SingleSpeciation can only be used with a species count of 1, species count is "
                            + speciesCount);
        }

        final Species species = this.owner.getPopulation().getSpecies().get(0);
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

                    }
                }
            } catch (AIFHError e) {
                tries--;
                if (tries < 0) {
                    throw new AIFHError(
                            "Could not perform a successful genetic operaton after "
                                    + this.train.getMaxOperationErrors()
                                    + " tries.");
                }
            } catch (final Throwable t) {
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

        final LUDecomposition lu = new LUDecomposition(new Matrix(hessian));

        if (lu.isNonsingular()) {
            deltas = lu.solve(gradient);
        } else {
            throw new AIFHError("Matrix Non singular");
        }

        final double[] prev = this.algorithm.getLongTermMemory().clone();

        for (int i = 0; i < this.algorithm.getLongTermMemory().length; i++)
View Full Code Here

Examples of com.heatonresearch.aifh.AIFHError

        if (genome1 instanceof DoubleArrayGenome) {
            return scoreDouble(genome1, genome2);
        } else if (genome1 instanceof IntegerArrayGenome) {
            return scoreInt(genome1, genome2);
        } else {
            throw new AIFHError("This speciation does not support: " + genome1.getClass().getName());
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.