Examples of EncogFileSection


Examples of org.encog.persist.EncogFileSection

   */
  public void load(final InputStream stream) {
    EncogReadHelper reader = null;

    try {
      EncogFileSection section = null;
      reader = new EncogReadHelper(stream);

      while ((section = reader.readNextSection()) != null) {
        processSubSection(section);
      }
View Full Code Here

Examples of org.encog.persist.EncogFileSection

   */
  @Override
  public Object read(final InputStream is) {

    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;
    final BasicMLDataSet samples = new BasicMLDataSet();
    Map<String, String> networkParams = null;
    PNNKernelType kernel = null;
    PNNOutputMode outmodel = null;
    int inputCount = 0;
    int outputCount = 0;
    double error = 0;
    double[] sigma = null;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("PNN")
          && section.getSubSectionName().equals("PARAMS")) {
        networkParams = section.parseParams();
      }
      if (section.getSectionName().equals("PNN")
          && section.getSubSectionName().equals("NETWORK")) {
        final Map<String, String> params = section.parseParams();
        inputCount = EncogFileSection.parseInt(params,
            PersistConst.INPUT_COUNT);
        outputCount = EncogFileSection.parseInt(params,
            PersistConst.OUTPUT_COUNT);
        kernel = PersistBasicPNN.stringToKernel(params
            .get(PersistConst.KERNEL));
        outmodel = PersistBasicPNN.stringToOutputMode(params
            .get(PersistBasicPNN.PROPERTY_outputMode));
        error = EncogFileSection
            .parseDouble(params, PersistConst.ERROR);
        sigma = section.parseDoubleArray(params,
            PersistConst.SIGMA);
      }
      if (section.getSectionName().equals("PNN")
          && section.getSubSectionName().equals("SAMPLES")) {
        for (final String line : section.getLines()) {
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          int index = 0;
          final MLData inputData = new BasicMLData(inputCount);
          for (int i = 0; i < inputCount; i++) {
View Full Code Here

Examples of org.encog.persist.EncogFileSection

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

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

View Full Code Here

Examples of org.encog.persist.EncogFileSection

  @Override
  public 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(section.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(section.parseDoubleArray(params,
            PersistConst.WEIGHTS));
        flat.setBiasActivation(section.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);
         
          // if this is a class name with a path, then do not default to inside of the Encog package.
View Full Code Here

Examples of org.encog.persist.EncogFileSection

   */
  @Override
  public 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(section.parseDoubleArray(params,
            PersistConst.WEIGHTS));
        result.setCurrentState(section.parseDoubleArray(params,
            PersistConst.OUTPUT));
        result.setNeuronCount(EncogFileSection.parseInt(params,
            PersistConst.NEURON_COUNT));
      }
    }
View Full Code Here

Examples of org.encog.persist.EncogFileSection

   */
  @Override
  public 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

Examples of org.encog.persist.EncogFileSection

    final NEATPopulation result = new NEATPopulation();
    final NEATInnovationList innovationList = new NEATInnovationList();
    innovationList.setPopulation(result);
    result.setInnovations(innovationList);
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

    while ((section = in.readNextSection()) != null) {
      if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("INNOVATIONS")) {
        for (final String line : section.getLines()) {
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          final NEATInnovation innovation = new NEATInnovation();
          final int innovationID = Integer.parseInt(cols.get(1));
          innovation.setInnovationID(innovationID);
          innovation.setNeuronID(Integer.parseInt(cols.get(2)));
          result.getInnovations().getInnovations()
              .put(cols.get(0), innovation);
          nextInnovationID = Math.max(nextInnovationID,
              innovationID + 1);
        }
      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("SPECIES")) {
        NEATGenome lastGenome = null;
        BasicSpecies lastSpecies = null;

        for (final String line : section.getLines()) {
          final List<String> cols = EncogFileSection
              .splitColumns(line);

          if (cols.get(0).equalsIgnoreCase("s")) {
            lastSpecies = new BasicSpecies();
            lastSpecies.setPopulation(result);
            lastSpecies.setAge(Integer.parseInt(cols.get(1)));
            lastSpecies.setBestScore(CSVFormat.EG_FORMAT.parse(cols
                .get(2)));
            lastSpecies.setGensNoImprovement(Integer.parseInt(cols
                .get(3)));
            result.getSpecies().add(lastSpecies);
          } else if (cols.get(0).equalsIgnoreCase("g")) {
            final boolean isLeader = lastGenome == null;
            lastGenome = new NEATGenome();
            lastGenome.setInputCount(result.getInputCount());
            lastGenome.setOutputCount(result.getOutputCount());
            lastGenome.setSpecies(lastSpecies);
            lastGenome.setAdjustedScore(CSVFormat.EG_FORMAT
                .parse(cols.get(1)));
            lastGenome.setScore(CSVFormat.EG_FORMAT.parse(cols
                .get(2)));
            lastGenome.setBirthGeneration(Integer.parseInt(cols
                .get(3)));
            lastSpecies.add(lastGenome);
            if (isLeader) {
              lastSpecies.setLeader(lastGenome);
            }
          } else if (cols.get(0).equalsIgnoreCase("n")) {
            final NEATNeuronGene neuronGene = new NEATNeuronGene();
            final int geneID = Integer.parseInt(cols.get(1));
            neuronGene.setId(geneID);

            final ActivationFunction af = EncogFileSection
                .parseActivationFunction(cols.get(2));
            neuronGene.setActivationFunction(af);

            neuronGene.setNeuronType(PersistNEATPopulation
                .stringToNeuronType(cols.get(3)));
            neuronGene
                .setInnovationId(Integer.parseInt(cols.get(4)));
            lastGenome.getNeuronsChromosome().add(neuronGene);
            nextGeneID = Math.max(geneID + 1, nextGeneID);
          } else if (cols.get(0).equalsIgnoreCase("l")) {
            final NEATLinkGene linkGene = new NEATLinkGene();
            linkGene.setId(Integer.parseInt(cols.get(1)));
            linkGene.setEnabled(Integer.parseInt(cols.get(2)) > 0);
            linkGene.setFromNeuronID(Integer.parseInt(cols.get(3)));
            linkGene.setToNeuronID(Integer.parseInt(cols.get(4)));
            linkGene.setWeight(CSVFormat.EG_FORMAT.parse(cols
                .get(5)));
            linkGene.setInnovationId(Integer.parseInt(cols.get(6)));
            lastGenome.getLinksChromosome().add(linkGene);
          }
        }

      } else if (section.getSectionName().equals("NEAT-POPULATION")
          && section.getSubSectionName().equals("CONFIG")) {
        final Map<String, String> params = section.parseParams();

        final String afStr = params
            .get(NEATPopulation.PROPERTY_NEAT_ACTIVATION);

        if (afStr.equalsIgnoreCase(PersistNEATPopulation.TYPE_CPPN)) {
View Full Code Here

Examples of org.encog.persist.EncogFileSection

  public 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(section.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(section.parseDoubleArray(params,
            PersistConst.WEIGHTS));
        flat.setBiasActivation(section.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

Examples of org.encog.persist.EncogFileSection

   */
  @Override
  public 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 = section
                .parseDoubleArray(params, key);
            result.put(key, list);
          }
        }
      }
View Full Code Here

Examples of org.encog.persist.EncogFileSection

    Matrix transitionProbability = null;
    Map<String,String> properties = null;
    List<StateDistribution> distributions = new ArrayList<StateDistribution>();
   
    final EncogReadHelper in = new EncogReadHelper(is);
    EncogFileSection section;

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

        states = EncogFileSection.parseInt(params, HiddenMarkovModel.TAG_STATES);
       
        if( params.containsKey(HiddenMarkovModel.TAG_ITEMS) ) {
          items = EncogFileSection.parseIntArray(params, HiddenMarkovModel.TAG_ITEMS);
        }
        pi = section.parseDoubleArray(params,  HiddenMarkovModel.TAG_PI);
        transitionProbability = section.parseMatrix(params, HiddenMarkovModel.TAG_TRANSITION);
      } else if (section.getSectionName().equals("HMM")
          && section.getSubSectionName().startsWith("DISTRIBUTION-")) {
        final Map<String, String> params = section.parseParams();
        String t = params.get(HiddenMarkovModel.TAG_DIST_TYPE);
        if( "ContinousDistribution".equals(t) ) {
          double[] mean = section.parseDoubleArray(params, HiddenMarkovModel.TAG_MEAN);
          Matrix cova = section.parseMatrix(params, HiddenMarkovModel.TAG_COVARIANCE);
          ContinousDistribution dist = new ContinousDistribution(mean,cova.getData());
          distributions.add(dist);
        } else if( "DiscreteDistribution".equals(t) ) {
          Matrix prob = section.parseMatrix(params, HiddenMarkovModel.TAG_PROBABILITIES);
          DiscreteDistribution dist = new DiscreteDistribution(prob.getData());
          distributions.add(dist);
        }
      }
    }
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.