Package org.encog.persist

Examples of org.encog.persist.EncogWriteHelper


  /**
   * {@inheritDoc}
   */
  @Override
  public final void save(final OutputStream os, final Object obj) {
    final EncogWriteHelper out = new EncogWriteHelper(os);
    final SVM svm2 = (SVM) obj;
    out.addSection("SVM");
    out.addSubSection("PARAMS");
    out.addProperties(svm2.getProperties());
    out.addSubSection("SVM-PARAM");
    out.writeProperty(PersistConst.INPUT_COUNT, svm2.getInputCount());
    out.writeProperty(PersistSVM.PARAM_C, svm2.getParams().C);
    out.writeProperty(PersistSVM.PARAM_CACHE_SIZE,
        svm2.getParams().cache_size);
    out.writeProperty(PersistSVM.PARAM_COEF0, svm2.getParams().coef0);
    out.writeProperty(PersistSVM.PARAM_DEGREE, svm2.getParams().degree);
    out.writeProperty(PersistSVM.PARAM_EPS, svm2.getParams().eps);
    out.writeProperty(PersistSVM.PARAM_GAMMA, svm2.getParams().gamma);
    out.writeProperty(PersistSVM.PARAM_KERNEL_TYPE,
        svm2.getParams().kernel_type);
    out.writeProperty(
        PersistSVM.PARAM_NUM_WEIGHT, svm2.getParams().nr_weight);
    out.writeProperty(PersistSVM.PARAM_NU, svm2.getParams().nu);
    out.writeProperty(PersistSVM.PARAM_P, svm2.getParams().p);
    out.writeProperty(PersistSVM.PARAM_PROBABILITY,
        svm2.getParams().probability);
    out.writeProperty(PersistSVM.PARAM_SHRINKING,
        svm2.getParams().shrinking);
    out.writeProperty(PersistSVM.PARAM_SVM_TYPE, svm2.getParams().svm_type);
    out.writeProperty(PersistSVM.PARAM_WEIGHT, svm2.getParams().weight);
    out.writeProperty(PersistSVM.PARAM_WEIGHT_LABEL,
        svm2.getParams().weight_label);
    if (svm2.getModel() != null) {
      out.addSubSection("SVM-MODEL");
      try {
        final ByteArrayOutputStream ba = new ByteArrayOutputStream();
        final DataOutputStream das = new DataOutputStream(ba);
        svm.svm_save_model(das, svm2.getModel());
        out.write(ba.toString("UTF-8"));
        das.close();
        ba.close();

      } catch (final IOException ex) {
        throw new PersistError(ex);
      }
    }

    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 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.getOutputNeuronCount());
    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 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");
    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

    try {
      String home = System.getProperty("user.home");
      file = new File(home, EncogWorkBench.CONFIG_FILENAME);

      OutputStream os = new FileOutputStream(file);
      EncogWriteHelper out = new EncogWriteHelper(os);
      out.addSection("ENCOG");
      out.addSubSection("TRAINING");

      out.writeProperty(EncogWorkBenchConfig.PROPERTY_DEFAULT_ERROR, this.defaultError);
      out.writeProperty(EncogWorkBenchConfig.PROPERTY_THREAD_COUNT, this.threadCount);
      out.writeProperty(EncogWorkBenchConfig.PROPERTY_USE_GPU, this.useOpenCL);
      out.writeProperty(EncogWorkBenchConfig.PROPERTY_ERROR_CALC, this.errorCalculation);
           
      out.flush();
      os.close();
    } catch (IOException ex) {
      if (file != null)
        EncogWorkBench.displayError("Can't write config file",
            file.toString());
View Full Code Here

   *
   * @param stream
   *            The output stream.
   */
  public final 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);
    }

    saveSubSection(out, "RANDOMIZE", "CONFIG");
    saveSubSection(out, "CLUSTER", "CONFIG");
    saveSubSection(out, "BALANCE", "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 BAM bam = (BAM) obj;
    out.addSection("BAM");
    out.addSubSection("PARAMS");
    out.addProperties(bam.getProperties());
    out.addSubSection("NETWORK");

    out.writeProperty(PersistConst.PROPERTY_F1_COUNT, bam.getF1Count());
    out.writeProperty(PersistConst.PROPERTY_F2_COUNT, bam.getF2Count());
    out.writeProperty(PersistConst.PROPERTY_WEIGHTS_F1_F2,
        bam.getWeightsF1toF2());
    out.writeProperty(PersistConst.PROPERTY_WEIGHTS_F2_F1,
        bam.getWeightsF2toF1());

    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 BayesianNetwork b = (BayesianNetwork) obj;
    out.addSection("BAYES-NETWORK");
    out.addSubSection("BAYES-PARAM");
    String queryType = "";
    String queryStr = b.getClassificationStructure();

    if( b.getQuery()!=null ) {
      queryType = b.getQuery().getClass().getSimpleName();
    }
   
    out.writeProperty("queryType", queryType);
    out.writeProperty("query", queryStr);
    out.writeProperty("contents", b.getContents());
    out.addSubSection("BAYES-PROPERTIES");
    out.addProperties(b.getProperties());

    out.addSubSection("BAYES-TABLE");
    for (BayesianEvent event : b.getEvents()) {
      for (TableLine line : event.getTable().getLines()) {
        if (line == null)
          continue;
        StringBuilder str = new StringBuilder();
        str.append("P(");

        str.append(BayesianEvent.formatEventName(event, line.getResult()));

        if (event.getParents().size() > 0) {
          str.append("|");
        }

        int index = 0;
        boolean first = true;
        for (BayesianEvent parentEvent : event.getParents()) {
          if (!first) {
            str.append(",");
          }
          first = false;
          int arg = line.getArguments()[index++];
          if (parentEvent.isBoolean()) {
            if (arg==0) {
              str.append("+");
            } else {
              str.append("-");
            }
          }
          str.append(parentEvent.getLabel());
          if (!parentEvent.isBoolean()) {
            str.append("=");
            if( arg>=parentEvent.getChoices().size()) {
              throw new BayesianError("Argument value " + arg + " is out of range for event " + parentEvent.toString());
            }
            str.append(parentEvent.getChoice(arg));
          }
        }
        str.append(")=");
        str.append(line.getProbability());
        str.append("\n");
        out.write(str.toString());
      }
    }

    out.flush();
  }
