Package org.encog.neural.neat

Examples of org.encog.neural.neat.NEATNetwork


    }
   
    links.add( new NEATLink(0,2,1.0));
    links.add( new NEATLink(1,2,2.0));
   
    NEATNetwork result = new NEATNetwork(1,1,links,activationFunctions);
       
    return result;
  }
View Full Code Here


    return result;
  }
 
  public void testPersistSerial() throws IOException, ClassNotFoundException
  {
    NEATNetwork network = create();
   
    SerializeObject.save(SERIAL_FILENAME, network);
    NEATNetwork network2 = (NEATNetwork)SerializeObject.load(SERIAL_FILENAME);
       
    validate(network2);
  }
View Full Code Here

   
    do {
      train.iteration();
    } while(train.getError() > 0.01 && train.getIteration()<10000);
    Encog.getInstance().shutdown();
    NEATNetwork network = (NEATNetwork)train.getCODEC().decode(train.getBestGenome());
   
    Assert.assertTrue(train.getError()<0.01);
    Assert.assertTrue(network.calculateError(buffer)<0.01);
  }
View Full Code Here

  public MLMethod decode(final NEATPopulation pop, final Substrate substrate,
      final Genome genome) {
    // obtain the CPPN
    final NEATCODEC neatCodec = new NEATCODEC();
    final NEATNetwork cppn = (NEATNetwork) neatCodec.decode(genome);

    final List<NEATLink> linkList = new ArrayList<NEATLink>();

    final ActivationFunction[] afs = new ActivationFunction[substrate
        .getNodeCount()];

    final ActivationFunction af = new ActivationSteepenedSigmoid();
    // all activation functions are the same
    for (int i = 0; i < afs.length; i++) {
      afs[i] = af;
    }

    final double c = this.maxWeight / (1.0 - this.minWeight);
    final MLData input = new BasicMLData(cppn.getInputCount());

    // First create all of the non-bias links.
    for (final SubstrateLink link : substrate.getLinks()) {
      final SubstrateNode source = link.getSource();
      final SubstrateNode target = link.getTarget();

      int index = 0;
      for (final double d : source.getLocation()) {
        input.setData(index++, d);
      }
      for (final double d : target.getLocation()) {
        input.setData(index++, d);
      }
      final MLData output = cppn.compute(input);

      double weight = output.getData(0);
      if (Math.abs(weight) > this.minWeight) {
        weight = (Math.abs(weight) - this.minWeight) * c
            * Math.signum(weight);
        linkList.add(new NEATLink(source.getId(), target.getId(),
            weight));
      }
    }

    // now create biased links
    input.clear();
    final int d = substrate.getDimensions();
    final List<SubstrateNode> biasedNodes = substrate.getBiasedNodes();
    for (final SubstrateNode target : biasedNodes) {
      for (int i = 0; i < d; i++) {
        input.setData(d + i, target.getLocation()[i]);
      }

      final MLData output = cppn.compute(input);

      double biasWeight = output.getData(1);
      if (Math.abs(biasWeight) > this.minWeight) {
        biasWeight = (Math.abs(biasWeight) - this.minWeight) * c
            * Math.signum(biasWeight);
        linkList.add(new NEATLink(0, target.getId(), biasWeight));
      }
    }

    // check for invalid neural network
    if (linkList.size() == 0) {
      return null;
    }

    Collections.sort(linkList);

    final NEATNetwork network = new NEATNetwork(substrate.getInputCount(),
        substrate.getOutputCount(), linkList, afs);

    network.setActivationCycles(substrate.getActivationCycles());
    return network;

  }
View Full Code Here

TOP

Related Classes of org.encog.neural.neat.NEATNetwork

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.