Package org.encog.persist

Examples of org.encog.persist.EncogWriteHelper


   *
   * @param stream
   *            The output stream.
   */
  public void save(final OutputStream stream) {
    final EncogWriteHelper out = new EncogWriteHelper(stream);
    saveSubSection(out, "HEADER", "DATASOURCE");
    saveConfig(out);

    if (this.script.getFields() != null) {
      saveData(out);
      saveNormalize(out);
    }

    saveProcess(out);
   
    saveSubSection(out, "RANDOMIZE", "CONFIG");
    saveSubSection(out, "CLUSTER", "CONFIG");
    saveSubSection(out, "BALANCE", "CONFIG");
    saveSubSection(out, "CODE", "CONFIG");

    if (this.script.getSegregate().getSegregateTargets() != null) {
      saveSegregate(out);
    }
    saveSubSection(out, "GENERATE", "CONFIG");
    saveMachineLearning(out);
    saveTasks(out);
    out.flush();
  }
View Full Code Here


  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final BasicPNN pnn = (BasicPNN) obj;
    out.addSection("PNN");
    out.addSubSection("PARAMS");
    out.addProperties(pnn.getProperties());
    out.addSubSection("NETWORK");

    out.writeProperty(PersistConst.ERROR, pnn.getError());
    out.writeProperty(PersistConst.INPUT_COUNT, pnn.getInputCount());
    out.writeProperty(PersistConst.KERNEL,
        PersistBasicPNN.kernelToString(pnn.getKernel()));
    out.writeProperty(PersistConst.OUTPUT_COUNT, pnn.getOutputCount());
    out.writeProperty(PersistBasicPNN.PROPERTY_outputMode,
        PersistBasicPNN.outputModeToString(pnn.getOutputMode()));
    out.writeProperty(PersistConst.SIGMA, pnn.getSigma());

    out.addSubSection("SAMPLES");
   
    if (pnn.getSamples() != null) {
      for (final MLDataPair pair : pnn.getSamples()) {
        for (int i = 0; i < pair.getInput().size(); i++) {
          out.addColumn(pair.getInput().getData(i));
        }
        for (int i = 0; i < pair.getIdeal().size(); i++) {
          out.addColumn(pair.getIdeal().getData(i));
        }
        out.writeLine();
      }
    }

    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final SOM som = (SOM) obj;
    out.addSection("SOM");
    out.addSubSection("PARAMS");
    out.addProperties(som.getProperties());
    out.addSubSection("NETWORK");
    out.writeProperty(PersistConst.WEIGHTS, som.getWeights());
    out.writeProperty(PersistConst.INPUT_COUNT, som.getInputCount());
    out.writeProperty(PersistConst.OUTPUT_COUNT, som.getOutputCount());
    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final HopfieldNetwork hopfield = (HopfieldNetwork) obj;
    out.addSection("HOPFIELD");
    out.addSubSection("PARAMS");
    out.addProperties(hopfield.getProperties());
    out.addSubSection("NETWORK");
    out.writeProperty(PersistConst.WEIGHTS, hopfield.getWeights());
    out.writeProperty(PersistConst.OUTPUT, hopfield.getCurrentState()
        .getData());
    out.writeProperty(PersistConst.NEURON_COUNT, hopfield.getNeuronCount());
    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final BasicNetwork net = (BasicNetwork) obj;
    final FlatNetwork flat = net.getStructure().getFlat();
    out.addSection("BASIC");
    out.addSubSection("PARAMS");
    out.addProperties(net.getProperties());
    out.addSubSection("NETWORK");

    out.writeProperty(BasicNetwork.TAG_BEGIN_TRAINING,
        flat.getBeginTraining());
    out.writeProperty(BasicNetwork.TAG_CONNECTION_LIMIT,
        flat.getConnectionLimit());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_OFFSET,
        flat.getContextTargetOffset());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_SIZE,
        flat.getContextTargetSize());
    out.writeProperty(BasicNetwork.TAG_END_TRAINING, flat.getEndTraining());
    out.writeProperty(BasicNetwork.TAG_HAS_CONTEXT, flat.getHasContext());
    out.writeProperty(PersistConst.INPUT_COUNT, flat.getInputCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_COUNTS, flat.getLayerCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_FEED_COUNTS,
        flat.getLayerFeedCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_CONTEXT_COUNT,
        flat.getLayerContextCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_INDEX, flat.getLayerIndex());
    out.writeProperty(PersistConst.OUTPUT, flat.getLayerOutput());
    out.writeProperty(PersistConst.OUTPUT_COUNT, flat.getOutputCount());
    out.writeProperty(BasicNetwork.TAG_WEIGHT_INDEX, flat.getWeightIndex());
    out.writeProperty(PersistConst.WEIGHTS, flat.getWeights());
    out.writeProperty(BasicNetwork.TAG_BIAS_ACTIVATION,
        flat.getBiasActivation());
    out.addSubSection("ACTIVATION");
    for (final ActivationFunction af : flat.getActivationFunctions()) {
      String sn = af.getClass().getSimpleName();
      // if this is an Encog class then only add the simple name, so it works with C#
      if( sn.startsWith("org.encog.") ) {
        out.addColumn(sn);
      } else {
        out.addColumn(af.getClass().getName());
      }
      for (int i = 0; i < af.getParams().length; i++) {
        out.addColumn(af.getParams()[i]);
      }
      out.writeLine();
    }

    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final BoltzmannMachine boltz = (BoltzmannMachine) obj;
    out.addSection("BOLTZMANN");
    out.addSubSection("PARAMS");
    out.addProperties(boltz.getProperties());
    out.addSubSection("NETWORK");
    out.writeProperty(PersistConst.WEIGHTS, boltz.getWeights());
    out.writeProperty(PersistConst.OUTPUT, boltz.getCurrentState()
        .getData());
    out.writeProperty(PersistConst.NEURON_COUNT, boltz.getNeuronCount());

    out.writeProperty(PersistConst.THRESHOLDS, boltz.getThreshold());
    out.writeProperty(BoltzmannMachine.ANNEAL_CYCLES,
        boltz.getAnnealCycles());
    out.writeProperty(BoltzmannMachine.RUN_CYCLES, boltz.getRunCycles());
    out.writeProperty(PersistConst.TEMPERATURE, boltz.getTemperature());

    out.flush();

  }