View Full Code Here

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

    out.addSection("BASIC");
    out.addSubSection("PARAMS");
    out.addProperties(pop.getProperties());
    out.addSubSection("EPL-OPCODES");
    for (final ProgramExtensionTemplate temp : pop.getContext()
        .getFunctions().getOpCodes()) {
      out.addColumn(temp.getName());
      out.addColumn(temp.getChildNodeCount());
      out.writeLine();
    }
    out.addSubSection("EPL-SYMBOLIC");
    out.addColumn("name");
    out.addColumn("type");
    out.addColumn("enum");
    out.addColumn("enum_type");
    out.addColumn("enum_count");
    out.writeLine();

    // write the first line, the result
    out.addColumn("");
    out.addColumn(getType(pop.getContext().getResult()));
    out.addColumn(pop.getContext().getResult().getEnumType());
    out.addColumn(pop.getContext().getResult().getEnumValueCount());
    out.writeLine();

    // write the next lines, the variables
    for (final VariableMapping mapping : pop.getContext()
        .getDefinedVariables()) {
      out.addColumn(mapping.getName());
      out.addColumn(getType(mapping));
      out.addColumn(mapping.getEnumType());
      out.addColumn(mapping.getEnumValueCount());
      out.writeLine();
    }
    out.addSubSection("EPL-POPULATION");
    for (final Species species : pop.getSpecies()) {
      if (species.getMembers().size() > 0) {
        out.addColumn("s");
        out.addColumn(species.getAge());
        out.addColumn(species.getBestScore());
        out.addColumn(species.getGensNoImprovement());
        out.writeLine();
        for (final Genome genome : species.getMembers()) {
          final EncogProgram prg = (EncogProgram) genome;
          out.addColumn("p");
          if (Double.isInfinite(prg.getScore())
              || Double.isNaN(prg.getScore())) {
            out.addColumn("NaN");
            out.addColumn("NaN");
          } else {

            out.addColumn(prg.getScore());
            out.addColumn(prg.getAdjustedScore());
          }

          out.addColumn(prg.generateEPL());
          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 CPN cpn = (CPN) obj;
    out.addSection("CPN");
    out.addSubSection("PARAMS");
    out.addProperties(cpn.getProperties());
    out.addSubSection("NETWORK");

    out.writeProperty(PersistConst.INPUT_COUNT, cpn.getInputCount());
    out.writeProperty(PersistConst.INSTAR, cpn.getInstarCount());
    out.writeProperty(PersistConst.OUTPUT_COUNT, cpn.getOutputCount());
    out.writeProperty(PersistCPN.PROPERTY_inputToInstar,
        cpn.getWeightsInputToInstar());
    out.writeProperty(PersistCPN.PROPERTY_instarToInput,
        cpn.getWeightsInstarToOutstar());
    out.writeProperty(PersistCPN.PROPERTY_winnerCount,
        cpn.getWinnerCount());

    out.flush();
  }
View Full Code Here

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

    out.writeProperty(ART.PROPERTY_A1, art1.getA1());
    out.writeProperty(ART.PROPERTY_B1, art1.getB1());
    out.writeProperty(ART.PROPERTY_C1, art1.getC1());
    out.writeProperty(ART.PROPERTY_D1, art1.getD1());
    out.writeProperty(PersistConst.PROPERTY_F1_COUNT, art1.getF1Count());
    out.writeProperty(PersistConst.PROPERTY_F2_COUNT, art1.getF2Count());
    out.writeProperty(ART.PROPERTY_NO_WINNER, art1.getNoWinner());
    out.writeProperty(ART.PROPERTY_L, art1.getL());
    out.writeProperty(ART.PROPERTY_VIGILANCE, art1.getVigilance());
    out.writeProperty(PersistConst.PROPERTY_WEIGHTS_F1_F2,
        art1.getWeightsF1toF2());
    out.writeProperty(PersistConst.PROPERTY_WEIGHTS_F2_F1,
        art1.getWeightsF2toF1());

    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.