Examples of NEATPopulation


Examples of org.encog.neural.neat.NEATPopulation

  public void testPersistEG()
  {
    Population pop = generate();

    EncogDirectoryPersistence.saveObject((EG_FILENAME), pop);
    NEATPopulation pop2 = (NEATPopulation)EncogDirectoryPersistence.loadObject((EG_FILENAME));
   
    validate(pop2);
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

    validate(pop2);
  }
 
  public void testPersistSerial() throws IOException, ClassNotFoundException
  {
    NEATPopulation pop = generate();
   
    SerializeObject.save(SERIAL_FILENAME, pop);
    NEATPopulation pop2 = (NEATPopulation)SerializeObject.load(SERIAL_FILENAME);
   
    validate(pop2);
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

    this.inputCount = inputCount;
    this.outputCount = outputCount;

    setCalculateScore(new GeneticScoreAdapter(calculateScore));
    setComparator(new GenomeComparator(getCalculateScore()));
    setPopulation(new NEATPopulation(inputCount, outputCount,
        populationSize));

    init();
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

  /**
   * Convert the genes to an actual network.
   */
  public void decode() {

    NEATPopulation pop = (NEATPopulation)this.getPopulation();
   
    final List<NEATNeuron> neurons = new ArrayList<NEATNeuron>();

    for (final Gene gene : getNeurons().getGenes()) {
      final NEATNeuronGene neuronGene = (NEATNeuronGene) gene;
      final NEATNeuron neuron = new NEATNeuron(
          neuronGene.getNeuronType(), neuronGene.getId(), neuronGene
              .getSplitY(), neuronGene.getSplitX(), neuronGene
              .getActivationResponse());

      neurons.add(neuron);
    }

    // now to create the links.
    for (final Gene gene : getLinks().getGenes()) {
      final NEATLinkGene linkGene = (NEATLinkGene) gene;
      if (linkGene.isEnabled()) {
        int element = getElementPos(linkGene.getFromNeuronID());
        final NEATNeuron fromNeuron = neurons.get(element);

        element = getElementPos(linkGene.getToNeuronID());
        if( element==-1 ) {
          System.out.println("test");
        }
        final NEATNeuron toNeuron = neurons.get(element);

        final NEATLink link = new NEATLink(linkGene.getWeight(),
            fromNeuron, toNeuron, linkGene.isRecurrent());

        fromNeuron.getOutputboundLinks().add(link);
        toNeuron.getInboundLinks().add(link);

      }
    }

    NEATNetwork network = new NEATNetwork(inputCount,
        outputCount,
        neurons,
        pop.getNeatActivationFunction(),
        pop.getOutputActivationFunction(),
        0);
   
   
    network.setSnapshot(pop.isSnapshot());   
    setOrganism(network);   
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

  public static double XOR_IDEAL[][] = { { 0.0 }, { 1.0 }, { 1.0 }, { 0.0 } };

  public static void main(final String args[]) {

    MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
    NEATPopulation pop = new NEATPopulation(2,1,1000);
    CalculateScore score = new TrainingSetScore(trainingSet);
    // train the neural network
    ActivationStep step = new ActivationStep();
    step.setCenter(0.5);
    pop.setOutputActivationFunction(step);
   
    final NEATTraining train = new NEATTraining(score,pop);
   
    EncogUtility.trainToError(train, 0.01);
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

  private void performTrain() {
    InputNEAT dialog = new InputNEAT();
    if (dialog.process()) {
      ProjectEGFile popFile = dialog.getPopulation();
      NEATPopulation pop = (NEATPopulation) popFile.getObject();

      pop.setInputCount(2);
      pop.setOutputCount(1);
      MLDataSet training = dialog.getTrainingSet();

      if (dialog.getLoadToMemory().getValue()) {
        training = ((BufferedNeuralDataSet) training).loadToMemory();
      }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

    if (dialog.process()) {
      int populationSize = dialog.getPopulationSize().getValue();
      int inputCount = dialog.getInputNeurons().getValue();
      int outputCount = dialog.getOutputNeurons().getValue();
      boolean snapshot = dialog.getSnapshot().getValue();
      NEATPopulation pop = new NEATPopulation(inputCount,outputCount,populationSize);
      pop.setSnapshot(snapshot);
      pop.setNeatActivationFunction(dialog.getNeatActivationFunction());
      pop.setOutputActivationFunction(dialog.getOutputActivationFunction());
      EncogWorkBench.getInstance().save(path,pop);
      EncogWorkBench.getInstance().refresh();
    }
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

  public static double XOR_IDEAL[][] = { { 0.0 }, { 1.0 }, { 1.0 }, { 0.0 } };

  public static void main(final String args[]) {

    MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
    NEATPopulation pop = new NEATPopulation(2,1,1000);
    pop.setInitialConnectionDensity(1.0);// not required, but speeds training
    pop.reset();

    CalculateScore score = new TrainingSetScore(trainingSet);
    // train the neural network
   
    final EvolutionaryAlgorithm train = NEATUtil.constructNEATTrainer(pop,score);
   
    do {
      train.iteration();
      System.out.println("Epoch #" + train.getIteration() + " Error:" + train.getError()+ ", Species:" + pop.getSpecies().size());
    } while(train.getError() > 0.01);

    NEATNetwork network = (NEATNetwork)train.getCODEC().decode(train.getBestGenome());

    // test the neural network
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

        MLMethodFactory.PROPERTY_CYCLES, false, NEATPopulation.DEFAULT_CYCLES);
   
    ActivationFunction af = this.factory.create(
        holder.getString(MLMethodFactory.PROPERTY_AF, false, MLActivationFactory.AF_SSIGMOID));

    NEATPopulation pop = new NEATPopulation(input,output,populationSize);
    pop.reset();
    pop.setActivationCycles(cycles);
    pop.setNEATActivationFunction(af);

    return pop;
  }
View Full Code Here

Examples of org.encog.neural.neat.NEATPopulation

      final int offspringIndex) {
    final NEATGenome target = obtainGenome(parents, parentIndex, offspring,
        offspringIndex);
    int countTrysToFindOldLink = getOwner().getMaxTries();

    final NEATPopulation pop = ((NEATPopulation) target.getPopulation());

    // the link to split
    NEATLinkGene splitLink = null;

    final int sizeBias = ((NEATGenome)parents[0]).getInputCount()
        + ((NEATGenome)parents[0]).getOutputCount() + 10;

    // if there are not at least
    int upperLimit;
    if (target.getLinksChromosome().size() < sizeBias) {
      upperLimit = target.getNumGenes() - 1
          - (int) Math.sqrt(target.getNumGenes());
    } else {
      upperLimit = target.getNumGenes() - 1;
    }

    while ((countTrysToFindOldLink--) > 0) {
      // choose a link, use the square root to prefer the older links
      final int i = RangeRandomizer.randomInt(0, upperLimit);
      final NEATLinkGene link = target.getLinksChromosome().get(i);

      // get the from neuron
      final long fromNeuron = link.getFromNeuronID();

      if ((link.isEnabled())
          && (target.getNeuronsChromosome()
              .get(getElementPos(target, fromNeuron))
              .getNeuronType() != NEATNeuronType.Bias)) {
        splitLink = link;
        break;
      }
    }

    if (splitLink == null) {
      return;
    }

    splitLink.setEnabled(false);

    final long from = splitLink.getFromNeuronID();
    final long to = splitLink.getToNeuronID();

    final NEATInnovation innovation = ((NEATPopulation)getOwner().getPopulation()).getInnovations()
        .findInnovationSplit(from, to);

    // add the splitting neuron
    final ActivationFunction af = ((NEATPopulation)getOwner().getPopulation())
        .getActivationFunctions().pick(new Random());

    target.getNeuronsChromosome().add(
        new NEATNeuronGene(NEATNeuronType.Hidden, af, innovation
            .getNeuronID(), innovation.getInnovationID()));

    // add the other two sides of the link
    createLink(target, from, innovation.getNeuronID(),
        splitLink.getWeight());
    createLink(target, innovation.getNeuronID(), to, pop.getWeightRange());
   
    target.sortGenes();
  }
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.