Package org.encog.persist

Examples of org.encog.persist.EncogFileSection


   */
  @Override
  public final Object read(final InputStream is) {
    final TrainingContinuation result = new TrainingContinuation();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("CONT")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        for (final String key : params.keySet()) {
          if (key.equalsIgnoreCase("type")) {
            result.setTrainingType(params.get(key));
          } else {
            final double[] list = EncogFileSection
View Full Code Here


  @Override
  public final Object read(final InputStream is) {
    final BasicNetwork result = new BasicNetwork();
    final FlatNetwork flat = new FlatNetwork();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("BASIC")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("BASIC")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();

        flat.setBeginTraining(EncogFileSection.parseInt(params,
            BasicNetwork.TAG_BEGIN_TRAINING));
        flat.setConnectionLimit(EncogFileSection.parseDouble(params,
            BasicNetwork.TAG_CONNECTION_LIMIT));
        flat.setContextTargetOffset(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_CONTEXT_TARGET_OFFSET));
        flat.setContextTargetSize(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_CONTEXT_TARGET_SIZE));
        flat.setEndTraining(EncogFileSection.parseInt(params,
            BasicNetwork.TAG_END_TRAINING));
        flat.setHasContext(EncogFileSection.parseBoolean(params,
            BasicNetwork.TAG_HAS_CONTEXT));
        flat.setInputCount(EncogFileSection.parseInt(params,
            PersistConst.INPUT_COUNT));
        flat.setLayerCounts(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_COUNTS));
        flat.setLayerFeedCounts(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_FEED_COUNTS));
        flat.setLayerContextCount(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_LAYER_CONTEXT_COUNT));
        flat.setLayerIndex(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_INDEX));
        flat.setLayerOutput(EncogFileSection.parseDoubleArray(params,
            PersistConst.OUTPUT));
        flat.setLayerSums(new double[flat.getLayerOutput().length]);
        flat.setOutputCount(EncogFileSection.parseInt(params,
            PersistConst.OUTPUT_COUNT));
        flat.setWeightIndex(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_WEIGHT_INDEX));
        flat.setWeights(EncogFileSection.parseDoubleArray(params,
            PersistConst.WEIGHTS));
        flat.setBiasActivation(EncogFileSection.parseDoubleArray(
            params, BasicNetwork.TAG_BIAS_ACTIVATION));
      } else if (section.getSectionName().equals("BASIC")
          && section.getSubSectionName().equals("ACTIVATION")) {
        int index = 0;

        flat.setActivationFunctions(new ActivationFunction[flat
            .getLayerCounts().length]);

        for (final String line : section.getLines()) {
          ActivationFunction af = null;
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          final String name = "org.encog.engine.network.activation."
              + cols.get(0);
View Full Code Here

   */
  @Override
  public final Object read(final InputStream is) {
    Map<String, String> networkParams = null;
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;
    int inputCount = 0;
    int instarCount = 0;
    int outputCount = 0;
    int winnerCount = 0;
    Matrix m1 = null;
    Matrix m2 = null;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("CPN")
          && section.getSubSectionName().equals("PARAMS")) {
        networkParams = section.parseParams();
      }
      if (section.getSectionName().equals("CPN")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();

        inputCount = EncogFileSection.parseInt(params,
            PersistConst.INPUT_COUNT);
        instarCount = EncogFileSection.parseInt(params,
            PersistConst.INSTAR);
View Full Code Here

  @Override
  public Object read(InputStream is) {
    NEATNetwork result = new NEATNetwork()
    EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;
    Map<Integer,NEATNeuron> neuronMap = new HashMap<Integer,NEATNeuron>();
   
    while( (section = in.readNextSection()) != null ) {
      if( section.getSectionName().equals("NEAT") && section.getSubSectionName().equals("PARAMS") ) {
        Map<String,String> params = section.parseParams();
        result.getProperties().putAll(params);
      } if( section.getSectionName().equals("NEAT") && section.getSubSectionName().equals("NETWORK") ) {
        Map<String,String> params = section.parseParams();
       
        result.setInputCount( EncogFileSection.parseInt(params,PersistConst.INPUT_COUNT));
        result.setOutputCount( EncogFileSection.parseInt(params,PersistConst.OUTPUT_COUNT));
        result.setActivationFunction( EncogFileSection.parseActivationFunction(params,PersistConst.ACTIVATION_FUNCTION));
        result.setOutputActivationFunction( EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_OUTPUT_ACTIVATION));
        result.setNetworkDepth( EncogFileSection.parseInt(params,PersistConst.DEPTH));
        result.setSnapshot( EncogFileSection.parseBoolean(params, PersistConst.SNAPSHOT));
      } else if( section.getSectionName().equals("NEAT") && section.getSubSectionName().equals("NEURONS") ) {
        for (String line : section.getLines()) {
          List<String> cols = EncogFileSection.splitColumns(line);

          final long neuronID = Integer.parseInt(cols.get(0));
          final NEATNeuronType neuronType = PersistNEATPopulation.stringToNeuronType(cols.get(1));
          final double activationResponse = CSVFormat.EG_FORMAT.parse(cols.get(2));
          final double splitY = CSVFormat.EG_FORMAT.parse(cols.get(3));
          final double splitX = CSVFormat.EG_FORMAT.parse(cols.get(4));
         
          NEATNeuron neatNeuron = new NEATNeuron(neuronType, neuronID,
            splitY,splitX,activationResponse);
          result.getNeurons().add(neatNeuron);
          neuronMap.put((int)neuronID, neatNeuron);
        }       
      } else if( section.getSectionName().equals("NEAT") && section.getSubSectionName().equals("LINKS") ) {
        for (String line : section.getLines()) {
          List<String> cols = EncogFileSection.splitColumns(line);
          int fromID = Integer.parseInt(cols.get(0));
          int toID = Integer.parseInt(cols.get(1));
          boolean recurrent = Integer.parseInt(cols.get(2))>0;
          double weight = CSVFormat.EG_FORMAT.parse(cols.get(3));
View Full Code Here

   */
  @Override
  public final Object read(final InputStream is) {
    final HopfieldNetwork result = new HopfieldNetwork();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("HOPFIELD")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("HOPFIELD")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();
        result.setWeights(NumberList.fromList(CSVFormat.EG_FORMAT,
            params.get(PersistConst.WEIGHTS)));
        result.setCurrentState(NumberList.fromList(CSVFormat.EG_FORMAT,
            params.get(PersistConst.OUTPUT)));
        result.setNeuronCount(EncogFileSection.parseInt(params,
View Full Code Here

   */
  @Override
  public final Object read(final InputStream is) {
    final BAM result = new BAM();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("BAM")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("BAM")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();

        result.setF1Count(EncogFileSection.parseInt(params,
            PersistConst.PROPERTY_F1_COUNT));
        result.setF2Count(EncogFileSection.parseInt(params,
            PersistConst.PROPERTY_F2_COUNT));
View Full Code Here

   */
  @Override
  public final Object read(final InputStream is) {
    final BoltzmannMachine result = new BoltzmannMachine();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("BOLTZMANN")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("BOLTZMANN")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();
        result.setWeights(NumberList.fromList(CSVFormat.EG_FORMAT,
            params.get(PersistConst.WEIGHTS)));
        result.setCurrentState(NumberList.fromList(CSVFormat.EG_FORMAT,
            params.get(PersistConst.OUTPUT)));
        result.setNeuronCount(EncogFileSection.parseInt(params,
View Full Code Here

   */
  @Override
  public final Object read(final InputStream is) {
    final ART1 result = new ART1();
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("ART1")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("ART1")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();

        result.setA1(EncogFileSection.parseDouble(params,
            ART.PROPERTY_A1));
        result.setB1(EncogFileSection.parseDouble(params,
            ART.PROPERTY_B1));
View Full Code Here

  public final Object read(final InputStream is) {
    final RBFNetwork result = new RBFNetwork();
    final FlatNetworkRBF flat = (FlatNetworkRBF) result.getFlat();

    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("RBF-NETWORK")
          && section.getSubSectionName().equals("PARAMS")) {
        final Map<String, String> params = section.parseParams();
        result.getProperties().putAll(params);
      }
      if (section.getSectionName().equals("RBF-NETWORK")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();

        flat.setBeginTraining(EncogFileSection.parseInt(params,
            BasicNetwork.TAG_BEGIN_TRAINING));
        flat.setConnectionLimit(EncogFileSection.parseDouble(params,
            BasicNetwork.TAG_CONNECTION_LIMIT));
        flat.setContextTargetOffset(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_CONTEXT_TARGET_OFFSET));
        flat.setContextTargetSize(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_CONTEXT_TARGET_SIZE));
        flat.setEndTraining(EncogFileSection.parseInt(params,
            BasicNetwork.TAG_END_TRAINING));
        flat.setHasContext(EncogFileSection.parseBoolean(params,
            BasicNetwork.TAG_HAS_CONTEXT));
        flat.setInputCount(EncogFileSection.parseInt(params,
            PersistConst.INPUT_COUNT));
        flat.setLayerCounts(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_COUNTS));
        flat.setLayerFeedCounts(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_FEED_COUNTS));
        flat.setLayerContextCount(EncogFileSection.parseIntArray(
            params, BasicNetwork.TAG_LAYER_CONTEXT_COUNT));
        flat.setLayerIndex(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_LAYER_INDEX));
        flat.setLayerOutput(EncogFileSection.parseDoubleArray(params,
            PersistConst.OUTPUT));
        flat.setLayerSums(new double[flat.getLayerOutput().length]);
        flat.setOutputCount(EncogFileSection.parseInt(params,
            PersistConst.OUTPUT_COUNT));
        flat.setWeightIndex(EncogFileSection.parseIntArray(params,
            BasicNetwork.TAG_WEIGHT_INDEX));
        flat.setWeights(EncogFileSection.parseDoubleArray(params,
            PersistConst.WEIGHTS));
        flat.setBiasActivation(EncogFileSection.parseDoubleArray(
            params, BasicNetwork.TAG_BIAS_ACTIVATION));
      } else if (section.getSectionName().equals("RBF-NETWORK")
          && section.getSubSectionName().equals("ACTIVATION")) {
        int index = 0;

        flat.setActivationFunctions(new ActivationFunction[flat
            .getLayerCounts().length]);

        for (final String line : section.getLines()) {
          ActivationFunction af = null;
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          final String name = "org.encog.engine.network.activation."
              + cols.get(0);
          try {
            final Class<?> clazz = Class.forName(name);
            af = (ActivationFunction) clazz.newInstance();
          } catch (final ClassNotFoundException e) {
            throw new PersistError(e);
          } catch (final InstantiationException e) {
            throw new PersistError(e);
          } catch (final IllegalAccessException e) {
            throw new PersistError(e);
          }

          for (int i = 0; i < af.getParamNames().length; i++) {
            af.setParam(i,
                CSVFormat.EG_FORMAT.parse(cols.get(i + 1)));
          }

          flat.getActivationFunctions()[index++] = af;
        }

      } else if (section.getSectionName().equals("RBF-NETWORK")
          && section.getSubSectionName().equals("RBF")) {
        int index = 0;

        final int hiddenCount = flat.getLayerCounts()[1];
        final int inputCount = flat.getLayerCounts()[2];

        flat.setRBF(new RadialBasisFunction[hiddenCount]);

        for (final String line : section.getLines()) {
          RadialBasisFunction rbf = null;
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          final String name = "org.encog.mathutil.rbf." + cols.get(0);
          try {
View Full Code Here

    result.setInnovations(innovationList);
    EncogReadHelper in = new EncogReadHelper(is);
    Map<Integer, Species> speciesMap = new HashMap<Integer, Species>();
    Map<Species, Integer> leaderMap = new HashMap<Species, Integer>();
    Map<Integer, Genome> genomeMap = new HashMap<Integer, Genome>();
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("INNOVATIONS")) {
        for (String line : section.getLines()) {
          List<String> cols = EncogFileSection.splitColumns(line);
          NEATInnovation innovation = new NEATInnovation();
          innovation.setInnovationID(Integer.parseInt(cols.get(0)));
          innovation.setInnovationType(PersistNEATPopulation
              .stringToInnovationType(cols.get(1)));
          innovation.setNeuronType(PersistNEATPopulation.stringToNeuronType(cols.get(2)));
          innovation.setSplitX(CSVFormat.EG_FORMAT.parse(cols.get(3)));
          innovation.setSplitY(CSVFormat.EG_FORMAT.parse(cols.get(4)));
          innovation.setNeuronID(Integer.parseInt(cols.get(5)));
          innovation.setFromNeuronID(Integer.parseInt(cols.get(6)));
          innovation.setToNeuronID(Integer.parseInt(cols.get(7)));
          result.getInnovations().add(innovation);
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("SPECIES")) {
        for (String line : section.getLines()) {
          String[] cols = line.split(",");
          BasicSpecies species = new BasicSpecies();

          species.setSpeciesID(Integer.parseInt(cols[0]));
          species.setAge(Integer.parseInt(cols[1]));
          species.setBestScore(CSVFormat.EG_FORMAT.parse(cols[2]));
          species.setGensNoImprovement(Integer.parseInt(cols[3]));
          species.setSpawnsRequired(CSVFormat.EG_FORMAT
              .parse(cols[4]));
          species.setSpawnsRequired(CSVFormat.EG_FORMAT
              .parse(cols[5]));
          leaderMap.put(species, Integer.parseInt(cols[6]));
          result.getSpecies().add(species);
          speciesMap.put((int) species.getSpeciesID(), species);
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("GENOMES")) {
        NEATGenome lastGenome = null;
        for (String line : section.getLines()) {
          List<String> cols = EncogFileSection.splitColumns(line);
          if (cols.get(0).equalsIgnoreCase("g") ) {
            lastGenome = new NEATGenome();
            lastGenome.setNeuronsChromosome(new Chromosome());
            lastGenome.setLinksChromosome(new Chromosome());
            lastGenome.getChromosomes().add(
                lastGenome.getNeuronsChromosome());
            lastGenome.getChromosomes().add(
                lastGenome.getLinksChromosome());
            lastGenome.setGenomeID(Integer.parseInt(cols.get(1)));
            lastGenome.setSpeciesID(Integer.parseInt(cols.get(2)));
            lastGenome.setAdjustedScore(CSVFormat.EG_FORMAT
                .parse(cols.get(3)));
            lastGenome.setAmountToSpawn(CSVFormat.EG_FORMAT
                .parse(cols.get(4)));
            lastGenome.setNetworkDepth(Integer.parseInt(cols.get(5)));
            lastGenome.setScore(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            result.add(lastGenome);
            genomeMap.put((int) lastGenome.getGenomeID(),
                lastGenome);
          } else if (cols.get(0).equalsIgnoreCase("n") ) {
            NEATNeuronGene neuronGene = new NEATNeuronGene();
            neuronGene.setId(Integer.parseInt(cols.get(1)));
            neuronGene.setNeuronType(PersistNEATPopulation
                .stringToNeuronType(cols.get(2)));
            neuronGene.setEnabled(Integer.parseInt(cols.get(3))>0);
            neuronGene.setInnovationId(Integer.parseInt(cols.get(4)));
            neuronGene.setActivationResponse(CSVFormat.EG_FORMAT
                .parse(cols.get(5)));
            neuronGene
                .setSplitX(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            neuronGene
                .setSplitY(CSVFormat.EG_FORMAT.parse(cols.get(7)));
            lastGenome.getNeurons().add(neuronGene);
          } else if (cols.get(0).equalsIgnoreCase("l")) {
            NEATLinkGene linkGene = new NEATLinkGene();
            linkGene.setId(Integer.parseInt(cols.get(1)));
            linkGene.setEnabled(Integer.parseInt(cols.get(2))>0);
            linkGene.setRecurrent(Integer.parseInt(cols.get(3))>0);
            linkGene.setFromNeuronID(Integer.parseInt(cols.get(4)));
            linkGene.setToNeuronID(Integer.parseInt(cols.get(5)));
            linkGene.setWeight(CSVFormat.EG_FORMAT.parse(cols.get(6)));
            linkGene.setInnovationId(Integer.parseInt(cols.get(7)));
            lastGenome.getLinks().add(linkGene);
          }
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("CONFIG")) {
        Map<String, String> params = section.parseParams();
       
        result.setNeatActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_NEAT_ACTIVATION));
        result.setOutputActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_OUTPUT_ACTIVATION));
        result.setSnapshot(EncogFileSection.parseBoolean(params, PersistConst.SNAPSHOT));
        result.setInputCount(EncogFileSection.parseInt(params,
View Full Code Here

TOP

Related Classes of org.encog.persist.EncogFileSection

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.