View Full Code Here

    return result;
  }

  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final NEATPopulation pop = (NEATPopulation) obj;
    out.addSection("NEAT-POPULATION");
    out.addSubSection("CONFIG");
    out.writeProperty(PersistConst.ACTIVATION_CYCLES,
        pop.getActivationCycles());

    if (pop.isHyperNEAT()) {
      out.writeProperty(NEATPopulation.PROPERTY_NEAT_ACTIVATION,
          PersistNEATPopulation.TYPE_CPPN);
    } else {
      final ActivationFunction af = pop.getActivationFunctions()
          .getList().get(0).getObj();
      out.writeProperty(NEATPopulation.PROPERTY_NEAT_ACTIVATION, af);
    }

    out.writeProperty(PersistConst.INPUT_COUNT, pop.getInputCount());
    out.writeProperty(PersistConst.OUTPUT_COUNT, pop.getOutputCount());
    out.writeProperty(NEATPopulation.PROPERTY_CYCLES,
        pop.getActivationCycles());
    out.writeProperty(NEATPopulation.PROPERTY_POPULATION_SIZE,
        pop.getPopulationSize());
    out.writeProperty(NEATPopulation.PROPERTY_SURVIVAL_RATE,
        pop.getSurvivalRate());
    out.addSubSection("INNOVATIONS");
    if (pop.getInnovations() != null) {
      for (final String key : pop.getInnovations().getInnovations()
          .keySet()) {
        final NEATInnovation innovation = pop.getInnovations()
            .getInnovations().get(key);
        out.addColumn(key);
        out.addColumn(innovation.getInnovationID());
        out.addColumn(innovation.getNeuronID());
        out.writeLine();
      }
    }

    out.addSubSection("SPECIES");

    // make sure the best species goes first
    final Species bestSpecies = pop.determineBestSpecies();
    if (bestSpecies != null) {
      saveSpecies(out, bestSpecies);
    }

    // now write the other species, other than the best one
    for (final Species species : pop.getSpecies()) {
      if (species != bestSpecies) {
        saveSpecies(out, species);
      }
    }
    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final RBFNetwork net = (RBFNetwork) obj;
    final FlatNetworkRBF flat = (FlatNetworkRBF) net.getFlat();
    out.addSection("RBF-NETWORK");
    out.addSubSection("PARAMS");
    out.addProperties(net.getProperties());
    out.addSubSection("NETWORK");
    out.writeProperty(BasicNetwork.TAG_BEGIN_TRAINING,
        flat.getBeginTraining());
    out.writeProperty(BasicNetwork.TAG_CONNECTION_LIMIT,
        flat.getConnectionLimit());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_OFFSET,
        flat.getContextTargetOffset());
    out.writeProperty(BasicNetwork.TAG_CONTEXT_TARGET_SIZE,
        flat.getContextTargetSize());
    out.writeProperty(BasicNetwork.TAG_END_TRAINING, flat.getEndTraining());
    out.writeProperty(BasicNetwork.TAG_HAS_CONTEXT, flat.getHasContext());
    out.writeProperty(PersistConst.INPUT_COUNT, flat.getInputCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_COUNTS, flat.getLayerCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_FEED_COUNTS,
        flat.getLayerFeedCounts());
    out.writeProperty(BasicNetwork.TAG_LAYER_CONTEXT_COUNT,
        flat.getLayerContextCount());
    out.writeProperty(BasicNetwork.TAG_LAYER_INDEX, flat.getLayerIndex());
    out.writeProperty(PersistConst.OUTPUT, flat.getLayerOutput());
    out.writeProperty(PersistConst.OUTPUT_COUNT, flat.getOutputCount());
    out.writeProperty(BasicNetwork.TAG_WEIGHT_INDEX, flat.getWeightIndex());
    out.writeProperty(PersistConst.WEIGHTS, flat.getWeights());
    out.writeProperty(BasicNetwork.TAG_BIAS_ACTIVATION,
        flat.getBiasActivation());
    out.addSubSection("ACTIVATION");
    for (final ActivationFunction af : flat.getActivationFunctions()) {
      out.addColumn(af.getClass().getSimpleName());
      for (int i = 0; i < af.getParams().length; i++) {
        out.addColumn(af.getParams()[i]);
      }
      out.writeLine();
    }
    out.addSubSection("RBF");
    for (final RadialBasisFunction rbf : flat.getRBF()) {
      out.addColumn(rbf.getClass().getSimpleName());
      out.addColumn(rbf.getWidth());
      out.addColumn(rbf.getPeak());
      for (int i = 0; i < rbf.getCenters().length; i++) {
        out.addColumn(rbf.getCenters()[i]);
      }
      out.writeLine();
    }

    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final TrainingContinuation cont = (TrainingContinuation) obj;
    out.addSection("CONT");
    out.addSubSection("PARAMS");
    out.writeProperty("type", cont.getTrainingType());
    for (final String key : cont.getContents().keySet()) {
      final double[] list = (double[]) cont.get(key);
      out.writeProperty(key, list);
    }
    out.flush();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public final void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final HiddenMarkovModel net = (HiddenMarkovModel) obj;

    out.addSection("HMM");
    out.addSubSection("PARAMS");
    out.addProperties(net.getProperties());
    out.addSubSection("CONFIG");

    out.writeProperty(HiddenMarkovModel.TAG_STATES,net.getStateCount());
    if( net.getItems()!=null ) {
      out.writeProperty(HiddenMarkovModel.TAG_ITEMS,net.getItems());
    }
    out.writeProperty(HiddenMarkovModel.TAG_PI,net.getPi());
    out.writeProperty(HiddenMarkovModel.TAG_TRANSITION,new Matrix(net.getTransitionProbability()));
   
    for( int i=0; i<net.getStateCount();i++) {
      out.addSubSection("DISTRIBUTION-"+i)
      StateDistribution sd = net.getStateDistribution(i);
      out.writeProperty(HiddenMarkovModel.TAG_DIST_TYPE, sd.getClass().getSimpleName());
     
      if( sd instanceof ContinousDistribution ) {
        ContinousDistribution cDist = (ContinousDistribution)sd;
        out.writeProperty(HiddenMarkovModel.TAG_MEAN, cDist.getMean());
        out.writeProperty(HiddenMarkovModel.TAG_COVARIANCE, cDist.getCovariance());
       
      } else if( sd instanceof DiscreteDistribution ) {
        DiscreteDistribution dDist = (DiscreteDistribution)sd;
        out.writeProperty(HiddenMarkovModel.TAG_PROBABILITIES, new Matrix(dDist.getProbabilities()));
      }
    }

    out.flush();
  }
View Full Code Here

TOP

Related Classes of org.encog.persist.EncogWriteHelper

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.